Python types.BooleanType() Examples
The following are 19
code examples of types.BooleanType().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
types
, or try the search function
.
Example #1
Source File: fetch_stats.py From elasticsearch-monitoring with Apache License 2.0 | 6 votes |
def into_signalfx(sfx_key, cluster_health, node_stats): import signalfx sfx = signalfx.SignalFx() ingest = sfx.ingest(sfx_key) for node in node_stats: source_node = node['source_node'] for s in node_stats_to_collect: flattened = flatten_json(node['node_stats'][s]) for k,v in flattened.items(): if isinstance(v, (int, float)) and not isinstance(v, types.BooleanType): ingest.send(gauges=[{"metric": 'elasticsearch.node.' + s + '.' + k, "value": v, "dimensions": { 'cluster_uuid': node.get('cluster_uuid'), 'cluster_name': node.get('cluster_name'), 'node_name': source_node.get('name'), 'node_host': source_node.get('host'), 'node_host': source_node.get('ip'), 'node_uuid': source_node.get('uuid'), 'cluster_name': source_node.get('uuid'), } }]) ingest.stop()
Example #2
Source File: recipe-473818.py From code with MIT License | 6 votes |
def new_looper(a, arg=None): """Helper function for nest() determines what sort of looper to make given a's type""" if isinstance(a,types.TupleType): if len(a) == 2: return RangeLooper(a[0],a[1]) elif len(a) == 3: return RangeLooper(a[0],a[1],a[2]) elif isinstance(a, types.BooleanType): return BooleanLooper(a) elif isinstance(a,types.IntType) or isinstance(a, types.LongType): return RangeLooper(a) elif isinstance(a, types.StringType) or isinstance(a, types.ListType): return ListLooper(a) elif isinstance(a, Looper): return a elif isinstance(a, types.LambdaType): return CalcField(a, arg)
Example #3
Source File: BeautifulSoup.py From darkc0de-old-stuff with GNU General Public License v3.0 | 5 votes |
def _matches(self, markup, matchAgainst): #print "Matching %s against %s" % (markup, matchAgainst) result = False if matchAgainst == True and type(matchAgainst) == types.BooleanType: result = markup != None elif callable(matchAgainst): result = matchAgainst(markup) else: #Custom match methods take the tag as an argument, but all #other ways of matching match the tag name as a string. if isinstance(markup, Tag): markup = markup.name if markup and not isString(markup): markup = unicode(markup) #Now we know that chunk is either a string, or None. if hasattr(matchAgainst, 'match'): # It's a regexp object. result = markup and matchAgainst.search(markup) elif isList(matchAgainst): result = markup in matchAgainst elif hasattr(matchAgainst, 'items'): result = markup.has_key(matchAgainst) elif matchAgainst and isString(markup): if isinstance(markup, unicode): matchAgainst = unicode(matchAgainst) else: matchAgainst = str(matchAgainst) if not result: result = matchAgainst == markup return result
Example #4
Source File: jsonobject.py From zstack-utility with Apache License 2.0 | 5 votes |
def _is_primitive_types(obj): return isinstance(obj, (types.BooleanType, types.LongType, types.IntType, types.FloatType, types.StringType, types.UnicodeType))
Example #5
Source File: BeautifulSoup.py From canvas with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _matches(self, markup, matchAgainst): #print "Matching %s against %s" % (markup, matchAgainst) result = False if matchAgainst == True and type(matchAgainst) == types.BooleanType: result = markup != None elif callable(matchAgainst): result = matchAgainst(markup) else: #Custom match methods take the tag as an argument, but all #other ways of matching match the tag name as a string. if isinstance(markup, Tag): markup = markup.name if markup and not isString(markup): markup = unicode(markup) #Now we know that chunk is either a string, or None. if hasattr(matchAgainst, 'match'): # It's a regexp object. result = markup and matchAgainst.search(markup) elif isList(matchAgainst): result = markup in matchAgainst elif hasattr(matchAgainst, 'items'): result = markup.has_key(matchAgainst) elif matchAgainst and isString(markup): if isinstance(markup, unicode): matchAgainst = unicode(matchAgainst) else: matchAgainst = str(matchAgainst) if not result: result = matchAgainst == markup return result
Example #6
Source File: register.py From Sepia with GNU General Public License v2.0 | 5 votes |
def __input_vector_check(self): if type(self.stop) is types.IntType and type(self.start) is types.IntType and type( self.mutex) is types.BooleanType: pass else: raise RegisterValueException('Register init func type error') if len(self.targets) is 0: msg = 'no target' raise RegisterDataException(msg) if self.start > self.stop: msg = 'start > stop' raise RegisterDataException(msg)
Example #7
Source File: register.py From Sepia with GNU General Public License v2.0 | 5 votes |
def __pretreat(self): self.__input_vector_check() for __target in self.targets: __trigger = __target.get('trigger') if type(__trigger) is types.BooleanType or type(__trigger) is types.StringType: if __trigger: self.verified.append(__target) else: msg = '[Trigger Type Error] Expected:boolean,found:' + str(type(__trigger)) raise RegisterValueException(msg) self.__mutex_check()
Example #8
Source File: BeautifulSoup.py From fimap with GNU General Public License v2.0 | 5 votes |
def _matches(self, markup, matchAgainst): #print "Matching %s against %s" % (markup, matchAgainst) result = False if matchAgainst == True and type(matchAgainst) == types.BooleanType: result = markup != None elif callable(matchAgainst): result = matchAgainst(markup) else: #Custom match methods take the tag as an argument, but all #other ways of matching match the tag name as a string. if isinstance(markup, Tag): markup = markup.name if markup and not isString(markup): markup = unicode(markup) #Now we know that chunk is either a string, or None. if hasattr(matchAgainst, 'match'): # It's a regexp object. result = markup and matchAgainst.search(markup) elif isList(matchAgainst): result = markup in matchAgainst elif hasattr(matchAgainst, 'items'): result = markup.has_key(matchAgainst) elif matchAgainst and isString(markup): if isinstance(markup, unicode): matchAgainst = unicode(matchAgainst) else: matchAgainst = str(matchAgainst) if not result: result = matchAgainst == markup return result
Example #9
Source File: BeautifulSoup.py From doork with MIT License | 5 votes |
def _matches(self, markup, matchAgainst): #print "Matching %s against %s" % (markup, matchAgainst) result = False if matchAgainst == True and type(matchAgainst) == types.BooleanType: result = markup != None elif callable(matchAgainst): result = matchAgainst(markup) else: #Custom match methods take the tag as an argument, but all #other ways of matching match the tag name as a string. if isinstance(markup, Tag): markup = markup.name if markup and not isString(markup): markup = unicode(markup) #Now we know that chunk is either a string, or None. if hasattr(matchAgainst, 'match'): # It's a regexp object. result = markup and matchAgainst.search(markup) elif isList(matchAgainst): result = markup in matchAgainst elif hasattr(matchAgainst, 'items'): result = markup.has_key(matchAgainst) elif matchAgainst and isString(markup): if isinstance(markup, unicode): matchAgainst = unicode(matchAgainst) else: matchAgainst = str(matchAgainst) if not result: result = matchAgainst == markup return result
Example #10
Source File: newjelly.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def _unjelly_boolean(self, exp): if BooleanType: assert exp[0] in ('true', 'false') return self.resolveReference(exp[0] == 'true') else: return self.resolveReference(Unpersistable(exp[0]))
Example #11
Source File: jelly.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def _unjelly_boolean(self, exp): if BooleanType: assert exp[0] in ('true', 'false') return exp[0] == 'true' else: return Unpersistable(exp[0])
Example #12
Source File: _bsoup.py From faces with GNU General Public License v2.0 | 5 votes |
def _matches(self, markup, matchAgainst): #print "Matching %s against %s" % (markup, matchAgainst) result = False if matchAgainst == True and type(matchAgainst) == types.BooleanType: result = markup != None elif callable(matchAgainst): result = matchAgainst(markup) else: #Custom match methods take the tag as an argument, but all #other ways of matching match the tag name as a string. if isinstance(markup, Tag): markup = markup.name if markup and not isString(markup): markup = unicode(markup) #Now we know that chunk is either a string, or None. if hasattr(matchAgainst, 'match'): # It's a regexp object. result = markup and matchAgainst.search(markup) elif isList(matchAgainst): result = markup in matchAgainst elif hasattr(matchAgainst, 'items'): result = markup.has_key(matchAgainst) elif matchAgainst and isString(markup): if isinstance(markup, unicode): matchAgainst = unicode(matchAgainst) else: matchAgainst = str(matchAgainst) if not result: result = matchAgainst == markup return result
Example #13
Source File: BeautifulSoup.py From python-for-android with Apache License 2.0 | 5 votes |
def _matches(self, markup, matchAgainst): #print "Matching %s against %s" % (markup, matchAgainst) result = False if matchAgainst == True and type(matchAgainst) == types.BooleanType: result = markup != None elif callable(matchAgainst): result = matchAgainst(markup) else: #Custom match methods take the tag as an argument, but all #other ways of matching match the tag name as a string. if isinstance(markup, Tag): markup = markup.name if markup is not None and not isString(markup): markup = unicode(markup) #Now we know that chunk is either a string, or None. if hasattr(matchAgainst, 'match'): # It's a regexp object. result = markup and matchAgainst.search(markup) elif (isList(matchAgainst) and (markup is not None or not isString(matchAgainst))): result = markup in matchAgainst elif hasattr(matchAgainst, 'items'): result = markup.has_key(matchAgainst) elif matchAgainst and isString(markup): if isinstance(markup, unicode): matchAgainst = unicode(matchAgainst) else: matchAgainst = str(matchAgainst) if not result: result = matchAgainst == markup return result
Example #14
Source File: jelly.py From python-for-android with Apache License 2.0 | 5 votes |
def _unjelly_boolean(self, exp): if BooleanType: assert exp[0] in ('true', 'false') return exp[0] == 'true' else: return Unpersistable("Could not unpersist boolean: %s" % (exp[0],))
Example #15
Source File: openshift_provision.py From dev-track with GNU General Public License v3.0 | 5 votes |
def __init__(self, module): self.module = module self.changed = False self.action = module.params['action'] self.fail_on_change = module.params['fail_on_change'] self.patch = None self.patch_type = module.params['patch_type'] self.resource = module.params['resource'] if not 'kind' in self.resource: raise Exception('resource must define kind') if not 'metadata' in self.resource: raise Exception('resource must include metadata') if not 'name' in self.resource['metadata']: raise Exception('resource metadata must include name') if 'namespace' in self.resource['metadata']: self.namespace = self.resource['metadata']['namespace'] elif 'namespace' in module.params: self.namespace = module.params['namespace'] self.resource['metadata']['namespace'] = self.namespace connection = module.params['connection'] if 'oc_cmd' in connection: self.oc_cmd = connection['oc_cmd'].split() else: self.oc_cmd = ['oc'] for opt in ['server','certificate_authority','token']: if opt in connection: self.oc_cmd += ['--' + opt.replace('_', '-') + '=' + connection[opt]] if 'insecure_skip_tls_verify' in connection: if type(connection['insecure_skip_tls_verify']) == types.BooleanType: self.oc_cmd += ['--insecure-skip-tls-verify'] elif connection['insecure_skip_tls_verify']: self.oc_cmd += ['--insecure-skip-tls-verify='+connection['insecure_skip_tls_verify']]
Example #16
Source File: BeautifulSoup.py From dirigible-spreadsheet with MIT License | 5 votes |
def _matches(self, markup, matchAgainst): #print "Matching %s against %s" % (markup, matchAgainst) result = False if matchAgainst == True and type(matchAgainst) == types.BooleanType: result = markup != None elif callable(matchAgainst): result = matchAgainst(markup) else: #Custom match methods take the tag as an argument, but all #other ways of matching match the tag name as a string. if isinstance(markup, Tag): markup = markup.name if markup is not None and not isString(markup): markup = unicode(markup) #Now we know that chunk is either a string, or None. if hasattr(matchAgainst, 'match'): # It's a regexp object. result = markup and matchAgainst.search(markup) elif (isList(matchAgainst) and (markup is not None or not isString(matchAgainst))): result = markup in matchAgainst elif hasattr(matchAgainst, 'items'): result = markup.has_key(matchAgainst) elif matchAgainst and isString(markup): if isinstance(markup, unicode): matchAgainst = unicode(matchAgainst) else: matchAgainst = str(matchAgainst) if not result: result = matchAgainst == markup return result
Example #17
Source File: atomic.py From atomos with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __setattr__(self, name, value): # Ensure the `value` attribute is always a bool. if name == '_value' and not isinstance(value, types.BooleanType): raise TypeError('_value must be of type bool') super(AtomicBoolean, self).__setattr__(name, value)
Example #18
Source File: inifile.py From python-scripts with GNU General Public License v3.0 | 4 votes |
def ini_write(f, d, comment=''): try: a = {'default':{}} for k,v in d.items(): assert type(k) == StringType k = k.lower() if type(v) == DictType: if DEBUG: print 'new section:' +k if k: assert not a.has_key(k) a[k] = {} aa = a[k] for kk,vv in v: assert type(kk) == StringType kk = kk.lower() assert not aa.has_key(kk) if type(vv) == BooleanType: vv = int(vv) if type(vv) == StringType: vv = '"'+vv+'"' aa[kk] = str(vv) if DEBUG: print 'a['+k+']['+kk+'] = '+str(vv) else: aa = a[''] assert not aa.has_key(k) if type(v) == BooleanType: v = int(v) if type(v) == StringType: v = '"'+v+'"' aa[k] = str(v) if DEBUG: print 'a[\'\']['+k+'] = '+str(v) r = open(f,'w') if comment: for c in comment.split('\n'): r.write('# '+c+'\n') r.write('\n') l = a.keys() l.sort() for k in l: if k: r.write('\n['+k+']\n') aa = a[k] ll = aa.keys() ll.sort() for kk in ll: r.write(kk+' = '+aa[kk]+'\n') success = True except: if DEBUG: print_exc() success = False try: r.close() except: pass return success
Example #19
Source File: humannum.py From pykit with MIT License | 4 votes |
def humannum(data, unit=None, include=None, exclude=None): if isinstance(data, types.DictType): data = data.copy() keys = set(data.keys()) if include is not None: keys = keys & set(include) if exclude is not None: keys = keys - set(exclude) for k in keys: data[k] = humannum(data[k]) return data elif isinstance(data, types.BooleanType): # We have to deal with bool because for historical reason bool is # subclass of int. # When bool is introduced into python 2.2 it is represented with int, # similar to C. return data elif isinstance(data, types.ListType): return [humannum(x) for x in data] elif isinstance(data, types.StringTypes): return data elif isinstance(data, integer_types): return humannum_int(data, unit=unit) elif isinstance(data, types.FloatType): if data > 999: return humannum_int(int(data), unit=unit) elif abs(data) < 0.0000000001: return '0' else: return '%.2f' % (data) else: return data