• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sys.intern函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sys.intern函数的典型用法代码示例。如果您正苦于以下问题:Python intern函数的具体用法?Python intern怎么用?Python intern使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了intern函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: parse_parts

 def parse_parts(self, parts):
     parsed = []
     sep = self.sep
     altsep = self.altsep
     drv = root = ''
     it = reversed(parts)
     for part in it:
         if not part:
             continue
         if altsep:
             part = part.replace(altsep, sep)
         drv, root, rel = self.splitroot(part)
         if sep in rel:
             for x in reversed(rel.split(sep)):
                 if x and x != '.':
                     parsed.append(sys.intern(x))
         else:
             if rel and rel != '.':
                 parsed.append(sys.intern(rel))
         if drv or root:
             if not drv:
                 # If no drive is present, try to find one in the previous
                 # parts. This makes the result of parsing e.g.
                 # ("C:", "/", "a") reasonably intuitive.
                 for part in it:
                     drv = self.splitroot(part)[0]
                     if drv:
                         break
             break
     if drv or root:
         parsed.append(drv + root)
     parsed.reverse()
     return drv, root, parsed
开发者ID:SantoKo,项目名称:RPI3-Desktop,代码行数:33,代码来源:pathlib.py


示例2: __set_values_from_fields

    def __set_values_from_fields(self):

        """
        Private method that sets the correct values from the fields derived from the input line.
        :return:
        """
        self.chrom, self.start, self.end, \
            self.name, self.score, self.strand, \
            self.thick_start, self.thick_end, self.rgb, \
            self.block_count, block_sizes, block_starts = self._fields

        # Reduce memory usage
        intern(self.chrom)
        self.start = int(self.start) + 1
        self.end = int(self.end)
        self.score = float(self.score)
        self.thick_start = int(self.thick_start) + 1
        self.thick_end = int(self.thick_end)
        self.block_count = int(self.block_count)
        self.block_sizes = [int(x) for x in block_sizes.split(",")]
        self.block_starts = [int(x) for x in block_starts.split(",")]
        self.has_start_codon = None
        self.has_stop_codon = None
        self.start_codon = None
        self.stop_codon = None
        self.fasta_length = len(self)
        return
开发者ID:Jamure,项目名称:Mikado,代码行数:27,代码来源:bed12.py


示例3: parse_GFF_attribute_string

def parse_GFF_attribute_string(attrStr, extra_return_first_value=False):
    """Parses a GFF attribute string and returns it as a dictionary.

    If 'extra_return_first_value' is set, a pair is returned: the dictionary
    and the value of the first attribute. This might be useful if this is the
    ID.
    """
    if attrStr.endswith("\n"):
        attrStr = attrStr[:-1]
    d = {}
    first_val = "_unnamed_"
    for (i, attr) in zip(
            itertools.count(),
            _HTSeq.quotesafe_split(attrStr.encode())):
        attr = attr.decode()
        if _re_attr_empty.match(attr):
            continue
        if attr.count('"') not in (0, 2):
            raise ValueError(
                "The attribute string seems to contain mismatched quotes.")
        mo = _re_attr_main.match(attr)
        if not mo:
            raise ValueError("Failure parsing GFF attribute line")
        val = mo.group(2)
        if val.startswith('"') and val.endswith('"'):
            val = val[1:-1]
        d[sys.intern(mo.group(1))] = sys.intern(val)
        if extra_return_first_value and i == 0:
            first_val = val
    if extra_return_first_value:
        return (d, first_val)
    else:
        return d
开发者ID:simon-anders,项目名称:htseq,代码行数:33,代码来源:__init__.py


示例4: __set_values_from_gff

    def __set_values_from_gff(self, fasta_length):
        """
        Private method that sets the correct values from the fields derived from an input GFF line.
        :return:
        """

        (self.chrom, self.thick_start,
         self.thick_end, self.strand, self.name) = (self._line.chrom,
                                                    self._line.start,
                                                    self._line.end, self._line.strand, self._line.id)
        intern(self.chrom)
        assert self.name is not None
        self.start = 1
        self.end = fasta_length
        self.score = self._line.score
        self.rgb = None
        self.block_count = 1
        self.block_sizes = [self.thick_end - self.thick_start +1]
        self.block_starts = [self.thick_start]
        self.has_start_codon = None
        self.has_stop_codon = None
        self.start_codon = None
        self.stop_codon = None
        self.fasta_length = fasta_length
        return
