python类MULTILINE的实例源码

dalvik.py 文件源码 项目:sublime-text-3-packages 作者: nickjj 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def analyse_text(text):
        score = 0
        if re.search(r'^\s*\.class\s', text, re.MULTILINE):
            score += 0.5
            if re.search(r'\b((check-cast|instance-of|throw-verification-error'
                         r')\b|(-to|add|[ais]get|[ais]put|and|cmpl|const|div|'
                         r'if|invoke|move|mul|neg|not|or|rem|return|rsub|shl|'
                         r'shr|sub|ushr)[-/])|{|}', text, re.MULTILINE):
                score += 0.3
        if re.search(r'(\.(catchall|epilogue|restart local|prologue)|'
                     r'\b(array-data|class-change-error|declared-synchronized|'
                     r'(field|inline|vtable)@0x[0-9a-fA-F]|generic-error|'
                     r'illegal-class-access|illegal-field-access|'
                     r'illegal-method-access|instantiation-error|no-error|'
                     r'no-such-class|no-such-field|no-such-method|'
                     r'packed-switch|sparse-switch))\b', text, re.MULTILINE):
            score += 0.6
        return score
makemessages.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def postprocess_messages(self, msgs):
        """
        Postprocess messages generated by xgettext GNU gettext utility.

        Transform paths as if these messages were generated from original
        translatable files rather than from preprocessed versions.
        """
        if not self.is_templatized:
            return msgs

        # Remove '.py' suffix
        if os.name == 'nt':
            # Preserve '.\' prefix on Windows to respect gettext behavior
            old_path = self.work_path
            new_path = self.path
        else:
            old_path = self.work_path[2:]
            new_path = self.path[2:]

        return re.sub(
            r'^(#: .*)(' + re.escape(old_path) + r')',
            lambda match: match.group().replace(old_path, new_path),
            msgs,
            flags=re.MULTILINE
        )
makemessages.py 文件源码 项目:NarshaTech 作者: KimJangHyeon 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def postprocess_messages(self, msgs):
        """
        Postprocess messages generated by xgettext GNU gettext utility.

        Transform paths as if these messages were generated from original
        translatable files rather than from preprocessed versions.
        """
        if not self.is_templatized:
            return msgs

        # Remove '.py' suffix
        if os.name == 'nt':
            # Preserve '.\' prefix on Windows to respect gettext behavior
            old_path = self.work_path
            new_path = self.path
        else:
            old_path = self.work_path[2:]
            new_path = self.path[2:]

        return re.sub(
            r'^(#: .*)(' + re.escape(old_path) + r')',
            lambda match: match.group().replace(old_path, new_path),
            msgs,
            flags=re.MULTILINE
        )
plugintest.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def remove_stack_traces(out):
    # this regexp taken from Python 2.5's doctest
    traceback_re = re.compile(r"""
        # Grab the traceback header.  Different versions of Python have
        # said different things on the first traceback line.
        ^(?P<hdr> Traceback\ \(
            (?: most\ recent\ call\ last
            |   innermost\ last
            ) \) :
        )
        \s* $                   # toss trailing whitespace on the header.
        (?P<stack> .*?)         # don't blink: absorb stuff until...
        ^(?=\w)                 #     a line *starts* with alphanum.
        .*?(?P<exception> \w+ ) # exception name
        (?P<msg> [:\n] .*)      # the rest
        """, re.VERBOSE | re.MULTILINE | re.DOTALL)
    blocks = []
    for block in blankline_separated_blocks(out):
        blocks.append(traceback_re.sub(r"\g<hdr>\n...\n\g<exception>\g<msg>", block))
    return "".join(blocks)
generator.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def _make_boundary(text=None):
    # Craft a random boundary.  If text is given, ensure that the chosen
    # boundary doesn't appear in the text.
    token = random.randrange(sys.maxint)
    boundary = ('=' * 15) + (_fmt % token) + '=='
    if text is None:
        return boundary
    b = boundary
    counter = 0
    while True:
        cre = re.compile('^--' + re.escape(b) + '(--)?$', re.MULTILINE)
        if not cre.search(text):
            break
        b = boundary + '.' + str(counter)
        counter += 1
    return b
MIMEAttachment.py 文件源码 项目:vspheretools 作者: devopshq 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def _make_boundary(text=None):
    #some code taken from python stdlib
    # Craft a random boundary.  If text is given, ensure that the chosen
    # boundary doesn't appear in the text.
    token = random.randrange(sys.maxint)
    boundary = ('=' * 10) + (_fmt % token) + '=='
    if text is None:
        return boundary
    b = boundary
    counter = 0
    while True:
        cre = re.compile('^--' + re.escape(b) + '(--)?$', re.MULTILINE)
        if not cre.search(text):
            break
        b = boundary + '.' + str(counter)
        counter += 1
    return b
