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


Python utils.re_compile函数代码示例

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


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

示例1: _match

 def _match(self, mapping, value):
     for pat, what in utils.group(mapping, 2):
         rx = utils.re_compile("^" + pat + "$")
         result = rx.match(value)
         if result:
             return what, [x and urllib.unquote(x) for x in result.groups()]
     return None, None
开发者ID:acgourley,项目名称:watchdog,代码行数:7,代码来源:application.py

示例2: _match

 def _match(self, mapping, value):
     for pat, what in utils.group(mapping, 2):
         if isinstance(what, basestring):
             what, result = utils.re_subm("^" + pat + "$", what, web.ctx.path)
         else:
             result = utils.re_compile("^" + pat + "$").match(web.ctx.path)
         if result:  # it's a match
             return what, [x and urllib.unquote(x) for x in result.groups()]
     return None, None
开发者ID:Letractively,项目名称:pytof,代码行数:9,代码来源:application.py

示例3: _match

    def _match(self, mapping, value):
        for pat, what in mapping:
            if isinstance(what, basestring):
                what, result = utils.re_subm('^' + pat + '$', what, value)
            else:
                result = utils.re_compile('^' + pat + '$').match(value)

            if result: # it's a match
                return what, [x for x in result.groups()]
        return None, None
开发者ID:alustig,项目名称:OSPi,代码行数:10,代码来源:application.py

示例4: _match

    def _match(self, mapping, value):
        for pat, what in mapping:
            if isinstance(what, basestring):
                what, result = utils.re_subm('^' + pat + '$', what, value)
            else:
                result = utils.re_compile('^' + pat + '$').match(value)

            if result: # it's a match
                return what, [x for x in set(result.groups()).difference(set(result.groupdict().values()))], result.groupdict()   #microhuang
        return None, None, None
开发者ID:masonyang,项目名称:webpy,代码行数:10,代码来源:application.py

示例5: _filter_links

    def _filter_links(self, links, text=None, text_regex=None, url=None, url_regex=None, predicate=None):
        predicates = []
        if text is not None:
            predicates.append(lambda link: link.string == text)
        if text_regex is not None:
            predicates.append(lambda link: re_compile(text_regex).search(link.string or ""))
        if url is not None:
            predicates.append(lambda link: link.get("href") == url)
        if url_regex is not None:
            predicates.append(lambda link: re_compile(url_regex).search(link.get("href", "")))
        if predicate:
            predicate.append(predicate)

        def f(link):
            for p in predicates:
                if not p(link):
                    return False
            return True

        return [link for link in links if f(link)]
开发者ID:keizo,项目名称:webpy,代码行数:20,代码来源:browser.py

示例6: _match

    def _match(self, mapping, value):
        for pat, what in utils.group(mapping, 2):
            if isinstance(what, application):
                if value.startswith(pat):
                    f = lambda: self._delegate_sub_application(pat, what)
                    return f, None
                else:
                    continue
            elif isinstance(what, basestring):
                what, result = utils.re_subm("^" + pat + "$", what, value)
            else:
                result = utils.re_compile("^" + pat + "$").match(value)

            if result:  # it's a match
                return what, [x and urllib.unquote(x) for x in result.groups()]
        return None, None
开发者ID:mzkmzk,项目名称:jit,代码行数:16,代码来源:application.py

示例7: compile_templates

def compile_templates(root):
    """Compiles templates to python code."""
    re_start = re_compile('^', re.M)
    
    for dirpath, dirnames, filenames in os.walk(root):
        filenames = [f for f in filenames if not f.startswith('.') and not f.endswith('~') and not f.startswith('__init__.py')]

        for d in dirnames[:]:
            if d.startswith('.'):
                dirnames.remove(d) # don't visit this dir

        out = open(os.path.join(dirpath, '__init__.py'), 'w')
        out.write('from web.template import CompiledTemplate, ForLoop\n\n')
        if dirnames:
            out.write("import " + ", ".join(dirnames))

        for f in filenames:
            path = os.path.join(dirpath, f)

            if '.' in f:
                name, _ = f.split('.', 1)
            else:
                name = f
                
            text = open(path).read()
            text = Template.normalize_text(text)
            code = Template.generate_code(text, path)
            code = re_start.sub('    ', code)
                        
            _gen = '' + \
            '\ndef %s():' + \
            '\n    loop = ForLoop()' + \
            '\n    _dummy  = CompiledTemplate(lambda: None, "dummy")' + \
            '\n    join_ = _dummy._join' + \
            '\n    escape_ = _dummy._escape' + \
            '\n' + \
            '\n%s' + \
            '\n    return __template__'
            
            gen_code = _gen % (name, code)
            out.write(gen_code)
            out.write('\n\n')
            out.write('%s = CompiledTemplate(%s, %s)\n\n' % (name, name, repr(path)))

            # create template to make sure it compiles
            t = Template(open(path).read(), path)
        out.close()