开发者ID:Jamure,项目名称:Mikado,代码行数:25,代码来源:bed12.py


示例5: _mapf_signal

def _mapf_signal(member):
	mname=member.name
	iname=member.interface._name
	mtype=member.signal_type
	mtype_read=mtype.unpack
	myKeyError=KeyError
	Bus_signal=Bus.signal

	def cb(callback, slot, msg):
		callback(*mtype_read(msg))
	cb_get=cb.__get__
	def cbm(callback, slot, msg):
		callback(msg, *mtype_read(msg))
	cbm_get=cbm.__get__

	def onsignal(_pybus_bound, callback):
		bus,destination,path,data=_pybus_bound
		return Bus_signal(bus, destination, path, iname, mname, cb_get(callback))

	def onsignalm(_pybus_bound, callback):
		bus,destination,path,data=_pybus_bound
		return Bus_signal(bus, destination, path, iname, mname, cbm_get(callback))

	onsignal.__name__=_sys.intern(mname+'__onsignal')
	onsignal.__qualname__=iname+'.'+mname+'__onsignal'
	onsignalm.__name__=_sys.intern(mname+'__onsignalm')
	onsignalm.__qualname__=iname+'.'+mname+'__onsignalm'

	return (onsignal,onsignalm)
开发者ID:pybus,项目名称:pybus,代码行数:29,代码来源:__init__.py


示例6: load_dict

    def load_dict(self, state, exclude_utr=False, protein_coding=False):

        for key in ["chrom", "source", "start", "end", "strand", "id"]:
            setattr(self, key, state[key])

        for tid, tvalues in state["transcripts"].items():
            transcript = Transcript(logger=self.logger)
            transcript.load_dict(tvalues)
            transcript.finalize()
            if protein_coding is True and transcript.is_coding is False:
                self.logger.debug("{0} is non coding ({1}, {2})".format(
                    transcript.id,
                    transcript.combined_cds,
                    transcript.segments))
                continue
            if exclude_utr is True:
                has_utrs = (transcript.utr_length > 0)
                transcript.remove_utrs()
                if has_utrs is True and (transcript.utr_length > 0):
                    raise AssertionError("Failed to remove the UTRs!")
            self.transcripts[tid] = transcript

        self.chrom = intern(self.chrom)
        self.source = intern(self.source)
        self.id = intern(self.id)

        return
开发者ID:Jamure,项目名称:Mikado,代码行数:27,代码来源:reference_gene.py


示例7: read_sources_file

def read_sources_file(filename, sources=None, intern=sys.intern):
    """Parse a single Sources file into a hash

    Parse a single Sources file into a dict mapping a source package
    name to a SourcePackage object.  If there are multiple source
    packages with the same version, then highest versioned source
    package (that is not marked as "Extra-Source-Only") is the
    version kept in the dict.

    :param filename: Path to the Sources file.  Can be compressed by any algorithm supported by apt_pkg.TagFile
    :param sources: Optional dict to add the packages to.  If given, this is also the value returned.
    :param intern: Internal optimisation / implementation detail to avoid python's "LOAD_GLOBAL" instruction in a loop
    :return a dict mapping a name to a source package
    """
    if sources is None:
        sources = {}

    tag_file = apt_pkg.TagFile(filename)
    get_field = tag_file.section.get
    step = tag_file.step

    while step():
        if get_field('Extra-Source-Only', 'no') == 'yes':
            # Ignore sources only referenced by Built-Using
            continue
        pkg = get_field('Package')
        ver = get_field('Version')
        # There may be multiple versions of the source package
        # (in unstable) if some architectures have out-of-date
        # binaries.  We only ever consider the source with the
        # largest version for migration.
        if pkg in sources and apt_pkg.version_compare(sources[pkg][0], ver) > 0:
            continue
        maint = get_field('Maintainer')
        if maint:
            maint = intern(maint.strip())
        section = get_field('Section')
        if section:
            section = intern(section.strip())
        build_deps_arch = ", ".join(x for x in (get_field('Build-Depends'), get_field('Build-Depends-Arch'))
                                    if x is not None)
        if build_deps_arch != '':
            build_deps_arch = sys.intern(build_deps_arch)
        else:
            build_deps_arch = None
        build_deps_indep = get_field('Build-Depends-Indep')
        if build_deps_indep is not None:
            build_deps_indep = sys.intern(build_deps_indep)
        sources[intern(pkg)] = SourcePackage(intern(ver),
                                             section,
                                             set(),
                                             maint,
                                             False,
                                             build_deps_arch,
                                             build_deps_indep,
                                             get_field('Testsuite', '').split(),
                                             get_field('Testsuite-Triggers', '').replace(',', '').split(),
                                             )
    return sources
