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

Python re.re函数代码示例

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

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



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

示例1: check_triple_double_quotes

    def check_triple_double_quotes(self, definition, docstring):
        r'''D300: Use """triple double quotes""".

        For consistency, always use """triple double quotes""" around
        docstrings. Use r"""raw triple double quotes""" if you use any
        backslashes in your docstrings. For Unicode docstrings, use
        u"""Unicode triple-quoted strings""".

        Note: Exception to this is made if the docstring contains
              """ quotes in its body.

        '''
        if docstring:
            if '"""' in ast.literal_eval(docstring):
                # Allow ''' quotes if docstring contains """, because
                # otherwise """ quotes could not be expressed inside
                # docstring. Not in PEP 257.
                regex = re(r"[uU]?[rR]?'''[^'].*")
            else:
                regex = re(r'[uU]?[rR]?"""[^"].*')

            if not regex.match(docstring):
                illegal_matcher = re(r"""[uU]?[rR]?("+|'+).*""")
                illegal_quotes = illegal_matcher.match(docstring).group(1)
                return violations.D300(illegal_quotes)
开发者ID:nnishimura,项目名称:python,代码行数:25,代码来源:checker.py


示例2: run_pep257

def run_pep257():
    log.setLevel(logging.DEBUG)
    opt_parser = get_option_parser()
    # setup the logger before parsing the config file, so that command line
    # arguments for debug / verbose will be printed.
    options, arguments = opt_parser.parse_args()
    setup_stream_handlers(options)
    # We parse the files before opening the config file, since it changes where
    # we look for the file.
    options = get_options(arguments, opt_parser)
    if not validate_options(options):
        return INVALID_OPTIONS_RETURN_CODE
    # Setup the handler again with values from the config file.
    setup_stream_handlers(options)

    collected = collect(arguments or ['.'],
                        match=re(options.match + '$').match,
                        match_dir=re(options.match_dir + '$').match)

    log.debug("starting pep257 in debug mode.")

    Error.explain = options.explain
    Error.source = options.source
    collected = list(collected)
    checked_codes = get_checked_error_codes(options)
    errors = check(collected, select=checked_codes)
    code = NO_VIOLATIONS_RETURN_CODE
    count = 0
    for error in errors:
        sys.stderr.write('%s\n' % error)
        code = VIOLATIONS_RETURN_CODE
        count += 1
    if options.count:
        print(count)
    return code
开发者ID:bagelbits,项目名称:pep257,代码行数:35,代码来源:pep257.py


示例3: run_pep257

def run_pep257():
    log.setLevel(logging.DEBUG)
    opt_parser = get_option_parser()
    # setup the logger before parsing the config file, so that command line
    # arguments for debug / verbose will be printed.
    options, arguments = opt_parser.parse_args()
    setup_stream_handler(options)
    # We parse the files before opening the config file, since it changes where
    # we look for the file.
    options = get_options(arguments, opt_parser)
    # Setup the handler again with values from the config file.
    setup_stream_handler(options)

    collected = collect(arguments or ['.'],
                        match=re(options.match + '$').match,
                        match_dir=re(options.match_dir + '$').match)

    log.debug("starting pep257 in debug mode.")

    Error.explain = options.explain
    Error.source = options.source
    collected = list(collected)
    errors = check(collected, ignore=options.ignore.split(','))
    code = 0
    count = 0
    for error in errors:
        sys.stderr.write('%s\n' % error)
        code = 1
        count += 1
    if options.count:
        print(count)
    return code
开发者ID:blueyed,项目名称:pylama,代码行数:32,代码来源:pep257.py


示例4: main

def main(options, arguments):
    Error.explain = options.explain
    Error.source = options.source
    collected = collect(arguments or ['.'],
                        match=re(options.match + '$').match,
                        match_dir=re(options.match_dir + '$').match)
    code = 0
    for error in check(collected, ignore=options.ignore.split(',')):
        sys.stderr.write('%s\n' % error)
        code = 1
    return code
开发者ID:LeeroyDing,项目名称:anaconda,代码行数:11,代码来源:pep257.py


示例5: main

def main(options, arguments):
    if options.debug:
        log.setLevel(logging.DEBUG)
    log.debug("starting pep257 in debug mode.")
    Error.explain = options.explain
    Error.source = options.source
    collected = collect(arguments or ['.'],
                        match=re(options.match + '$').match,
                        match_dir=re(options.match_dir + '$').match)
    code = 0
    for error in check(collected, ignore=options.ignore.split(',')):
        sys.stderr.write('%s\n' % error)
        code = 1
    return code