开发者ID:dsc,项目名称:webpy,代码行数:47,代码来源:template.py

示例8: compile_templates

def compile_templates(root):
    """Compiles templates to python code."""
    re_start = re_compile("^", re.M)

    for dirpath, dirnames, filenames in os.walk(root):
        filenames = [
            f for f in filenames if not f.startswith(".") and not f.endswith("~") and not f.startswith("__init__.py")
        ]

        for d in dirnames[:]:
            if d.startswith("."):
                dirnames.remove(d)  # don't visit this dir

        out = open(os.path.join(dirpath, "__init__.py"), "w")
        out.write("from web.template import CompiledTemplate, ForLoop, TemplateResult\n\n")
        if dirnames:
            out.write("import " + ", ".join(dirnames))

        out.write("_dummy = CompiledTemplate(lambda: None, 'dummy')\n")
        out.write("join_ = _dummy._join\n")
        out.write("escape_ = _dummy._escape\n")
        out.write("\n")

        for f in filenames:
            path = os.path.join(dirpath, f)

            if "." in f:
                name, _ = f.split(".", 1)
            else:
                name = f

            text = open(path).read()
            text = Template.normalize_text(text)
            code = Template.generate_code(text, path)

            code = code.replace("__template__", name, 1)

            out.write(code)

            out.write("\n\n")
            out.write("%s = CompiledTemplate(%s, %s)\n\n" % (name, name, repr(path)))

            # create template to make sure it compiles
            t = Template(open(path).read(), path)
        out.close()
开发者ID:silvacharles,项目名称:notifry,代码行数:45,代码来源:template.py

示例9: compile_templates

def compile_templates(root):
    """Compiles templates to python code."""
    re_start = re_compile("^", re.M)

    for dirpath, dirnames, filenames in os.walk(root):
        filenames = [
            f for f in filenames if not f.startswith(".") and not f.endswith("~") and not f.startswith("__init__.py")
        ]

        out = open(os.path.join(dirpath, "__init__.py"), "w")
        out.write("from web.template import CompiledTemplate, ForLoop\n\n")
        if dirnames:
            out.write("import " + ", ".join(dirnames))

        for f in filenames:
            path = os.path.join(dirpath, f)

            # create template to make sure it compiles
            t = Template(open(path).read(), path)

            if "." in f:
                name, _ = f.split(".", 1)
            else:
                name = f

            code = Template.generate_code(open(path).read(), path)
            code = re_start.sub("    ", code)

            _gen = (
                ""
                + "\ndef %s():"
                + "\n    loop = ForLoop()"
                + '\n    _dummy  = CompiledTemplate(lambda: None, "dummy")'
                + "\n    join_ = _dummy._join"
                + "\n    escape_ = _dummy._escape"
                + "\n"
                + "\n%s"
                + "\n    return __template__"
            )

            gen_code = _gen % (name, code)
            out.write(gen_code)
            out.write("\n\n")
            out.write("%s = CompiledTemplate(%s(), %s)\n\n" % (name, name, repr(path)))
        out.close()
开发者ID:mzkmzk,项目名称:jit,代码行数:45,代码来源:template.py

示例10: compile_templates

def compile_templates(root):
    """Compiles templates to python code."""
    re_start = re_compile('^', re.M)
    
    for dirpath, dirnames, filenames in os.walk(root):
        filenames = [f for f in filenames if not f.startswith('.') and not f.endswith('~') and not f.startswith('__init__.py')]

        for d in dirnames[:]:
            if d.startswith('.'):
                dirnames.remove(d) # don't visit this dir

        out = open(os.path.join(dirpath, '__init__.py'), 'w')
        out.write('from web.template import CompiledTemplate, ForLoop, TemplateResult\n\n')
        if dirnames:
            out.write("import " + ", ".join(dirnames))
        out.write("\n")

        for f in filenames:
            path = os.path.join(dirpath, f)

            if '.' in f:
                name, _ = f.split('.', 1)
            else:
                name = f
                
            text = open(path).read()
            text = Template.normalize_text(text)
            code = Template.generate_code(text, path)

            code = code.replace("__template__", name, 1)
            
            # inject "join_ = ..; escape_ = .." into the code. 
            # That is required to make escape functionality work correctly.
            code = code.replace("\n", "\n    join_ = %s._join; escape_ = %s._escape\n" % (name, name), 1)

            out.write(code)

            out.write('\n\n')
            out.write('%s = CompiledTemplate(%s, %s)\n\n' % (name, name, repr(path)))

            # create template to make sure it compiles
            t = Template(open(path).read(), path)
        out.close()
