当前位置: 首页>>代码示例>>Python>>正文


Python sys.intern方法代码示例

本文整理汇总了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) 
开发者ID:SylvainDe,项目名称:DidYouMean-Python,代码行数:25,代码来源:didyoumean_sugg_tests.py

示例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 
开发者ID:google,项目名称:rekall,代码行数:24,代码来源:utils.py

示例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): 
开发者ID:Autodesk,项目名称:arnold-usd,代码行数:22,代码来源:Util.py

示例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. 
开发者ID:coin3d,项目名称:pivy,代码行数:19,代码来源:Util.py

示例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): 
开发者ID:coin3d,项目名称:pivy,代码行数:23,代码来源:Util.py

示例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 
开发者ID:holzschu,项目名称:python3_ios,代码行数:26,代码来源:fixdiv.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:pickle.py

示例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 
开发者ID:PhonologicalCorpusTools,项目名称:CorpusTools,代码行数:22,代码来源:multiple_files.py

示例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 = '' 
开发者ID:nojanath,项目名称:SublimeKSP,代码行数:12,代码来源:ksp_ast.py

示例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) 
开发者ID:SylvainDe,项目名称:DidYouMean-Python,代码行数:11,代码来源:didyoumean_sugg_tests.py

示例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) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:16,代码来源:test_fixers.py

示例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 
开发者ID:remg427,项目名称:misp42splunk,代码行数:16,代码来源:test_fixers.py

示例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) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:17,代码来源:test_fixers.py

示例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 
开发者ID:salesforce,项目名称:decaNLP,代码行数:12,代码来源:example.py

示例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)) 
开发者ID:google,项目名称:rekall,代码行数:7,代码来源:utils.py


注:本文中的sys.intern方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。