开发者ID:Debian,项目名称:britney2,代码行数:59,代码来源:utils.py


示例8: _read_episode

    def _read_episode(self, data_generator):
        """Reads one episode at a time from the provided iterator over entries.
        """
        episode = []
        last_cands = None
        for entry, new in data_generator:
            if new and len(episode) > 0:
                yield tuple(episode)
                episode = []
                last_cands = None

            # intern all strings so we don't store them more than once
            new_entry = []
            if len(entry) > 0:
                # process text if available
                if entry[0] is not None:
                    new_entry.append(sys.intern(entry[0]))
                else:
                    new_entry.append(None)
                if len(entry) > 1:
                    # process labels if available
                    if entry[1] is None:
                        new_entry.append(None)
                    elif hasattr(entry[1], '__iter__') and type(entry[1]) is not str:
                        # make sure iterable over labels, not single string
                        new_entry.append(tuple(sys.intern(e) for e in entry[1]))
                    else:
                        raise TypeError('Must provide iterable over labels, not a single string.')
                    if len(entry) > 2:
                        # process reward if available
                        if entry[2] is not None:
                            new_entry.append(entry[2])
                        else:
                            new_entry.append(None)
                        if len(entry) > 3:
                            # process label candidates if available
                            if entry[3] is None:
                                new_entry.append(None)
                            elif last_cands and entry[3] is last_cands:
                                # if cands are shared, say "same" so we
                                # don't store them again
                                new_entry.append(
                                    sys.intern('same as last time'))
                            elif hasattr(entry[3], '__iter__') and type(entry[3]) is not str:
                                # make sure iterable over candidates, not single string
                                last_cands = entry[3]
                                new_entry.append(tuple(
                                    sys.intern(e) for e in entry[3]))
                            else:
                                raise TypeError('Must provide iterable over label candidates, not a single string.')
                            if len(entry) > 4 and entry[4] is not None:
                                new_entry.append(sys.intern(entry[4]))

            episode.append(tuple(new_entry))

        if len(episode) > 0:
            yield tuple(episode)
开发者ID:jojonki,项目名称:ParlAI,代码行数:57,代码来源:dialog_teacher.py


示例9: set_identifier

 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:SamWindell,项目名称:SublimeKSP,代码行数:10,代码来源:ksp_ast.py


示例10: test_sys_intern

 def test_sys_intern(self):
     """
     Py2's builtin intern() has been moved to the sys module. Tests
     whether sys.intern is available.
     """
     from sys import intern
     if utils.PY3:
         self.assertEqual(intern('hello'), 'hello')
     else:
         # intern() requires byte-strings on Py2:
         self.assertEqual(intern(b'hello'), b'hello')
开发者ID:bakkerthehacker,项目名称:python-future,代码行数:11,代码来源:test_standard_library.py


示例11: _reduce_memory_dict

        def _reduce_memory_dict(old_dict):
            new_dict = dict()
            for (k, v) in iteritems(old_dict):
                if type(k) is str:
                    k = intern(k)

                if type(v) is str:
                    v = intern(v)
                elif type(v) is dict:
                    # This handles [{'Caller': ..., 'DebugLoc': { 'File': ... }}]
                    v = _reduce_memory_dict(v)
                new_dict[k] = v
            return tuple(new_dict.items())
开发者ID:cambridgehackers,项目名称:llvm,代码行数:13,代码来源:optrecord.py


示例12: create_from_describe

    def create_from_describe(vardict, index):
        """Create P4File from p4 describe

        Describe does not report the client path, but that will be
        reported later by p4 sync and set on the P4File at that time.
        """

        f = P4File()
        f.depot_path = sys.intern(vardict["depotFile"][index])
        f.type = sys.intern(vardict["type"][index])
        f.action = sys.intern(vardict["action"][index])
        f._revision = int(vardict["rev"][index])
        return f
开发者ID:spearhead-ea,项目名称:git-fusion,代码行数:13,代码来源:p4gf_p4file.py


