我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用operator.isMappingType()。
def updateFromTree(self,tree): """ This method takes a dictionary of type {level0:{level1:{level2:{}}}} and converts it into a grid like level0 \t level1 \t level2 WARNING!: This method deletes the actual content of the array! """ if self.trace: print('WARNING!: updateFromTree deletes ' 'the actual content of the array!') table = tree2table(tree) self.resize(1,1) self.resize(len(table),max(len(line) for line in table)) [self.setRow(i,table[i]) for i in range(len(table))] #def printTree(self,level=None,depth=0): #if not level: level=self.getAsTree() #MAX_DEPTH=10 #if depth>MAX_DEPTH or not hasattr(level,'items'): return #for k,l in level.iteritems(): #if operator.isMappingType(l): #print (' '*depth),k,'=',l.keys() #self.printTree(l,depth+1) #else: #print (' '*depth),k,'=',l
def test_operator(self): import operator self.assertIs(operator.truth(0), False) self.assertIs(operator.truth(1), True) with test_support.check_py3k_warnings(): self.assertIs(operator.isCallable(0), False) self.assertIs(operator.isCallable(len), True) self.assertIs(operator.isNumberType(None), False) self.assertIs(operator.isNumberType(0), True) self.assertIs(operator.not_(1), False) self.assertIs(operator.not_(0), True) self.assertIs(operator.isSequenceType(0), False) self.assertIs(operator.isSequenceType([]), True) self.assertIs(operator.contains([], 1), False) self.assertIs(operator.contains([1], 1), True) self.assertIs(operator.isMappingType(1), False) self.assertIs(operator.isMappingType({}), True) self.assertIs(operator.lt(0, 0), False) self.assertIs(operator.lt(0, 1), True) self.assertIs(operator.is_(True, True), True) self.assertIs(operator.is_(True, False), False) self.assertIs(operator.is_not(True, True), False) self.assertIs(operator.is_not(True, False), True)
def _format_CreateMotorGroup_arguments(self, argin): if len(argin) == 0: msg = PoolClass.cmd_list["CreateMotorGroup"][0][1] raise Exception(msg) if len(argin) == 1: ret = [] try: elems = json.loads(argin[0]) except: elems = argin if operator.isMappingType(elems): elems = [elems] for elem in elems: d = {} for k, v in elem.items(): d[str(k)] = str(v) ret.append(d) return ret ret = {'name': argin[0]} if argin[-1].count('/') == 2: ret['full_name'] = argin[-1] del argin[-1] ret['elements'] = argin[1:] return [ret]
def setEnvObj(self, obj): """Sets the environment for the given object. If object is a sequence then each pair of elements k, v is added as env[k] = v. If object is a map then the environmnent is updated. Other object types are not supported The elements which are strings are 'python evaluated' @throws TypeError is obj is not a sequence or a map @param[in] obj object to be added to the environment @return a dict representing the added environment""" if operator.isSequenceType(obj) and \ not isinstance(obj, (str, unicode)): obj = self._dictFromSequence(obj) elif not operator.isMappingType(obj): raise TypeError("obj parameter must be a sequence or a map") obj = self._encode(obj) for k, v in obj.iteritems(): self._setOneEnv(k, v) return obj
def format_string(f, val, grouping=False): """Formats a string in the same way that the % formatting would use, but takes the current locale into account. Grouping is applied if the third parameter is true.""" percents = list(_percent_re.finditer(f)) new_f = _percent_re.sub('%s', f) if operator.isMappingType(val): new_val = [] for perc in percents: if perc.group()[-1]=='%': new_val.append('%') else: new_val.append(format(perc.group(), val, grouping)) else: if not isinstance(val, tuple): val = (val,) new_val = [] i = 0 for perc in percents: if perc.group()[-1]=='%': new_val.append('%') else: starcount = perc.group('modifiers').count('*') new_val.append(_format(perc.group(), val[i], grouping, False, *val[i+1:i+1+starcount])) i += (1 + starcount) val = tuple(new_val) return new_f % val
def test_isMappingType(self): self.assertRaises(TypeError, operator.isMappingType) self.assertFalse(operator.isMappingType(1)) self.assertFalse(operator.isMappingType(operator.isMappingType)) self.assertTrue(operator.isMappingType(operator.__dict__)) self.assertTrue(operator.isMappingType({}))