开发者ID:bartvm,项目名称:pep257,代码行数:14,代码来源:pep257.py


示例6: _get_ignore_decorators

 def _get_ignore_decorators(config):
     """Return the `ignore_decorators` as None or regex."""
     if config.ignore_decorators:  # not None and not ''
         ignore_decorators = re(config.ignore_decorators)
     else:
         ignore_decorators = None
     return ignore_decorators
开发者ID:byd913,项目名称:vim,代码行数:7,代码来源:config.py


示例7: is_public

 def is_public(self):
     # Check if we are a setter/deleter method, and mark as private if so.
     for decorator in self.decorators:
         # Given 'foo', match 'foo.bar' but not 'foobar' or 'sfoo'
         if re(r"^{0}\.".format(self.name)).match(decorator.name):
             return False
     name_is_public = not self.name.startswith('_') or is_magic(self.name)
     return self.parent.is_public and name_is_public
开发者ID:bagelbits,项目名称:pep257,代码行数:8,代码来源:pep257.py


示例8: _get_leading_words

    def _get_leading_words(line):
        """Return any leading set of words from `line`.

        For example, if `line` is "  Hello world!!!", returns "Hello world".
        """
        result = re("[A-Za-z ]+").match(line.strip())
        if result is not None:
            return result.group()
开发者ID:nnishimura,项目名称:python,代码行数:8,代码来源:checker.py


示例9: keys

    def keys(self, pattern):
        """ Add abilite to retrieve a list of keys with wildcard pattern.

        :returns: List keys

        """
        offset = len(self.make_key(''))
        mask = re(fnmatch.translate(self.make_key(pattern)))
        return [k[offset:] for k in self._cache.keys() if mask.match(k)]
开发者ID:emil2k,项目名称:joltem,代码行数:9,代码来源:cache.py


示例10: is_public

 def is_public(self):
     """Return True iff this method should be considered public."""
     # Check if we are a setter/deleter method, and mark as private if so.
     for decorator in self.decorators:
         # Given 'foo', match 'foo.bar' but not 'foobar' or 'sfoo'
         if re(r"^{}\.".format(self.name)).match(decorator.name):
             return False
     name_is_public = (not self.name.startswith('_') or
                       self.name in VARIADIC_MAGIC_METHODS or
                       self.is_magic)
     return self.parent.is_public and name_is_public
开发者ID:Marslo,项目名称:VimConfig,代码行数:11,代码来源:parser.py


示例11: parse_options

def parse_options(args=None, config=True, **overrides): # noqa
    """ Parse options from command line and configuration files.

    :return argparse.Namespace:

    """
    if args is None:
        args = []

    # Parse args from command string
    options = PARSER.parse_args(args)
    options.file_params = dict()
    options.linter_params = dict()

    # Override options
    for k, v in overrides.items():
        passed_value = getattr(options, k, _Default())
        if isinstance(passed_value, _Default):
            setattr(options, k, _Default(v))

    # Compile options from ini
    if config:
        cfg = get_config(str(options.options))
        for k, v in cfg.default.items():
            LOGGER.info('Find option %s (%s)', k, v)
            passed_value = getattr(options, k, _Default())
            if isinstance(passed_value, _Default):
                setattr(options, k, _Default(v))

        # Parse file related options
        for name, opts in cfg.sections.items():

            if not name.startswith('pylama'):
                continue

            if name == cfg.default_section:
                continue

            name = name[7:]

            if name in LINTERS:
                options.linter_params[name] = dict(opts)
                continue

            mask = re(fnmatch.translate(name))
            options.file_params[mask] = dict(opts)

    # Postprocess options
    opts = dict(options.__dict__.items())
    for name, value in opts.items():
        if isinstance(value, _Default):
            setattr(options, name, process_value(name, value.value))

    return options
开发者ID:BearDrinkbeer,项目名称:python-mode,代码行数:54,代码来源:config.py


示例12: Rue

