Python types.ListType() Examples
The following are 30
code examples of types.ListType().
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: validate.py From pmatic with GNU General Public License v2.0 | 6 votes |
def check_headers(headers): assert_(type(headers) is ListType, "Headers (%r) must be of type list: %r" % (headers, type(headers))) header_names = {} for item in headers: assert_(type(item) is TupleType, "Individual headers (%r) must be of type tuple: %r" % (item, type(item))) assert_(len(item) == 2) name, value = item assert_(name.lower() != 'status', "The Status header cannot be used; it conflicts with CGI " "script, and HTTP status is not given through headers " "(value: %r)." % value) header_names[name.lower()] = None assert_('\n' not in name and ':' not in name, "Header names may not contain ':' or '\\n': %r" % name) assert_(header_re.search(name), "Bad header name: %r" % name) assert_(not name.endswith('-') and not name.endswith('_'), "Names may not end in '-' or '_': %r" % name) if bad_header_value_re.search(value): assert_(0, "Bad header value: %r (bad char: %r)" % (value, bad_header_value_re.search(value).group(0)))
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: validate.py From meddle with MIT License | 6 votes |
def check_headers(headers): assert_(type(headers) is ListType, "Headers (%r) must be of type list: %r" % (headers, type(headers))) header_names = {} for item in headers: assert_(type(item) is TupleType, "Individual headers (%r) must be of type tuple: %r" % (item, type(item))) assert_(len(item) == 2) name, value = item assert_(name.lower() != 'status', "The Status header cannot be used; it conflicts with CGI " "script, and HTTP status is not given through headers " "(value: %r)." % value) header_names[name.lower()] = None assert_('\n' not in name and ':' not in name, "Header names may not contain ':' or '\\n': %r" % name) assert_(header_re.search(name), "Bad header name: %r" % name) assert_(not name.endswith('-') and not name.endswith('_'), "Names may not end in '-' or '_': %r" % name) if bad_header_value_re.search(value): assert_(0, "Bad header value: %r (bad char: %r)" % (value, bad_header_value_re.search(value).group(0)))
Example #4
Source File: recipe-223610.py From code with MIT License | 6 votes |
def __init__(self,rowset,description): # save the description as is self.description = fRow(description) self.description.__Field2Index__ = self.__fieldToIndex # Create the list and dict of fields self.fields = [] self.__fieldDict = {} for f in range(len(description)): if type(description[f]) == types.TupleType or type(description[f]) == types.ListType: self.__fieldDict[description[f][0].lower()] = f self.fields.append( description[f][0].lower()) else: self.__fieldDict[description[f].lower()] = f self.fields.append( description[f].lower()) # Add all the rows for r in rowset: self.append(r)
Example #5
Source File: validate.py From ironpython2 with Apache License 2.0 | 6 votes |
def check_headers(headers): assert_(type(headers) is ListType, "Headers (%r) must be of type list: %r" % (headers, type(headers))) header_names = {} for item in headers: assert_(type(item) is TupleType, "Individual headers (%r) must be of type tuple: %r" % (item, type(item))) assert_(len(item) == 2) name, value = item assert_(name.lower() != 'status', "The Status header cannot be used; it conflicts with CGI " "script, and HTTP status is not given through headers " "(value: %r)." % value) header_names[name.lower()] = None assert_('\n' not in name and ':' not in name, "Header names may not contain ':' or '\\n': %r" % name) assert_(header_re.search(name), "Bad header name: %r" % name) assert_(not name.endswith('-') and not name.endswith('_'), "Names may not end in '-' or '_': %r" % name) if bad_header_value_re.search(value): assert_(0, "Bad header value: %r (bad char: %r)" % (value, bad_header_value_re.search(value).group(0)))
Example #6
Source File: lint.py From mishkal with GNU General Public License v3.0 | 6 votes |
def check_headers(headers): assert type(headers) is ListType, ( "Headers (%r) must be of type list: %r" % (headers, type(headers))) header_names = {} for item in headers: assert type(item) is TupleType, ( "Individual headers (%r) must be of type tuple: %r" % (item, type(item))) assert len(item) == 2 name, value = item assert name.lower() != 'status', ( "The Status header cannot be used; it conflicts with CGI " "script, and HTTP status is not given through headers " "(value: %r)." % value) header_names[name.lower()] = None assert '\n' not in name and ':' not in name, ( "Header names may not contain ':' or '\\n': %r" % name) assert header_re.search(name), "Bad header name: %r" % name assert not name.endswith('-') and not name.endswith('_'), ( "Names may not end in '-' or '_': %r" % name) assert not bad_header_value_re.search(value), ( "Bad header value: %r (bad char: %r)" % (value, bad_header_value_re.search(value).group(0)))
Example #7
Source File: QuestPath.py From Pirates-Online-Rewritten with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _asString(self): if self.__goalDataStr != None: return self.__goalDataStr if self.__goalData == None: resultStr = '' if self.__goalType == types.ListType: resultStr = str(self.__goalData) else: strRep = '' for currField in range(self.MAX_IDX): strRep += str(self.__goalData.get(currField, None)) strRep += '-' resultStr = strRep self.__goalDataStr = resultStr return resultStr
Example #8
Source File: admin.py From uac-a-mola with GNU General Public License v3.0 | 6 votes |
def runAsAdmin(cmdLine=None, wait=True): if os.name != 'nt': raise RuntimeError, "This function is only implemented on Windows." import win32api import win32con import win32event import win32process from win32com.shell.shell import ShellExecuteEx from win32com.shell import shellcon python_exe = sys.executable if cmdLine is None: cmdLine = [python_exe] + sys.argv elif type(cmdLine) not in (types.TupleType, types.ListType): raise ValueError, "cmdLine is not a sequence." cmd = '"%s"' % (cmdLine[0],) # XXX TODO: isn't there a function or something we can call to massage command line params? params = " ".join(['"%s"' % (x,) for x in cmdLine[1:]]) cmdDir = '' #showCmd = win32con.SW_SHOWNORMAL showCmd = win32con.SW_HIDE lpVerb = 'runas' # causes UAC elevation prompt. # print "Running", cmd, params # ShellExecute() doesn't seem to allow us to fetch the PID or handle # of the process, so we can't get anything useful from it. Therefore # the more complex ShellExecuteEx() must be used. # procHandle = win32api.ShellExecute(0, lpVerb, cmd, params, cmdDir, showCmd) procInfo = ShellExecuteEx(nShow=showCmd, fMask=shellcon.SEE_MASK_NOCLOSEPROCESS, lpVerb=lpVerb, lpFile=cmd, lpParameters=params) if wait: procHandle = procInfo['hProcess'] obj = win32event.WaitForSingleObject(procHandle, win32event.INFINITE) rc = win32process.GetExitCodeProcess(procHandle) # print "Process handle %s returned code %s" % (procHandle, rc) else: rc = None return rc
Example #9
Source File: handler.py From addon with GNU General Public License v3.0 | 6 votes |
def send_resp_header(self, cont_type, size, range=False): if range: self.send_response(206, 'Partial Content') else: self.send_response(200, 'OK') self.send_header('Content-Type', cont_type) self.send_header('Accept-Ranges', 'bytes') if range: if isinstance(range, (types.TupleType, types.ListType)) and len(range)==3: self.send_header('Content-Range', 'bytes %d-%d/%d' % range) self.send_header('Content-Length', range[1]-range[0]+1) else: raise ValueError('Invalid range value') else: self.send_header('Content-Length', size) self.send_header('Connection', 'close') self.end_headers()
Example #10
Source File: QuestPath.py From Pirates-Online-Rewritten with BSD 3-Clause "New" or "Revised" License | 6 votes |
def getGoalIds(self, uidMgr=None, all=True): if all: results = [ (0, '')] else: results = '' if self.__goalType == types.ListType: if all: uidData = self.__goalData else: uidData = self.__goalData[:1] if uidMgr: results = zip(map(lambda x: uidMgr.getDoId(x, None), uidData), uidData) elif len(uidData) == 0: results = '' else: results = uidData[0] return results
Example #11
Source File: AnimationMixer.py From Pirates-Online-Rewritten with BSD 3-Clause "New" or "Revised" License | 6 votes |
def getPartsNameList(self, sectionName): outList = [] if sectionName is None or set(sectionName) == set(self.sectionNames): return else: if isinstance(sectionName, types.StringType): sectionNames = [ sectionName] elif isinstance(sectionName, types.ListType): sectionNames = sectionName else: sectionNames = [] for section in sectionNames: partList = self.partNameLists.get(section) if partList: outList.extend(partList) return outList
Example #12
Source File: Base.py From mailin with MIT License | 6 votes |
def argparse(self,name,args): if not name and self.defaults.has_key('name'): args['name'] = self.defaults['name'] if type(name) is types.StringType: args['name']=name else: if len(name) == 1: if name[0]: args['name']=name[0] if defaults['server_rotate'] and \ type(defaults['server']) == types.ListType: defaults['server'] = defaults['server'][1:]+defaults['server'][:1] for i in defaults.keys(): if not args.has_key(i): if self.defaults.has_key(i): args[i]=self.defaults[i] else: args[i]=defaults[i] if type(args['server']) == types.StringType: args['server'] = [args['server']] self.args=args
Example #13
Source File: influx.py From kotori with GNU Affero General Public License v3.0 | 6 votes |
def process_message(self, topic, payload, *args): log.debug('Bus receive: topic={topic}, payload={payload}', topic=topic, payload=payload) # TODO: filter by realm/topic # decode message if type(payload) is types.DictionaryType: message = payload.copy() elif type(payload) is types.ListType: message = OrderedDict(payload) else: raise TypeError('Unable to handle data type "{}" from bus'.format(type(payload))) # compute storage location from topic and message storage_location = self.storage_location(message) log.debug('Storage location: {storage_location}', storage_location=dict(storage_location)) # store data self.store_message(storage_location, message)
Example #14
Source File: _version200.py From baidupan_shell with GNU General Public License v2.0 | 6 votes |
def str642int(string): """Converts a base64 encoded string into an integer. The chars of this string in in the range '0'-'9','A'-'Z','a'-'z','-','_' >>> str642int('7MyqL') 123456789 """ if not (type(string) is types.ListType or type(string) is types.StringType): raise TypeError("You must pass a string or a list") integer = 0 for byte in string: integer *= 64 if type(byte) is types.StringType: byte = ord(byte) integer += from64(byte) return integer
Example #15
Source File: validate.py From BinderFilter with MIT License | 6 votes |
def check_headers(headers): assert_(type(headers) is ListType, "Headers (%r) must be of type list: %r" % (headers, type(headers))) header_names = {} for item in headers: assert_(type(item) is TupleType, "Individual headers (%r) must be of type tuple: %r" % (item, type(item))) assert_(len(item) == 2) name, value = item assert_(name.lower() != 'status', "The Status header cannot be used; it conflicts with CGI " "script, and HTTP status is not given through headers " "(value: %r)." % value) header_names[name.lower()] = None assert_('\n' not in name and ':' not in name, "Header names may not contain ':' or '\\n': %r" % name) assert_(header_re.search(name), "Bad header name: %r" % name) assert_(not name.endswith('-') and not name.endswith('_'), "Names may not end in '-' or '_': %r" % name) if bad_header_value_re.search(value): assert_(0, "Bad header value: %r (bad char: %r)" % (value, bad_header_value_re.search(value).group(0)))
Example #16
Source File: _version200.py From baidupan_shell with GNU General Public License v2.0 | 6 votes |
def bytes2int(bytes): """Converts a list of bytes or a string to an integer >>> (((128 * 256) + 64) * 256) + 15 8405007 >>> l = [128, 64, 15] >>> bytes2int(l) #same as bytes2int('\x80@\x0f') 8405007 """ if not (type(bytes) is types.ListType or type(bytes) is types.StringType): raise TypeError("You must pass a string or a list") # Convert byte stream to integer integer = 0 for byte in bytes: integer *= 256 if type(byte) is types.StringType: byte = ord(byte) integer += byte return integer
Example #17
Source File: _version133.py From baidupan_shell with GNU General Public License v2.0 | 6 votes |
def bytes2int(bytes): """Converts a list of bytes or a string to an integer >>> (128*256 + 64)*256 + + 15 8405007 >>> l = [128, 64, 15] >>> bytes2int(l) 8405007 """ if not (type(bytes) is types.ListType or type(bytes) is types.StringType): raise TypeError("You must pass a string or a list") # Convert byte stream to integer integer = 0 for byte in bytes: integer *= 256 if type(byte) is types.StringType: byte = ord(byte) integer += byte return integer
Example #18
Source File: TorrentDef.py From p2ptv-pi with MIT License | 6 votes |
def set_dht_nodes(self, nodes): if self.readonly: raise OperationNotPossibleAtRuntimeException() if type(nodes) != ListType: raise ValueError('nodes not a list') else: for node in nodes: if type(node) != ListType and len(node) != 2: raise ValueError('node in nodes not a 2-item list: ' + `node`) if type(node[0]) != StringType: raise ValueError('host in node is not string:' + `node`) if type(node[1]) != IntType: raise ValueError('port in node is not int:' + `node`) self.input['nodes'] = nodes self.metainfo_valid = False
Example #19
Source File: TorrentDef.py From p2ptv-pi with MIT License | 6 votes |
def set_tracker_hierarchy(self, hier): if self.readonly: raise OperationNotPossibleAtRuntimeException() newhier = [] if type(hier) != ListType: raise ValueError('hierarchy is not a list') for tier in hier: if type(tier) != ListType: raise ValueError('tier is not a list') newtier = [] for url in tier: if not isValidURL(url): raise ValueError('Invalid URL: ' + `url`) if url.endswith('/'): url = url[:-1] newtier.append(url) newhier.append(newtier) self.input['announce-list'] = newhier self.metainfo_valid = False
Example #20
Source File: NatCheckMsgHandler.py From p2ptv-pi with MIT License | 6 votes |
def validNatCheckReplyMsg(self, ncr_data): if not type(ncr_data) == ListType: raise RuntimeError, 'NatCheckMsgHandler: received data is not valid. It must be a list of parameters.' return False if not type(ncr_data[0]) == StringType: raise RuntimeError, 'NatCheckMsgHandler: received data is not valid. The first element in the list must be a string.' return False if not type(ncr_data[1]) == IntType: raise RuntimeError, 'NatCheckMsgHandler: received data is not valid. The second element in the list must be an integer.' return False if not type(ncr_data[2]) == IntType: raise RuntimeError, 'NatCheckMsgHandler: received data is not valid. The third element in the list must be an integer.' return False if not type(ncr_data[3]) == StringType: raise RuntimeError, 'NatCheckMsgHandler: received data is not valid. The forth element in the list must be a string.' return False if not type(ncr_data[4]) == IntType: raise RuntimeError, 'NatCheckMsgHandler: received data is not valid. The fifth element in the list must be an integer.' return False if not type(ncr_data[5]) == StringType: raise RuntimeError, 'NatCheckMsgHandler: received data is not valid. The sixth element in the list must be a string.' return False if not type(ncr_data[6]) == IntType: raise RuntimeError, 'NatCheckMsgHandler: received data is not valid. The seventh element in the list must be an integer.' return False
Example #21
Source File: validate.py From oss-ftp with MIT License | 6 votes |
def check_headers(headers): assert_(type(headers) is ListType, "Headers (%r) must be of type list: %r" % (headers, type(headers))) header_names = {} for item in headers: assert_(type(item) is TupleType, "Individual headers (%r) must be of type tuple: %r" % (item, type(item))) assert_(len(item) == 2) name, value = item assert_(name.lower() != 'status', "The Status header cannot be used; it conflicts with CGI " "script, and HTTP status is not given through headers " "(value: %r)." % value) header_names[name.lower()] = None assert_('\n' not in name and ':' not in name, "Header names may not contain ':' or '\\n': %r" % name) assert_(header_re.search(name), "Bad header name: %r" % name) assert_(not name.endswith('-') and not name.endswith('_'), "Names may not end in '-' or '_': %r" % name) if bad_header_value_re.search(value): assert_(0, "Bad header value: %r (bad char: %r)" % (value, bad_header_value_re.search(value).group(0)))
Example #22
Source File: headers.py From pmatic with GNU General Public License v2.0 | 5 votes |
def __init__(self,headers): if type(headers) is not ListType: raise TypeError("Headers must be a list of name/value tuples") self._headers = headers
Example #23
Source File: type_system.py From hask with BSD 2-Clause "Simplified" License | 5 votes |
def __getitem__(self, item): try: if isinstance(item, ADT): return self.__instances__[id(item.__type_constructor__)] elif isinstance(typeof(item), ListType): return self.__instances__[id(type(item))] elif isinstance(item, Hask): return self.__instances__[id(typeof(item))] return self.__instances__[id(type(item))] except KeyError: raise TypeError("No instance for {0}".format(item))
Example #24
Source File: recipe-302742.py From code with MIT License | 5 votes |
def _CopyItem(self, item): """ Return shallow copy of item. If item is a sequence, recursively shallow copy each member that is also a sequence """ newitem = copy.copy(item) if type(newitem) is types.DictType: for key in newitem: if type(newitem[key]) in SeqType: newitem[key] = self._CopyItem(newitem[key]) elif type(newitem) is types.ListType: for k in range(len(newitem)): if type(newitem[k]) in SeqType: newitem[k] = self._CopyItem(newitem[k]) return newitem
Example #25
Source File: ldap_auth.py From kansha with BSD 3-Clause "New" or "Revised" License | 5 votes |
def toUTF8(v): if isinstance(v, unicode): return v.encode('utf-8') elif isinstance(v, (types.TupleType, types.ListType)): return [toUTF8(e) for e in v] elif isinstance(v, types.DictType): return dict([(toUTF8(k), toUTF8(v_)) for k, v_ in v.items()]) else: return v
Example #26
Source File: optparse.py From hacker-scripts with MIT License | 5 votes |
def _check_choice(self): if self.type == "choice": if self.choices is None: raise OptionError( "must supply a list of choices for type 'choice'", self) elif type(self.choices) not in (types.TupleType, types.ListType): raise OptionError( "choices must be a list of strings ('%s' supplied)" % str(type(self.choices)).split("'")[1], self) elif self.choices is not None: raise OptionError( "must not supply choices for type %r" % self.type, self)
Example #27
Source File: Eaglepy.py From PyEagle with GNU Lesser General Public License v2.1 | 5 votes |
def createAttribute(self,ul_name,datatype,writeable=False,readable=True,args=None): self.args = args if isinstance(datatype,ListType): self.__dict__[ul_name] = ULMethodAttribute(self,ul_name,datatype[0]) else: self.__dict__[ul_name] = ULPropertyAttribute(self,ul_name,datatype) if issubclass(datatype,(str,int,float)) and not self.args: self.simplePropertyList.append(self.__dict__[ul_name]) if ul_name == "name" and datatype == str: def rename_func(newname): globals()["rename"](self.name(),newname) self.rename = rename_func elif ul_name == "x": def move_func(unitx,unity,currentUnits=None): eaglex = configuredToEagle(unitx,currentUnits) eagley = configuredToEagle(unity,currentUnits) self.x.__dict__["cachedValue"] = eaglex self.y.__dict__["cachedValue"] = eagley globals()["move"](self.name(),unitx,unity) self.move = move_func
Example #28
Source File: optparse.py From hacker-scripts with MIT License | 5 votes |
def _check_choice(self): if self.type == "choice": if self.choices is None: raise OptionError( "must supply a list of choices for type 'choice'", self) elif type(self.choices) not in (types.TupleType, types.ListType): raise OptionError( "choices must be a list of strings ('%s' supplied)" % str(type(self.choices)).split("'")[1], self) elif self.choices is not None: raise OptionError( "must not supply choices for type %r" % self.type, self)
Example #29
Source File: _version133.py From aqua-monitor with GNU Lesser General Public License v3.0 | 5 votes |
def bytes2int(bytes): """Converts a list of bytes or a string to an integer """ if not (type(bytes) is types.ListType or type(bytes) is types.StringType): raise TypeError("You must pass a string or a list") # Convert byte stream to integer integer = 0 for byte in bytes: integer *= 256 if type(byte) is types.StringType: byte = ord(byte) integer += byte return integer
Example #30
Source File: pyjsontestrunner.py From OpenXR-SDK-Source with Apache License 2.0 | 5 votes |
def valueTreeToString(fout, value, path = '.'): ty = type(value) if ty is types.DictType: fout.write('%s={}\n' % path) suffix = path[-1] != '.' and '.' or '' names = value.keys() names.sort() for name in names: valueTreeToString(fout, value[name], path + suffix + name) elif ty is types.ListType: fout.write('%s=[]\n' % path) for index, childValue in zip(xrange(0,len(value)), value): valueTreeToString(fout, childValue, path + '[%d]' % index) elif ty is types.StringType: fout.write('%s="%s"\n' % (path,value)) elif ty is types.IntType: fout.write('%s=%d\n' % (path,value)) elif ty is types.FloatType: fout.write('%s=%.16g\n' % (path,value)) elif value is True: fout.write('%s=true\n' % path) elif value is False: fout.write('%s=false\n' % path) elif value is None: fout.write('%s=null\n' % path) else: assert False and "Unexpected value type"