示例13: loadAlignedParts

 def loadAlignedParts(self, db):
     "load lists of existing aligned partitions for the updated, if not already done"
     if self.alignDb != db:
         self.alignDb = db
         self.alignParts = []
         self.alignMap = {}
         alnDir = "data/aligned/" + self.rel + "/" + db + "/" + self
         for alIdx in globSort(alnDir + "/mrna.*.alidx"):
             names = os.path.basename(alIdx).split(".")
             self._addAlignedPart(MRNA, sys.intern(names[1]))
         for alIdx in globSort(alnDir + "/est.*.*.alidx"):
             names = os.path.basename(alIdx).split(".")
             self._addAlignedPart(EST, sys.intern(names[2]), sys.intern(names[1]))
开发者ID:maximilianh,项目名称:pubMunch,代码行数:13,代码来源:GbIndex.py


示例14: format_stack_trace

def format_stack_trace(frame, thread_category):
    """Formats the frame obj into a list of stack trace tuples.
    """

    stack_trace = deque()

    while frame:
        # The value frame.f_code.co_firstlineno is the first line of
        # code in the file for the specified function. The value
        # frame.f_lineno is the actual line which is being executed
        # at the time the stack frame was being viewed.

        code = frame.f_code

        filename = intern(code.co_filename)
        func_name = intern(code.co_name)
        first_line = code.co_firstlineno

        real_line = frame.f_lineno

        # Set ourselves up to process next frame back up the stack.

        frame = frame.f_back

        # So as to make it more obvious to the user as to what their
        # code is doing, we drop out stack frames related to the
        # agent instrumentation. Don't do this for the agent threads
        # though as we still need to seem them in that case so can
        # debug what the agent itself is doing.

        if (thread_category != 'AGENT' and
                filename.startswith(AGENT_PACKAGE_DIRECTORY)):
            continue

        if not stack_trace:
            # Add the fake leaf node with line number of where the
            # code was executing at the point of the sample. This
            # could be actual Python code within the function, or
            # more likely showing the point where a call is being
            # made into a C function wrapped as Python object. The
            # latter can occur because we will not see stack frames
            # when calling into C functions.

            stack_trace.appendleft((filename, func_name, real_line, real_line))

        # Add the actual node for the function being called at this
        # level in the stack frames.

        stack_trace.appendleft((filename, func_name, first_line, real_line))

    return stack_trace
开发者ID:Dragoon013,项目名称:newrelic-python-kata,代码行数:51,代码来源:profile_sessions.py


示例15: __init__

    def __init__(self, next_attr_name=None, prev_attr_name=None):
        """Initializes this list.

        next_attr_name: The name of the attribute that holds a reference
                        to the next item in the list.

        prev_attr_name: the name of the attribute that holds a reference
                        to the previous item in the list.
        """

        # Keep an interned version of the attribute names. This should
        # speed up the process of looking up the attributes.
        self.next_name = intern(next_attr_name)
        self.prev_name = intern(prev_attr_name)
开发者ID:5g-empower,项目名称:empower-ryu,代码行数:14,代码来源:circlist.py


示例16: __init__

 def __init__(self, row):
     self.taxId = int(row[0])
     self.parentTaxId = int(row[1])
     self.rank = sys.intern(row[2])
     self.emblCode = sys.intern(row[3])
     self.divisionId = int(row[4])
     self.inheritedDivFlag = bool(row[5])
     self.geneticCodeId = int(row[6])
     self.inheritedGCflag = bool(row[7])
     self.mitochondrialGeneticCodeId = int(row[8])
     self.inheritedMGCflag = bool(row[9])
     self.genBankHiddenFlag = bool(row[10])
     self.hiddenSubtreeRootFlag = bool(row[11])
     self.comments = row[12]
开发者ID:maximilianh,项目名称:pubMunch,代码行数:14,代码来源:Taxon.py