def Rue(f,A="",s=0):
	from random import choice
	if f in G:f=G[f]
	else:
		c=f
		f=k("",open(f).read())
		if f.startswith("import "):
			a=f.find("\n",8)
			f=open(f[7:a]).read()+f[a:]
		a=f.find("\nimport ")+1
		while a:
			b=f.find("\n",a+8)
			f=f[:a]+open(f[a+7:b]).read()+f[b:]
			a=f.find("\nimport ",a)+1
		f=f.split("\n::=\n")
		G[c]=f
	c=""
	R=[]
	for lf,C in zip(range(len(f)-1,-1,-1),f):
		R+=((re(R[0],16).sub,R[1] if len(R) == 2 else R[1:] or "",len(R) == 1) for R in (R.split("::=") for R in c.split("\n") if R))
		while 1:
			while 1:
				c=C=C.replace("@@",A)
				for p0,p1,p2 in R:
					C=p0(choice(p1) if p2 else p1,C,1)
					if c is not C:break
				else:break
				if D:print(" "*s+C)
			if lf:break
			a=C.find("}")
			if a == -1:break
			while 1:
				b=C.rfind("{",0,a)
				c=C.rfind(":",0,b)
				f=C[c+1:b]
				b=C[b+1:a]
				C=C[:c]+(Smod[f](b) if f in Smod else Rue(f,b,s+1))+C[a+1:]
				a=C.find("}",c)
				if a == -1:break
	return C
开发者ID:serprex,项目名称:Rue,代码行数:40,代码来源:Rue.py


示例13: highlighter

def highlighter(text, terms):
    if not terms:
        return text
    def highlight(match):
        return '<span class="highlight">%s</span>' % match.groups(0)[0]
    return re(r'(%s)' % '|'.join(escape(term) for term in terms), IGNORECASE).sub(highlight, text)
开发者ID:kriskowal,项目名称:3rin.gs,代码行数:6,代码来源:markup.py


示例14: re

from re import compile as re
from iterkit import all

part_finder = re(r'(_+|\d+|[A-Z]+(?![a-z])|[A-Z][a-z]+|[A-Z]+|[a-z]+)')

class CaseString(object):

    def __init__(
        self,
        string = None,
        parts = None,
        prefix = None,
        suffix = None
    ):

        # UPPER_CASE
        # lower_case
        # TitleCase
        # camelCase
        # TitleCase1_2

        self.string = string

        if parts is not None:
            self.parts = parts
            self.prefix = ''
            self.suffix = ''
        else:

            subparts = part_finder.findall(string)
开发者ID:kriskowal,项目名称:planes,代码行数:30,代码来源:case.py


示例15: _get_matches

 def _get_matches(config):
     """Return the `match` and `match_dir` functions for `config`."""
     match_func = re(config.match + '$').match
     match_dir_func = re(config.match_dir + '$').match
     return match_func, match_dir_func
开发者ID:byd913,项目名称:vim,代码行数:5,代码来源:config.py


示例16: check_def_documents_parameteres

    def check_def_documents_parameteres(self, function, docstring):
        """Definition must document parameters in docstrings.

        All functions and methods must document each of the parameters in the
        NumPy format.

        https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt

        Parameters
        ----------
        function: str
            The string text of the function code
        docstring: str
            The docstring for the function, or None

        """
        if (not isinstance(function, Method) and
                not isinstance(function, Function)):
            return

        # I use ___ to prefix locals here, because we had a naming conflict
        # with a function called name and a local variable called name, so I
        # want to avoid all naming conflicts.
        ___fail = False

        # If it does not exist return
        if not docstring:
            return

        # In case of multline function definition with long parameters, we need
        # to reconstruct the definition from source.
        function_source = function.source.split("\n")
        function_def = ''
        while not function_def.endswith(":"):
            function_def += function_source.pop(0)
        function_def = function_def.strip()
        ___split = function_def.split("(")
        ___name = ___split[0].split()[1]

        params = ___split[1].split("):")[0]
        # We also need to clean up any extra spaces
        params = re(', +').split(params)
        params = [entry.split("=")[0] for entry in params]

        # Emptry string is for when there are no params.
        IGNORED_PARAMETERS = ["self", "request", "*args", "**kwargs", ""]

        # Just drop all ignored parameters. This is a lot cleaner.
        params = list(set(params) - set(IGNORED_PARAMETERS))

        # Ignore self if it is the only param
        if len(params) == 0:
            return

        if len(params) > 0:
            if not re('Parameters\n\s+----------\n').search(docstring):
                print "[Method %s] Forgot to define parameters section." % (
                    ___name)
                ___fail = True

        for p in params:
            # Ignore self as a parameter
            if p in IGNORED_PARAMETERS:
                continue

            # name: type
            #    description
            reg = escape(p) + ': \w+\n\s+\w+'
            if not re(reg).search(docstring):
                print "[Method %s] Forgot to document parameter %s" % (
                    ___name, p)
                ___fail = True

        if ___fail:
            return D410()
