python类finditer()的实例源码

gdrive_api2.py 文件源码 项目:Python-GoogleDrive-VideoStream 作者: ddurdle 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def getOfflineMediaList(self, folderName=False, title=False, contentType=7):

        mediaFiles = []
        for r1 in re.finditer('\{(.*?)\"spaces\"\:' , entryS, re.DOTALL):
            entry = r1.group(1)
            media = self.getMediaPackage(entry, folderName=folderName, contentType=contentType, fanart=folderFanart, icon=folderIcon)
            if media is not None:
                mediaFiles.append(media)



        return mediaFiles





    ##
    # retrieve a list of videos, using playback type stream
    #   parameters: prompt for video quality (optional), cache type (optional)
    #   returns: list of videos
    ##
sequence.py 文件源码 项目:sequana 作者: sequana 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_occurences(self, pattern, overlap=False):
        """Return position of the input pattern in the sequence

        ::

            >>> from sequana import Sequence
            >>> s = Sequence('ACGTTTTACGT')
            >>> s.get_occurences("ACGT")
            [0, 7]

        """
        if overlap is False:
            res = [m.start() for m in re.finditer(pattern, self.sequence)]
        elif overlap is True:
            res = [m.start() for m in re.finditer('(?=%s)'%pattern, self.sequence)]
        return res

        # reverse find-all without overlaps, you can combine positive and
        # negative lookahead into an expression like this:
        #res = [m.start() for m in re.finditer('(?=%s)(?!.{1,%d}%s)' % (search,
        #    len(pattern)-1, pattern), 'ttt')]
lover.py 文件源码 项目:core-python 作者: yidao620c 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def find_cute(url):
    # ??????
    r = requests.get(url)
    # ??r.encoding
    encoding = re.search('content="text/html;\s*charset=(.*?)"', r.text).group(1)
    r.encoding = encoding
    # print(r.text)
    finds = re.finditer(r'<p>\s*([^>]*?)\s*\n', r.text)
    i = random.randint(0, sum(1 for _ in finds))
    start = 0
    finds = re.finditer(r'<p>\s*([^>]*?)\s*\n', r.text)
    for f in finds:
        if start == i:
            print(f.group(1))
            break
        start += 1
tarfile.py 文件源码 项目:python- 作者: secondtonone1 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _proc_gnusparse_00(self, next, pax_headers, buf):
        """Process a GNU tar extended sparse header, version 0.0.
        """
        offsets = []
        for match in re.finditer(br"\d+ GNU.sparse.offset=(\d+)\n", buf):
            offsets.append(int(match.group(1)))
        numbytes = []
        for match in re.finditer(br"\d+ GNU.sparse.numbytes=(\d+)\n", buf):
            numbytes.append(int(match.group(1)))
        next.sparse = list(zip(offsets, numbytes))
tarfile.py 文件源码 项目:python- 作者: secondtonone1 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _proc_gnusparse_00(self, next, pax_headers, buf):
        """Process a GNU tar extended sparse header, version 0.0.
        """
        offsets = []
        for match in re.finditer(br"\d+ GNU.sparse.offset=(\d+)\n", buf):
            offsets.append(int(match.group(1)))
        numbytes = []
        for match in re.finditer(br"\d+ GNU.sparse.numbytes=(\d+)\n", buf):
            numbytes.append(int(match.group(1)))
        next.sparse = list(zip(offsets, numbytes))
tarfile.py 文件源码 项目:my-first-blog 作者: AnkurBegining 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _proc_gnusparse_00(self, next, pax_headers, buf):
        """Process a GNU tar extended sparse header, version 0.0.
        """
        offsets = []
        for match in re.finditer(br"\d+ GNU.sparse.offset=(\d+)\n", buf):
            offsets.append(int(match.group(1)))
        numbytes = []
        for match in re.finditer(br"\d+ GNU.sparse.numbytes=(\d+)\n", buf):
            numbytes.append(int(match.group(1)))
        next.sparse = list(zip(offsets, numbytes))
SqlExtractor.py 文件源码 项目:mysql-er 作者: StefanLim0 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def get_selects_from_text(content):
        sqls = []
        select_keyword = '@Select\s*\('
        for m in re.finditer(select_keyword, content):
            rparen_pos = MybatisInlineSqlExtractor.find_right_paren_pos(content[m.end():])
            if rparen_pos < 0:
                continue
            sqls.append(SQL('', eval(content[m.end():m.end() + rparen_pos].replace('\r', '').replace('\n', '')).strip()))
        return sqls