MIMEAttachment.py 文件源码 项目:p2pool-bch 作者: amarian12 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def _make_boundary(text=None):
    #some code taken from python stdlib
    # Craft a random boundary.  If text is given, ensure that the chosen
    # boundary doesn't appear in the text.
    token = random.randrange(sys.maxint)
    boundary = ('=' * 10) + (_fmt % token) + '=='
    if text is None:
        return boundary
    b = boundary
    counter = 0
    while True:
        cre = re.compile('^--' + re.escape(b) + '(--)?$', re.MULTILINE)
        if not cre.search(text):
            break
        b = boundary + '.' + str(counter)
        counter += 1
    return b
test_verify.py 文件源码 项目:SwiftKitten 作者: johncsnyder 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def setup_module():
    import cffi.verifier
    cffi.verifier.cleanup_tmpdir()
    #
    # check that no $ sign is produced in the C file; it used to be the
    # case that anonymous enums would produce '$enum_$1', which was
    # used as part of a function name.  GCC accepts such names, but it's
    # apparently non-standard.
    _r_comment = re.compile(r"/\*.*?\*/|//.*?$", re.DOTALL | re.MULTILINE)
    _r_string = re.compile(r'\".*?\"')
    def _write_source_and_check(self, file=None):
        base_write_source(self, file)
        if file is None:
            f = open(self.sourcefilename)
            data = f.read()
            f.close()
            data = _r_comment.sub(' ', data)
            data = _r_string.sub('"skipped"', data)
            assert '$' not in data
    base_write_source = cffi.verifier.Verifier._write_source
    cffi.verifier.Verifier._write_source = _write_source_and_check
makemessages.py 文件源码 项目:Scrum 作者: prakharchoudhary 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def postprocess_messages(self, msgs):
        """
        Postprocess messages generated by xgettext GNU gettext utility.

        Transform paths as if these messages were generated from original
        translatable files rather than from preprocessed versions.
        """
        if not self.is_templatized:
            return msgs

        # Remove '.py' suffix
        if os.name == 'nt':
            # Preserve '.\' prefix on Windows to respect gettext behavior
            old_path = self.work_path
            new_path = self.path
        else:
            old_path = self.work_path[2:]
            new_path = self.path[2:]

        return re.sub(
            r'^(#: .*)(' + re.escape(old_path) + r')',
            lambda match: match.group().replace(old_path, new_path),
            msgs,
            flags=re.MULTILINE
        )
evaluation.py 文件源码 项目:seq2seq 作者: eske 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def corpus_ter(hypotheses, references, case_sensitive=True, tercom_path=None, **kwargs):
    tercom_path = tercom_path or 'scripts/tercom.jar'

    with tempfile.NamedTemporaryFile('w') as hypothesis_file, tempfile.NamedTemporaryFile('w') as reference_file:
        for i, (hypothesis, reference) in enumerate(zip(hypotheses, references)):
            hypothesis_file.write('{} ({})\n'.format(hypothesis, i))
            reference_file.write('{} ({})\n'.format(reference, i))
        hypothesis_file.flush()
        reference_file.flush()

        cmd = ['java', '-jar', tercom_path, '-h', hypothesis_file.name, '-r', reference_file.name]
        if case_sensitive:
            cmd.append('-s')

        output = subprocess.check_output(cmd).decode()

        error = re.findall(r'Total TER: (.*?) ', output, re.MULTILINE)[0]
        return float(error) * 100, ''
katana.py 文件源码 项目:warriorframework 作者: warriorframework 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def get_action_dirlist(driverpath):
    """ Get the list of action directories
    """
    actions_package_list = []
    try:
        if os.path.isfile(driverpath):
            with open(driverpath, 'r') as fobj:
                drv_text = fobj.read()
            search_string = re.compile('package_list.*=.*\]',
                                       re.DOTALL | re.MULTILINE)
            match = re.search(search_string, drv_text)

            if match:
                match_string = match.group()
                # extracting the text within [] and get the list of packages separated by ,
                actions_package_list = re.findall(r'\[(.*)\]', match_string)[0].split(',')
                print "\n actions package list: ", actions_package_list
        else:
            print "file {0} does not exist".format(driverpath)
    except Exception, e:
        print str(e)
    return actions_package_list
dictionary.py 文件源码 项目:piband 作者: bobmonkeywarts 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def find(x):     #simple dictionary code copy-pasted from stack overflow
    srch=str(x)
    x=urllib2.urlopen("http://dictionary.reference.com/browse/"+srch+"?s=t")
    x=x.read()
    items=re.findall('<meta name="description" content="'+".*$",x,re.MULTILINE)
    for x in items:
        y=x.replace('<meta name="description" content="','')
        z=y.replace(' See more."/>','')
        m=re.findall('at Dictionary.com, a free online dictionary with pronunciation,              synonyms and translation. Look it up now! "/>',z)
        if m==[]:
            if z.startswith("Get your reference question answered by Ask.com"):
                print "Word not found! :("
            else:
        z = z[z.index(',')+2:z.index("See more")]
               # print z
        say(z)