开发者ID:bagelbits,项目名称:pep257,代码行数:75,代码来源:pep257.py


示例17: import

from re import compile as re
import operator as op

from funcparserlib.lexer import make_tokenizer, Token
from funcparserlib.parser import (some, a, maybe, finished, skip, many)


NUMBER_RE = re('(\d*\.?\d*)')
CONVERT = {
    "bytes": (
        ("TB", 1099511627776), ("GB", 1073741824.0), ("MB", 1048576.0), ("KB", 1024.0),
    ),
    "bits": (
        ("Tb", 1099511627776), ("Gb", 1073741824.0), ("Mb", 1048576.0), ("Kb", 1024.0),
    ),
    "bps": (
        ("Gbps", 1000000000.0), ("Mbps", 1000000.0), ("Kbps", 1000.0),
    ),
    "short": (
        ("Tri", 1000000000000.0), ("Bil", 1000000000.0), ("Mil", 1000000.0), ("K",   1000.0),
    ),
    "s": (
        ("y", 31536000.0),
        ("M", 2592000.0),
        ("w", 604800.0),
        ("d", 86400.0),
        ("h", 3600.0),
        ("m", 60.0),
        ("s", 1.0),
        ("ms", 0.001),
    ),
开发者ID:Runscope,项目名称:graphite-beacon,代码行数:31,代码来源:utils.py


示例18: kafka_system_metric

def kafka_system_metric(match):
    return {
        'name': 'kafka-' + match.group(2),
        'labels': {
            'system': match.group(1)
        }
    }

"""
Simple metrics are encoded as strings.
Metrics that need a regex to extract labels are encoded as a tuple (regex, parser).
"""
metrics = {
    'org.apache.samza.system.kafka.KafkaSystemProducerMetrics': [
        (re('(.*)-(producer-send-failed)'), kafka_system_metric),
        (re('(.*)-(producer-send-success)'), kafka_system_metric),
        (re('(.*)-(producer-sends)'), kafka_system_metric),
        (re('(.*)-(producer-retries)'), kafka_system_metric),
        (re('(.*)-(flush-ms)'), kafka_system_metric),
        (re('(.*)-(flush-failed)'), kafka_system_metric),
        (re('(.*)-(flushes)'), kafka_system_metric),
        (re('(.*)-(flush-ns)'), kafka_system_metric),
        'serialization error',
    ],
    'org.apache.samza.system.kafka.KafkaSystemConsumerMetrics': {
        (re('(.*)-(\d+)-(bytes-read)'), topic_partition_metric),
        (re('(.*)-(\d+)-(high-watermark)'), topic_partition_metric),
        (re('(.*)-(\d+)-(messages-read)'), topic_partition_metric),
        (re('(.*)-(\d+)-(offset-change)'), topic_partition_metric),
        (re('(.*)-(\d+)-(messages-behind-high-watermark)'), topic_partition_metric),
开发者ID:juris,项目名称:samza-prometheus-exporter,代码行数:30,代码来源:samza.py


示例19: leading_space

def leading_space(string):
    return re('\s*').match(string).group()
开发者ID:bagelbits,项目名称:pep257,代码行数:2,代码来源:pep257.py


示例20: bytes

from threading import get_ident as gettid
from os import getpid, unlink, F_OK, O_RDONLY, O_WRONLY, O_EXCL, O_CREAT

from pathlib import Path
from re import compile as re

from time import sleep
from random import choice
from itertools import chain

b64bytes = b'+_'
b64chars = b64bytes.decode()

b64seq = bytes(b64encode(bytes((i << 2,)), b64bytes)[0] for i in range(64)).decode()
#b64set = set(b64seq)
directory_re = re('[A-Za-z0-9'+b64chars+']{2}')

def my_b64encode(b):
	return b64encode(b, b64bytes).rstrip(b'=').decode()

def my_b64decode(s):
	return b64decode(s + '=' * (-len(s) & 3), b64bytes)

class FilesystemListAction(PoolAction):
	directory = None
	cursor = None

	def sync(self):
		super().sync()
		return self.cursor
开发者ID:wsldankers,项目名称:fruitbak,代码行数:30,代码来源:filesystem.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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