开发者ID:alphamule,项目名称:pythonecho,代码行数:43,代码来源:template.py

示例11: find_indent

 def find_indent(text):
     rx = re_compile('  +')
     match = rx.match(text)    
     first_indent = match and match.group(0)
     return first_indent or ""
开发者ID:wangfeng3769,项目名称:remotebox,代码行数:5,代码来源:template.py

示例12: upvars

__all__ = ["render"]

import re, urlparse, pprint, traceback, sys
from Cheetah.Compiler import Compiler
from Cheetah.Filters import Filter
from utils import re_compile, memoize, dictadd
from net import htmlquote, websafe
from webapi import ctx, header, output, input, cookies

def upvars(level=2):
    """Guido van Rossum sez: don't use this function."""
    return dictadd(
      sys._getframe(level).f_globals,
      sys._getframe(level).f_locals)

r_include = re_compile(r'(?!\\)#include \"(.*?)\"($|#)', re.M)
def __compiletemplate(template, base=None, isString=False):
    if isString: 
        text = template
    else: 
        text = open('templates/'+template).read()
    # implement #include at compile-time
    def do_include(match):
        text = open('templates/'+match.groups()[0]).read()
        return text
    while r_include.findall(text): 
        text = r_include.sub(do_include, text)

    execspace = _compiletemplate.bases.copy()
    tmpl_compiler = Compiler(source=text, mainClassName='GenTemplate')
    tmpl_compiler.addImportedVarNames(execspace.keys())
开发者ID:Codesleuth,项目名称:rabbitmq-dotnet-client,代码行数:31,代码来源:cheetah.py

示例13: ssdut_news_list

def ssdut_news_list(page_raw):
    ''' parse the news_list page,
    get a list of news, the same squence as the page,

    result.soup
          .page_no
          .news_list
          .total_records
    '''
    result = Storage()
    soup = bsoup(page_raw)
    result.soup = soup

    # get current page number
    r = soup.find(text=ur"\u4e0b\u4e00\u9875")  # text=u"下一页"
    if r:
        '''not the last page'''
        next_page_link = r.parent.attrs[0][1]
        #logging.debug("r.parent.attrs = %r" % r.parent.attrs)
        r = re_compile(r'/p/(\d+)')
        page_no = r.search(next_page_link).group(1)
        page_no = int(page_no)  # - 1
    else:
        ''' the last page'''
        r = soup.find(text=ur'\u4e0a\u4e00\u9875')
        prev_page_link = r.parent.attrs[0][1]
        #logging.debug("r.parent.attrs = %r" % r.parent.attrs)
        r = re_compile(r'/p/(\d+)')
        page_no = r.search(prev_page_link).group(1)
        page_no = int(page_no)  # + 1
    result.page_no = page_no

    # get the news list
    res = soup.findAll(attrs={"bgcolor": "#EEEEEE"})
    news_list = []
    counter = 1
    for r in res:
        a = r.findChildren("a")
        date_str = r.find(text=re_compile("\d{4}-\d{2}-\d{2}")).encode("utf-8")
        news_list.append(
            {
                "link": a[0].get("href").encode("utf-8"),
                "title": a[0].text.encode("utf-8"),
                "source": a[1].text.encode("utf-8"),
                "source_link": a[1].get("href").encode("utf-8"),
                "date_str": date_str,
                "date": datetime.date(
                    *[int(n) for n in date_str.split("-")]),
                "no": counter,
            })
        counter += 1
        #logging.debug("source = %s, source_link = %s" %
        #              (news_list[-1]['source'], news_list[-1]['source_link']))
    result.news_list = news_list

    # tital news num
    # 共\d+ t条记录
    s = soup.find(text=re_compile(ur"\u5171\d+ \u6761\u8bb0\u5f55"))
    r = re_compile(ur"\u5171(\d+)")
    result.total_records = int(r.search(s).group(1))

    return result
开发者ID:dawn110110,项目名称:ssdut_news_server,代码行数:62,代码来源:parser.py

示例14: _vaild_session_id

 def _vaild_session_id(self,session_id):
     rx = utils.re_compile('^[0-9a-fA-F]+$')
     if rx.match(session_id):
         return True
     
     return False
开发者ID:kangds,项目名称:My-blog-test,代码行数:6,代码来源:session.py

示例15: _valid_session_id

 def _valid_session_id(self, session_id):
     rx = utils.re_compile('^[0-9a-fA-F]+$')
     return rx.match(session_id)
开发者ID:Manchester412,项目名称:socorro,代码行数:3,代码来源:session.py


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