本文整理汇总了Python中types.TupleType方法的典型用法代码示例。如果您正苦于以下问题:Python types.TupleType方法的具体用法?Python types.TupleType怎么用?Python types.TupleType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types
的用法示例。
在下文中一共展示了types.TupleType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_headers
# 需要导入模块: import types [as 别名]
# 或者: from types import TupleType [as 别名]
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)))
示例2: decrypt
# 需要导入模块: import types [as 别名]
# 或者: from types import TupleType [as 别名]
def decrypt(self, ciphertext):
"""Decrypt a piece of data.
:Parameter ciphertext: The piece of data to decrypt.
:Type ciphertext: byte string, long or a 2-item tuple as returned by `encrypt`
:Return: A byte string if ciphertext was a byte string or a tuple
of byte strings. A long otherwise.
"""
wasString=0
if not isinstance(ciphertext, types.TupleType):
ciphertext=(ciphertext,)
if isinstance(ciphertext[0], types.StringType):
ciphertext=tuple(map(bytes_to_long, ciphertext)) ; wasString=1
plaintext=self._decrypt(ciphertext)
if wasString: return long_to_bytes(plaintext)
else: return plaintext
示例3: check_headers
# 需要导入模块: import types [as 别名]
# 或者: from types import TupleType [as 别名]
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)))
示例4: isAmbivalent
# 需要导入模块: import types [as 别名]
# 或者: from types import TupleType [as 别名]
def isAmbivalent(self, dim=None):
"""
Return True if any of the factors are in fact tuples.
If a dimension name is given only that dimension is tested.
::
>>> l = Location(pop=1)
>>> l.isAmbivalent()
False
>>> l = Location(pop=1, snap=(100, -100))
>>> l.isAmbivalent()
True
"""
if dim is not None:
try:
return type(self[dim]) == TupleType
except KeyError:
# dimension is not present, it should be 0, so not ambivalent
return False
for dim, val in self.items():
if type(val) == TupleType:
return True
return False
示例5: split
# 需要导入模块: import types [as 别名]
# 或者: from types import TupleType [as 别名]
def split(self):
"""
Split an ambivalent location into 2. One for the x, the other for the y.
::
>>> l = Location(pop=(-5,5))
>>> l.split()
(<Location pop:-5 >, <Location pop:5 >)
"""
x = self.__class__()
y = self.__class__()
for dim, val in self.items():
if type(val) == TupleType:
x[dim] = val[0]
y[dim] = val[1]
else:
x[dim] = val
y[dim] = val
return x, y
示例6: spliceX
# 需要导入模块: import types [as 别名]
# 或者: from types import TupleType [as 别名]
def spliceX(self):
"""
Return a copy with the x values preferred for ambivalent locations.
::
>>> l = Location(pop=(-5,5))
>>> l.spliceX()
<Location pop:-5 >
"""
new = self.__class__()
for dim, val in self.items():
if type(val) == TupleType:
new[dim] = val[0]
else:
new[dim] = val
return new
示例7: spliceY
# 需要导入模块: import types [as 别名]
# 或者: from types import TupleType [as 别名]
def spliceY(self):
"""
Return a copy with the y values preferred for ambivalent locations.
::
>>> l = Location(pop=(-5,5))
>>> l.spliceY()
<Location pop:5 >
"""
new = self.__class__()
for dim, val in self.items():
if type(val) == TupleType:
new[dim] = val[1]
else:
new[dim] = val
return new
示例8: __init__
# 需要导入模块: import types [as 别名]
# 或者: from types import TupleType [as 别名]
def __init__(self, name, enumList):
self.__doc__ = name
lookup = { }
reverseLookup = { }
i = 0
uniqueNames = [ ]
uniqueValues = [ ]
for x in enumList:
if type(x) == types.TupleType:
x, i = x
if type(x) != types.StringType:
raise EnumException, "enum name is not a string: " + x
if type(i) != types.IntType:
raise EnumException, "enum value is not an integer: " + i
if x in uniqueNames:
raise EnumException, "enum name is not unique: " + x
if i in uniqueValues:
raise EnumException, "enum value is not unique for " + x
uniqueNames.append(x)
uniqueValues.append(i)
lookup[x] = i
reverseLookup[i] = x
i = i + 1
self.lookup = lookup
self.reverseLookup = reverseLookup
示例9: new_looper
# 需要导入模块: import types [as 别名]
# 或者: from types import TupleType [as 别名]
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)
示例10: __init__
# 需要导入模块: import types [as 别名]
# 或者: from types import TupleType [as 别名]
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)
示例11: send_resp_header
# 需要导入模块: import types [as 别名]
# 或者: from types import TupleType [as 别名]
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()
示例12: send_resp_header
# 需要导入模块: import types [as 别名]
# 或者: from types import TupleType [as 别名]
def send_resp_header(self, cont_type, cont_length, range=False): # @ReservedAssignment
if range:
self.send_response(206, 'Partial Content')
else:
self.send_response(200, 'OK')
self.send_header('Content-Type', cont_type)
self.send_header('transferMode.dlna.org', 'Streaming')
self.send_header('contentFeatures.dlna.org',
'DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01700000000000000000000000000000')
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', cont_length)
self.finish_header()
示例13: _tag
# 需要导入模块: import types [as 别名]
# 或者: from types import TupleType [as 别名]
def _tag(self, tok):
if type(tok) == types.TupleType:
return tok[1]
elif isinstance(tok, Tree):
return tok.node
else:
raise ValueError, 'chunk structures must contain tokens and trees'
示例14: add
# 需要导入模块: import types [as 别名]
# 或者: from types import TupleType [as 别名]
def add(self, event, new_state,
TupleType = TupleType):
"""
Add transition to |new_state| on |event|.
"""
if type(event) == TupleType:
code0, code1 = event
i = self.split(code0)
j = self.split(code1)
map = self.map
while i < j:
map[i + 1][new_state] = 1
i = i + 2
else:
self.get_special(event)[new_state] = 1
示例15: add_set
# 需要导入模块: import types [as 别名]
# 或者: from types import TupleType [as 别名]
def add_set(self, event, new_set,
TupleType = TupleType):
"""
Add transitions to the states in |new_set| on |event|.
"""
if type(event) == TupleType:
code0, code1 = event
i = self.split(code0)
j = self.split(code1)
map = self.map
while i < j:
map[i + 1].update(new_set)
i = i + 2
else:
self.get_special(event).update(new_set)