reference.py 文件源码 项目:cellranger 作者: 10XGenomics 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def get_properties_dict(self, properties_str):
        if isinstance(properties_str, dict):
            return properties_str

        properties = collections.OrderedDict()
        pattern = re.compile('(\S+?)\s*"(.*?)"')
        for m in re.finditer(pattern, properties_str):
            key = m.group(1)
            value = m.group(2)
            properties[key] = value
        return properties
reference.py 文件源码 项目:cellranger 作者: 10XGenomics 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_unambiguous_regions(reference_path):
    '''Calculate regions corresponding to unambiguous bases'''
    chrom_map = {}
    for chrom, seq in open_reference(reference_path).items():
        regions = [(m.start(), m.end()) for m in re.finditer('[acgtACGT]+', seq[:])]
        chrom_map[chrom] = Regions(regions=regions)
    return chrom_map
tokenize_uk.py 文件源码 项目:tokenize-uk 作者: lang-uk 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def tokenize_sents(string):
    """
    Tokenize input text to sentences.

    :param string: Text to tokenize
    :type string: str or unicode
    :return: sentences
    :rtype: list of strings
    """
    string = six.text_type(string)

    spans = []
    for match in re.finditer('[^\s]+', string):
        spans.append(match)
    spans_count = len(spans)

    rez = []
    off = 0

    for i in range(spans_count):
        tok = string[spans[i].start():spans[i].end()]
        if i == spans_count - 1:
            rez.append(string[off:spans[i].end()])
        elif tok[-1] in ['.', '!', '?', '…', '»']:
            tok1 = tok[re.search('[.!?…»]', tok).start()-1]
            next_tok = string[spans[i + 1].start():spans[i + 1].end()]
            if (next_tok[0].isupper()
                and not tok1.isupper()
                and not (tok[-1] != '.'
                         or tok1[0] == '('
                         or tok in ABBRS)):
                rez.append(string[off:spans[i].end()])
                off = spans[i + 1].start()

    return rez
whatstyle.py 文件源码 项目:whatstyle 作者: mikr 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def register_options(self):
        # type: () -> None
        """Parse options from text like this:
        # Uncrustify 0.63
        #
        # General options
        #

        newlines                                  { Auto, LF, CR, CRLF }
          The type of line endings

        input_tab_size                            Number
          The original size of tabs in the input

        indent_align_string                       { False, True }
          Whether to indent strings broken by '\' so that they line up
        """
        exeresult = run_executable(self.exe, ['--show-config'], cache=self.cache)
        options = []
        text = unistr(exeresult.stdout)
        for m in re.finditer(r'^(\w+)\s+(.*?)\s*$', text, re.MULTILINE):
            optionname, optiondesc = m.group(1), m.group(2)
            if optiondesc.startswith('{'):
                optiontype = 'Enum'
                configs = optiondesc[1:-1].strip().split(', ')
                configs = [c.lower() for c in configs]
            else:
                optiontype = optiondesc
                configs = []
            options.append(option_make(optionname, optiontype, configs))
        self.styledefinition = styledef_make(options)
jsunfuck.py 文件源码 项目:plugin.video.exodus 作者: lastship 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __handle_tostring(self):
        for match in re.finditer('(\d+)\[t\+o\+S\+t\+r\+i\+n\+g\](\d+)', self.js):
            repl = to_base(match.group(1), match.group(2))
            self.js = self.js.replace(match.group(0), repl)
dom_parser.py 文件源码 项目:plugin.video.exodus 作者: lastship 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __get_attribs(element):
    attribs = {}
    for match in re.finditer('''\s+(?P<key>[^=]+)=\s*(?:(?P<delim>["'])(?P<value1>.*?)(?P=delim)|(?P<value2>[^"'][^>\s]*))''', element):
        match = match.groupdict()
        value1 = match.get('value1')
        value2 = match.get('value2')
        value = value1 if value1 is not None else value2
        if value is None: continue
        attribs[match['key'].lower().strip()] = value
    return attribs