cql.py 文件源码 项目:cassandra-migrate 作者: Cobliteam 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def scanner(cls):
        if not getattr(cls, '_scanner', None):
            def h(tpe):
                return lambda sc, tk: cls.Token(tpe, tk)

            cls._scanner = re.Scanner([
                (r"(--|//).*?$",               h(cls.LINE_COMMENT)),
                (r"\/\*.+?\*\/",               h(cls.BLOCK_COMMENT)),
                (r'"(?:[^"\\]|\\.)*"',         h(cls.STRING)),
                (r"'(?:[^'\\]|\\.)*'",         h(cls.STRING)),
                (r"\$\$(?:[^\$\\]|\\.)*\$\$",  h(cls.STRING)),
                (r";",                         h(cls.SEMICOLON)),
                (r"\s+",                       h(cls.WHITESPACE)),
                (r".",                         h(cls.OTHER))
            ], re.MULTILINE | re.DOTALL)
        return cls._scanner
pyqsub.py 文件源码 项目:reportIT 作者: stevekm 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def check_qsub_job_status(job_id, desired_status = "r"):
    '''
    Use 'qstat' to check on the run status of a qsub job
    returns True or False if the job status matches the desired_status
    job running:
    desired_status = "r"
    job waiting:
    desired_status = "qw"
    '''
    import re
    from sh import qstat
    job_id_pattern = r"^.*{0}.*\s{1}\s.*$".format(job_id, desired_status)
    # using the 'sh' package
    qstat_stdout = qstat()
    # using the standard subprocess package
    # qstat_stdout = subprocess_cmd('qstat', return_stdout = True)
    job_match = re.findall(str(job_id_pattern), str(qstat_stdout), re.MULTILINE)
    job_status = bool(job_match)
    if job_status == True:
        status = True
        return(job_status)
    elif job_status == False:
        return(job_status)
download_pics.py 文件源码 项目:core-python 作者: yidao620c 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def down_allpic(html_file):
    urls = []
    id_pattern = re.compile(r' data-clipboard-text="(.*?)"', re.MULTILINE)
    with open(html_file, encoding='utf-8') as f:
        content = f.read()
    for m in id_pattern.finditer(content):
        urls.append(m.group(1))
    print(len(urls))
    down_dir = r'D:/download/20170304/'
    for u in urls:
        if (u.endswith('.zip') or u.endswith('/')):
            continue
        print(u)
        # ?????????
        r = requests.get(u, stream=True)
        # ??????????????
        chunk_size = 1024
        with open(os.path.join(down_dir, os.path.split(u)[1]), 'wb') as fd:
            for chunk in r.iter_content(chunk_size):
                fd.write(chunk)
    return urls
download_pics.py 文件源码 项目:core-python 作者: yidao620c 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def compare_diff(qiniuhtml, coshtml):
    urls1 = set()
    id_pattern = re.compile(r' data-clipboard-text="(.*?)"', re.MULTILINE)
    with open(qiniuhtml, encoding='utf-8') as f:
        content = f.read()
    for m in id_pattern.finditer(content):
        url = m.group(1)
        if (url.endswith('.zip') or url.endswith('/')):
            continue
        urls1.add(os.path.split(url)[1])

    urls2 = set()
    id_pattern2 = re.compile(r' filename="(.*?)"', re.MULTILINE)
    with open(coshtml, encoding='utf-8') as f:
        content = f.read()
    for m in id_pattern2.finditer(content):
        url = m.group(1)
        if (url.endswith('.zip') or url.endswith('/')):
            continue
        urls2.add(url)

    print(urls1.difference(urls2))
    print(urls2.difference(urls1))
    print(urls1.symmetric_difference(urls2))
crushmap.py 文件源码 项目:core-python 作者: yidao620c 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def find_osd_weight(crush_file, hdd_osds, ssd_osds):
    """
    :param crush_file: 
    :param hdd_osds
        hhd???osd??????[('1', 'node0001'), ('3', 'node0002')]
    :param ssd_osds
        ssd???osd??????[('0', 'node0002'), ('2', 'node0002')]
    :return: 
    """
    result_dict = dict()
    osd_list = []
    if hdd_osds:
        osd_list.extend([osd_num for osd_num, _ in hdd_osds ])
    if ssd_osds:
        osd_list.extend([osd_num for osd_num, _ in ssd_osds ])
    with open(crush_file) as f:
        content_list = f.readlines()
    for osd_num in osd_list:
        id_pattern = re.compile(r'^\s*item osd.{} weight (\d+\.\d+)'.format(osd_num), re.MULTILINE)
        for line in content_list:
            m = id_pattern.match(line)
            if m:
                result_dict[osd_num] = m.group(1)
                break
    return result_dict
kube_service_status.py 文件源码 项目:kolla-kubernetes 作者: openstack 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _matchSingleLineField(field_name, haystack):
        """Returns field name's value"""

        # Initial checks
        assert field_name is not None
        if haystack is None:
            return None

        # Execute the Search
        match = re.search('^{}:\s+(?P<MY_VAL>.*)$'.format(field_name),
                          haystack,
                          re.MULTILINE)

        # Check the value
        if match is None:
            return None
        else:
            return match.group('MY_VAL').strip()


问题


面经


文章

微信
公众号

扫码关注公众号