本文整理汇总了Python中sys.intern方法的典型用法代码示例。如果您正苦于以下问题:Python sys.intern方法的具体用法?Python sys.intern怎么用?Python sys.intern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys
的用法示例。
在下文中一共展示了sys.intern方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_removed_3_0
# 需要导入模块: import sys [as 别名]
# 或者: from sys import intern [as 别名]
def test_removed_3_0(self):
"""Test for names removed in 3.0."""
before, after = before_and_after((3, 0))
for name, suggs in {
'StandardError': [STDERR_REMOVED_MSG],
'apply': [APPLY_REMOVED_MSG],
'basestring': [],
'buffer': [BUFFER_REMOVED_MSG],
'cmp': [CMP_REMOVED_MSG],
'coerce': [],
'execfile': [],
'file': ["'filter' (builtin)"],
'intern': ["'iter' (builtin)", "'sys.intern'"],
'long': [LONG_REMOVED_MSG],
'raw_input': ["'input' (builtin)"],
'reduce': ["'reduce' from functools (not imported)"],
'reload': [RELOAD_REMOVED_MSG],
'unichr': [],
'unicode': ["'code' (local)"],
'xrange': ["'range' (builtin)"],
}.items():
self.runs(name, before)
self.throws(name, NAMEERROR, suggs, after)
示例2: InternObject
# 需要导入模块: import sys [as 别名]
# 或者: from sys import intern [as 别名]
def InternObject(obj):
"""Copies and interns strings in a recursive object."""
obj_cls = obj.__class__
if obj_cls is str:
return sys.intern(obj)
if obj_cls is str:
return sys.intern(str(obj))
if obj_cls is dict:
result = {}
for k, v in list(obj.items()):
k = InternObject(k)
v = InternObject(v)
result[k] = v
return result
if obj_cls is list:
return [InternObject(x) for x in obj]
return obj
示例3: silent_intern
# 需要导入模块: import sys [as 别名]
# 或者: from sys import intern [as 别名]
def silent_intern(x):
"""
Perform sys.intern() on the passed argument and return the result.
If the input is ineligible (e.g. a unicode string) the original argument is
returned and no exception is thrown.
"""
try:
return sys.intern(x)
except TypeError:
return x
# From Dinu C. Gherman,
# Python Cookbook, second edition, recipe 6.17, p. 277.
# Also:
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/68205
# ASPN: Python Cookbook: Null Object Design Pattern
#TODO??? class Null(object):
示例4: MD5collect
# 需要导入模块: import sys [as 别名]
# 或者: from sys import intern [as 别名]
def MD5collect(signatures):
"""
Collects a list of signatures into an aggregate signature.
signatures - a list of signatures
returns - the aggregate signature
"""
if len(signatures) == 1:
return signatures[0]
else:
return MD5signature(string.join(signatures, ', '))
# Wrap the intern() function so it doesn't throw exceptions if ineligible
# arguments are passed. The intern() function was moved into the sys module in
# Python 3.
示例5: silent_intern
# 需要导入模块: import sys [as 别名]
# 或者: from sys import intern [as 别名]
def silent_intern(x):
"""
Perform intern() on the passed argument and return the result.
If the input is ineligible (e.g. a unicode string) the original argument is
returned and no exception is thrown.
"""
try:
return sys.intern(x)
except TypeError:
return x
# From Dinu C. Gherman,
# Python Cookbook, second edition, recipe 6.17, p. 277.
# Also:
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/68205
# ASPN: Python Cookbook: Null Object Design Pattern
# TODO(1.5):
#class Null(object):
示例6: readwarnings
# 需要导入模块: import sys [as 别名]
# 或者: from sys import intern [as 别名]
def readwarnings(warningsfile):
prog = re.compile(PATTERN)
try:
f = open(warningsfile)
except IOError as msg:
sys.stderr.write("can't open: %s\n" % msg)
return
warnings = {}
while 1:
line = f.readline()
if not line:
break
m = prog.match(line)
if not m:
if line.find("division") >= 0:
sys.stderr.write("Warning: ignored input " + line)
continue
filename, lineno, what = m.groups()
list = warnings.get(filename)
if list is None:
warnings[filename] = list = []
list.append((int(lineno), sys.intern(what)))
f.close()
return warnings
示例7: load_build
# 需要导入模块: import sys [as 别名]
# 或者: from sys import intern [as 别名]
def load_build(self):
stack = self.stack
state = stack.pop()
inst = stack[-1]
setstate = getattr(inst, "__setstate__", None)
if setstate is not None:
setstate(state)
return
slotstate = None
if isinstance(state, tuple) and len(state) == 2:
state, slotstate = state
if state:
inst_dict = inst.__dict__
intern = sys.intern
for k, v in state.items():
if type(k) is str:
inst_dict[intern(k)] = v
else:
inst_dict[k] = v
if slotstate:
for k, v in slotstate.items():
setattr(inst, k, v)
示例8: read_phones
# 需要导入模块: import sys [as 别名]
# 或者: from sys import intern [as 别名]
def read_phones(path, dialect, sr = None):
output = []
with open(path,'r') as file_handle:
if dialect == 'buckeye':
header_pattern = re.compile("#\r{0,1}\n")
line_pattern = re.compile("\s+\d{3}\s+")
label_pattern = re.compile(" {0,1};| {0,1}\+")
f = header_pattern.split(file_handle.read())[1]
flist = f.splitlines()
begin = 0.0
for l in flist:
line = line_pattern.split(l.strip())
end = float(line[0])
label = sys.intern(label_pattern.split(line[1])[0])
output.append(BaseAnnotation(label, begin, end))
begin = end
else:
raise(NotImplementedError)
return output
示例9: set_identifier
# 需要导入模块: import sys [as 别名]
# 或者: from sys import intern [as 别名]
def set_identifier(self, identifier):
self._identifier = str(identifier)
sys.intern(self._identifier)
# identifier_first_part represents the part of the name in front of the first dot (if any), eg. for myfamily.myvar it would represent myfamily
if '.' in identifier:
self.identifier_first_part = identifier[:identifier.index('.')]
self.identifier_last_part = identifier[identifier.index('.'):]
else:
self.identifier_first_part = identifier
self.identifier_last_part = ''
示例10: test_removed_intern
# 需要导入模块: import sys [as 别名]
# 或者: from sys import intern [as 别名]
def test_removed_intern(self):
"""Builtin intern is removed - moved to sys."""
code = 'intern("toto")'
new_code = 'sys.intern("toto")'
suggs = ["'iter' (builtin)", "'sys.intern'"]
before, after = before_and_after((3, 0))
self.runs(code, before)
self.throws(code, NAMEERROR, suggs, after)
self.runs(new_code, after)
示例11: test_prefix_preservation
# 需要导入模块: import sys [as 别名]
# 或者: from sys import intern [as 别名]
def test_prefix_preservation(self):
b = """x = intern( a )"""
a = """import sys\nx = sys.intern( a )"""
self.check(b, a)
b = """y = intern("b" # test
)"""
a = """import sys\ny = sys.intern("b" # test
)"""
self.check(b, a)
b = """z = intern(a+b+c.d, )"""
a = """import sys\nz = sys.intern(a+b+c.d, )"""
self.check(b, a)
示例12: test
# 需要导入模块: import sys [as 别名]
# 或者: from sys import intern [as 别名]
def test(self):
b = """x = intern(a)"""
a = """import sys\nx = sys.intern(a)"""
self.check(b, a)
b = """z = intern(a+b+c.d,)"""
a = """import sys\nz = sys.intern(a+b+c.d,)"""
self.check(b, a)
b = """intern("y%s" % 5).replace("y", "")"""
a = """import sys\nsys.intern("y%s" % 5).replace("y", "")"""
self.check(b, a)
# These should not be refactored
示例13: test_unchanged
# 需要导入模块: import sys [as 别名]
# 或者: from sys import intern [as 别名]
def test_unchanged(self):
s = """intern(a=1)"""
self.unchanged(s)
s = """intern(f, g)"""
self.unchanged(s)
s = """intern(*h)"""
self.unchanged(s)
s = """intern(**i)"""
self.unchanged(s)
s = """intern()"""
self.unchanged(s)
示例14: intern_strings
# 需要导入模块: import sys [as 别名]
# 或者: from sys import intern [as 别名]
def intern_strings(x):
if isinstance(x, (list, tuple)):
r = []
for y in x:
if isinstance(y, str):
r.append(sys.intern(y))
else:
r.append(y)
return r
return x
示例15: intern_str
# 需要导入模块: import sys [as 别名]
# 或者: from sys import intern [as 别名]
def intern_str(string):
if six.PY3:
return sys.intern(str(string))
return intern(str(string))