RJ_3.5.py 文件源码 项目:Radiojavan 作者: nimasaj 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def album(URL):
    track_list=[]
    if (URL.find('?index=')>0):
        all_track_nr=((html.count('?index='))//2)-1
        a1=URL[:URL.find('?index=')]
        current_track_no=int(URL[len(a1)+len('?index='):])
        ID=a1[a1.find('/album/')+len('/album/'):]
        track_list.append('%s'%current_track_no)
    elif (URL.find('?start')>0):
        all_track_nr=((html.count('?index='))//2)-1
        a1=URL[:URL.find('?start')]
        current_track_no=int(URL[len(a1)+len('?start'):])
        ID=a1[a1.find('/album/')+len('/album/'):]
        track_list.append('%s'%current_track_no)
    else:
        all_track_nr=(html.count('?index='))//2
        a1=URL
        current_track_no='null'
        ID=a1[a1.find('/album/')+len('/album/'):]
        track_list.append('%s'%current_track_no)
    i=0
    b=html[html.find('<span class="song_name">'):html.rfind('<span class="song_name">')]
    b_len=len('<span class="song_name">')
    iter=re.finditer(r'<span class="song_name">', b)
    indices=[m.start(0) for m in iter]
    while i<all_track_nr:
        track_list.append('%s?index=%d'%(a1,i))
        d=(b[indices[i]:].find('</span>'))
        track_name=b[indices[i]+b_len:indices[i]+d]
        track_list.append(track_name)
        i+=1
    return(track_list)
RJ_3.py 文件源码 项目:Radiojavan 作者: nimasaj 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def album(URL):
    track_list=[]
    if (URL.find('?index=')>0):
        all_track_nr=((html.count('?index='))//2)-1
        a1=URL[:URL.find('?index=')]
        current_track_no=int(URL[len(a1)+len('?index='):])
        ID=a1[a1.find('/album/')+len('/album/'):]
        track_list.append('%s'%current_track_no)
    elif (URL.find('?start')>0):
        all_track_nr=((html.count('?index='))//2)-1
        a1=URL[:URL.find('?start')]
        current_track_no=int(URL[len(a1)+len('?start'):])
        ID=a1[a1.find('/album/')+len('/album/'):]
        track_list.append('%s'%current_track_no)
    else:
        all_track_nr=(html.count('?index='))//2
        a1=URL
        current_track_no='null'
        ID=a1[a1.find('/album/')+len('/album/'):]
        track_list.append('%s'%current_track_no)
    i=0
    b=html[html.find('<span class="song_name">'):html.rfind('<span class="song_name">')]
    b_len=len('<span class="song_name">')
    iter=re.finditer(r'<span class="song_name">', b)
    indices=[m.start(0) for m in iter]
    while i<all_track_nr:
        track_list.append('%s?index=%d'%(a1,i))
        d=(b[indices[i]:].find('</span>'))
        track_name=b[indices[i]+b_len:indices[i]+d]
        track_list.append(track_name)
        i+=1
    return(track_list)
utils.py 文件源码 项目:googletranslate.popclipext 作者: wizyoung 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def legacy_format_json(original):
    # save state
    states = []
    text = original

    # save position for double-quoted texts
    for i, pos in enumerate(re.finditer('"', text)):
        # pos.start() is a double-quote
        p = pos.start() + 1
        if i % 2 == 0:
            nxt = text.find('"', p)
            states.append((p, text[p:nxt]))

    # replace all weired characters in text
    while text.find(',,') > -1:
        text = text.replace(',,', ',null,')
    while text.find('[,') > -1:
        text = text.replace('[,', '[null,')

    # recover state
    for i, pos in enumerate(re.finditer('"', text)):
        p = pos.start() + 1
        if i % 2 == 0:
            j = int(i / 2)
            nxt = text.find('"', p)
            # replacing a portion of a string
            # use slicing to extract those parts of the original string to be kept
            text = text[:p] + states[j][1] + text[nxt:]

    converted = json.loads(text)
    return converted
Analysis.py 文件源码 项目:BioNanoAnalyst 作者: AppliedBioinformatics 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def make_RefCmap(fasta_file, enz=None, min_len=20, min_nsite=5, path=None):
    name = fasta_file.rsplit('.',1)[0].split('/')[-1]
    index = 0
    enzymes = {'BspQI':'GCTCTTC',
                'BbvCI':'CCTCAGC',
                'Bsml':'GAATGC',
                'BsrDI':'GCAATG',
                'bseCI':'ATCGAT',
                'BssSI':'CACGAG'}
    try:
        cmap_file='%s/%s_%s.cmap'%(path,name,enz)
        forwards = enzymes[enz]
        reverse = str(Seq(forwards).reverse_complement())
        with open (cmap_file,'a') as ref_cmap:
            ref_cmap.write('# CMAP File Version:\t0.1\n')
            ref_cmap.write('# Label Channels:\t1\n')
            ref_cmap.write('# Nickase Recognition Site 1:\t%s\n'%forwards)
            ref_cmap.write('# Enzyme1:\tNt.%s\n'%enz)
            ref_cmap.write('# Number of Consensus Nanomaps:\tN/A\n')
            ref_cmap.write('#h CMapId\tContigLength\tNumSites\tSiteID\tLabelChannel\tPosition\tStdDev\tCoverage\tOccurrence\n')
            ref_cmap.write('#f int\tfloat\tint\tint\tint\tfloat\tfloat\tint\tint\n')
            for seqs in SeqIO.parse(fasta_file,'fasta'):
                seq = str(seqs.seq.upper())
                seq_len = len(seq)
                index+=1
                if seq_len >= min_len*1000:
                    nsites = len(re.findall('%s|%s'%(forwards,reverse),seq))
                    if nsites >=min_nsite:
                        j=1
                        for o in re.finditer('%s|%s'%(forwards,reverse),seq):
                            ref_cmap.write('%s\t%.1f\t%d\t%d\t1\t%.1f\t1.0\t1\t1\n'%(index,seq_len,nsites,j,o.start()+1))
                            j+=1
                        ref_cmap.write('%s\t%.1f\t%d\t%d\t0\t%.1f\t0.0\t1\t0\n'%(index,seq_len,nsites,j,seq_len))
    except:
        pass
mod_stat.py 文件源码 项目:mod_stat 作者: DadoZe 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def formatString(self, text, stats, not_found_replacement = None):
        #try:
        values = stats['values']
        for m in re.finditer("{{([gc]:)?([^}:]*)((:d)|(:1f)|:(\d+)|:(\d+)\.(\d+)f|(:\+d)|(:\+1f))?}}", text):
            g, g1, key, g2, sg1, sg2, sg3, sg4a, sg4b, sg5, sg6 = m.group(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
            if not key in values:
                if not_found_replacement is None:
                    if d: LOG_NOTE('No key in values of %s (%s)' % (stats.get('_type', 'unknown'), key))
                else:
                    text = text.replace('%s' % g, not_found_replacement)
            elif g1 is None:
                if g2 is None:
                    text = text.replace('{{%s}}' % key, self.applyMacros(values[key]))
                elif sg1:
                    text = text.replace('{{%s:d}}' % key, self.applyMacros(values[key], 0))
                elif sg2:
                    text = text.replace('{{%s:1f}}' % key, self.applyMacros(values[key], 1))
                elif sg3:
                    xx = int(sg3)
                    text = text.replace('{{%s:%d}}' % (key, xx), self.applyMacros2(values[key], xx))
                elif sg4a:
                    xx, yy = int(sg4a), int(sg4b)
                    text = text.replace('{{%s:%d.%df}}' % (key, xx, yy), self.applyMacros2(values[key], xx, yy))
                elif sg5:
                    text = text.replace('{{%s:+d}}' % key, self.applyMacros(values[key], 0, '+'))
                elif sg6:
                    text = text.replace('{{%s:+1f}}' % key, self.applyMacros(values[key], 1, '+'))
            elif g1=="g:":
                text = text.replace('{{g:%s}}' % key, stats['gradient'][key])
            elif g1=="c:":
                text = text.replace('{{c:%s}}' % key, stats['palette'][key])
        #except:
        #  LOG_CURRENT_EXCEPTION()
        #finally:
        return text
tokenizer.py 文件源码 项目:yargy 作者: natasha 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __call__(self, text):
        for match in re.finditer(self.regexp, text):
            name = match.lastgroup
            value = match.group(0)
            span = match.span()
            rule = self.mapping[name]
            token = rule(value, span)
            yield token
model.py 文件源码 项目:aapm_thoracic_challenge 作者: xf4j 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def load(self, model_name='main'):
        checkpoint_dir = os.path.join(self.checkpoint_dir, self.model_dir)

        ckpt = tf.train.get_checkpoint_state(checkpoint_dir)
        if ckpt and ckpt.model_checkpoint_path:
            ckpt_name = os.path.basename(ckpt.model_checkpoint_path)
            self.saver.restore(self.sess, os.path.join(checkpoint_dir, ckpt_name))
            counter = int(next(re.finditer("(\d+)(?!.*\d)", ckpt_name)).group(0))
            return True, counter
        else:
            print("Failed to find a checkpoint")
            return False, 0


问题


面经


文章

微信
公众号

扫码关注公众号