示例17: dig_node

 def dig_node(node, parent_summary_builder, child_literals_holder):
     if node is None:
         return
     elif isinstance(node, list):
         n0 = node[0]
         assert n0 in (ct.ORDERED_AND, ct.ORDERED_OR)
         for subn in node[1:]:
             dig_node(subn, parent_summary_builder, child_literals_holder)
         return
     elif isinstance(node, ct.CallNode):
         invoked = node.invoked
         lits = invoked.literals
         lits and parent_summary_builder.extend_literal(lits)
         lbl = callnode_label(node)
         if lbl not in parent_summary_builder.already_appended_callnodes:
             stack.append(lbl)
             nodesum = summary_table.get(lbl)
             if nodesum is None:
                 sb = SummaryBuilder()
                 clh = []
                 subnode = node.body
                 if subnode is None:
                     pass
                 elif isinstance(subnode, (list, ct.CallNode)):
                     dig_node(subnode, sb, clh)
                 elif isinstance(subnode, ct.Invoked):
                     sb.append_callee(intern(subnode.callee))
                     lits = subnode.literals
                     if lits:
                         sb.extend_literal(lits)
                         clh.append(lits)
                 else:
                     assert False
                 nodesum = sb.to_summary()
                 nodesum.literals = intern_literals(nodesum.literals, clh)
                 summary_table[lbl] = nodesum
             parent_summary_builder.append_summary(nodesum, lbl)
             parent_summary_builder.append_callee(invoked.callee)
             child_literals_holder.append(nodesum.literals)
             stack.pop()
         return
     elif isinstance(node, ct.Invoked):
         parent_summary_builder.append_callee(intern(node.callee))
         if node.literals:
             parent_summary_builder.extend_literal(node.literals)
             child_literals_holder.append(node.literals)
     else:
         assert False
开发者ID:tos-kamiya,项目名称:agoat,代码行数:48,代码来源:calltree_summary.py


示例18: string_from_print

def string_from_print(d):
    """create a string from p4 print dict

    This is a noop for unicode servers, because p4python returns strings.

    But for non-unicode servers, when running 'p4 print' we use "raw" encoding
    with p4python to avoid mangling file content, so we get back bytes from
    p4python, which need to be decoded according to the locale encoding"""
    if type(d) == str:
        return sys.intern(d)
    try:
        return sys.intern(d.decode(locale.nl_langinfo(locale.CODESET)))
    except UnicodeDecodeError:
        replaced = d.decode(locale.nl_langinfo(locale.CODESET), 'replace').replace('\ufffd', '?')
        msg = _('Error decoding file path: {}').format(replaced)
        raise RuntimeError(msg)
开发者ID:spearhead-ea,项目名称:git-fusion,代码行数:16,代码来源:p4gf_p4file.py


示例19: read_words

def read_words(path, dialect, sr = None):
    output = list()
    with open(path,'r') as file_handle:
        if dialect == 'buckeye':
            f = re.split(r"#\r{0,1}\n",file_handle.read())[1]
            line_pattern = re.compile("; | \d{3} ")
            begin = 0.0
            flist = f.splitlines()
            for l in flist:
                line = line_pattern.split(l.strip())
                end = float(line[0])
                word = sys.intern(line[1])
                if word[0] != "<" and word[0] != "{":
                    try:
                        citation = line[2].split(' ')
                        phonetic = line[3].split(' ')
                        category = line[4]
                    except:
                        citation = None
                        phonetic = None
                        category = None
                else:
                    citation = None
                    phonetic = None
                    category = None
                if word in FILLERS:
                    category = 'UH'
                line = {'spelling':word,'begin':begin,'end':end,
                        'transcription':citation,'surface_transcription':phonetic,
                        'category':category}
                output.append(line)
                begin = end
        else:
            raise(NotImplementedError)
    return output
开发者ID:PhonologicalCorpusTools,项目名称:CorpusTools,代码行数:35,代码来源:multiple_files.py


示例20: parse_full

    def parse_full(cls, line_string):
        match = cls._line_regex.match(line_string.decode('utf8', errors='replace'))
        if match is None:
            # raise ValueError ("not a valid log line (%r)" % (line_string,))
            groups = [0, 0, 0, 0, "", "", 0, "", "", 0]
            return cls(groups)

        line = cls(match.groups())
        # Timestamp.
        line[0] = parse_time(line[0])
        # PID.
        line[1] = int(line[1])
        # Thread.
        line[2] = int(line[2], 16)
        # Level (this is handled in LineCache).
        line[3] = 0
        # Line.
        line[6] = int(line[6])
        # Message start offset.
        line[9] = match.start(9 + 1)

        for col_id in (4,   # COL_CATEGORY
                       5,   # COL_FILENAME
                       7,   # COL_FUNCTION,
                       8,):  # COL_OBJECT
            line[col_id] = sys.intern(line[col_id] or "")

        return line
开发者ID:thiblahute,项目名称:gst-devtools,代码行数:28,代码来源:Data.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sys.setcheckinterval函数代码示例发布时间:2022-05-27
下一篇:
Python sys.grc函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap