python类_pattern_type()的实例源码

test_re.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def test_compile(self):
        # Test return value when given string and pattern as parameter
        pattern = re.compile('random pattern')
        self.assertIsInstance(pattern, re._pattern_type)
        same_pattern = re.compile(pattern)
        self.assertIsInstance(same_pattern, re._pattern_type)
        self.assertIs(same_pattern, pattern)
        # Test behaviour when not given a string or pattern as parameter
        self.assertRaises(TypeError, re.compile, 0)
core.py 文件源码 项目:r2-d7 作者: FreakyDug 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def register_handler(self, pattern, method):
        if not isinstance(pattern, re._pattern_type):
            pattern = re.compile(pattern)
        self._handlers[pattern] = method
core.py 文件源码 项目:r2-d7 作者: FreakyDug 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def register_dm_handler(self, pattern, method):
        if not isinstance(pattern, re._pattern_type):
            pattern = re.compile(pattern)
        self._dm_handlers[pattern] = method
crontab.py 文件源码 项目:python-crontab 作者: doctormo 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def find_command(self, command):
        """Return an iter of jobs matching any part of the command."""
        for job in list(self.crons):
            if isinstance(command, re._pattern_type):
                if command.findall(job.command):
                    yield job
            elif command in job.command:
                yield job
crontab.py 文件源码 项目:python-crontab 作者: doctormo 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def find_comment(self, comment):
        """Return an iter of jobs that match the comment field exactly."""
        for job in list(self.crons):
            if isinstance(comment, re._pattern_type):
                if comment.findall(job.comment):
                    yield job
            elif comment == job.comment:
                yield job
test_re.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_compile(self):
        # Test return value when given string and pattern as parameter
        pattern = re.compile('random pattern')
        self.assertIsInstance(pattern, re._pattern_type)
        same_pattern = re.compile(pattern)
        self.assertIsInstance(same_pattern, re._pattern_type)
        self.assertIs(same_pattern, pattern)
        # Test behaviour when not given a string or pattern as parameter
        self.assertRaises(TypeError, re.compile, 0)
common.py 文件源码 项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda 作者: SignalMedia 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def is_re(obj):
    return isinstance(obj, re._pattern_type)
test_re.py 文件源码 项目:pefile.pypy 作者: cloudtracer 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_compile(self):
        # Test return value when given string and pattern as parameter
        pattern = re.compile('random pattern')
        self.assertIsInstance(pattern, re._pattern_type)
        same_pattern = re.compile(pattern)
        self.assertIsInstance(same_pattern, re._pattern_type)
        self.assertIs(same_pattern, pattern)
        # Test behaviour when not given a string or pattern as parameter
        self.assertRaises(TypeError, re.compile, 0)
test_re.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_compile(self):
        # Test return value when given string and pattern as parameter
        pattern = re.compile('random pattern')
        self.assertIsInstance(pattern, re._pattern_type)
        same_pattern = re.compile(pattern)
        self.assertIsInstance(same_pattern, re._pattern_type)
        self.assertIs(same_pattern, pattern)
        # Test behaviour when not given a string or pattern as parameter
        self.assertRaises(TypeError, re.compile, 0)
test_re.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def test_compile(self):
        # Test return value when given string and pattern as parameter
        pattern = re.compile('random pattern')
        self.assertIsInstance(pattern, re._pattern_type)
        same_pattern = re.compile(pattern)
        self.assertIsInstance(same_pattern, re._pattern_type)
        self.assertIs(same_pattern, pattern)
        # Test behaviour when not given a string or pattern as parameter
        self.assertRaises(TypeError, re.compile, 0)
pyrocopy.py 文件源码 项目:pyrocopy 作者: caskater4 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _normalizeDirPattern(pattern, path):
    bIsRegex = False
    tmpPattern = pattern
    if (isinstance(pattern, re._pattern_type)):
        tmpPattern = pattern.pattern
        bIsRegex = True
    elif (pattern.startswith('re:')):
        tmpPattern = pattern[3:]
        bIsRegex = True

    numPathSep = path.count(os.path.sep)
    numPatternSep = tmpPattern.count(os.path.sep)

    # When the path has more levels, fill in the pattern with wildcards
    if (numPathSep > numPatternSep):
        while (numPathSep > numPatternSep):
            if (bIsRegex):
                if (tmpPattern != ''):
                    tmpPattern = tmpPattern + "/.*"
                else:
                    tmpPattern = '.*'
            else:
                tmpPattern = os.path.join(tmpPattern, "*")
            numPatternSep = numPatternSep + 1

    if (bIsRegex):
        return re.compile(tmpPattern)
    else:
        return tmpPattern
pyrocopy.py 文件源码 项目:pyrocopy 作者: caskater4 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _normalizeFilePattern(pattern, filepath):
    bIsRegex = False
    tmpPattern = pattern
    if (isinstance(pattern, re._pattern_type)):
        tmpPattern = pattern.pattern
        bIsRegex = True
    elif (pattern.startswith('re:')):
        tmpPattern = pattern[3:]
        bIsRegex = True

    # Separate the file pattern from the dir/path pattern
    patternParts = os.path.split(tmpPattern)
    tmpPattern = patternParts[0]

    numPathSep = filepath.count(os.path.sep)
    numPatternSep = tmpPattern.count(os.path.sep)
    if (tmpPattern != ''):
        numPatternSep = numPatternSep + 1

    # When the path has more levels, fill in the pattern with wildcards
    if (numPathSep > numPatternSep):
        while (numPathSep > numPatternSep):
            if (bIsRegex):
                if (tmpPattern != ''):
                    tmpPattern = tmpPattern + "/.*"
                else:
                    tmpPattern = '.*'
            else:
                tmpPattern = os.path.join(tmpPattern, "*")
            numPatternSep = numPatternSep + 1

    # Append the file pattern back
    if (bIsRegex):
        tmpPattern = tmpPattern + "/" + patternParts[1]
    else:
        tmpPattern = os.path.join(tmpPattern, patternParts[1])

    if (bIsRegex):
        return re.compile(tmpPattern)
    else:
        return tmpPattern
operators.py 文件源码 项目:sqlalchemy_zdb 作者: skftn 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def zdb_like_op(left, right, c, compiler, tables, format_args):
    r"""Implement the ``LIKE`` operator.

    In a normal context, produces the expression::

        column:"foo"

    E.g.::

        stmt = select([sometable]).\
            where(sometable.c.column.like("foo"))


    In a regex context, produces the expression::

        column:~"foo[a-z]"

    E.g.::

        stmt = select([sometable]).\
            where(sometable.c.column.like(re.compile("foo[a-z]")))
    """
    from sqlalchemy_zdb.compiler import compile_clause

    if isinstance(right.value, re._pattern_type):
        _oper = ":~"
    else:
        _oper = ":"

    return "%s%s%s" % (left.name, _oper, compile_clause(right, compiler, tables, format_args))
compiler.py 文件源码 项目:sqlalchemy_zdb 作者: skftn 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def compile_clause(c, compiler, tables, format_args):
    if isinstance(c, BindParameter) and isinstance(c.value, (
            str, int, re._pattern_type, ZdbLiteral)):
        if isinstance(c.value, str):
            return "\"%s\"" % escape_tokens(c.value)
        elif isinstance(c.value, re._pattern_type):
            return "\"%s\"" % c.value.pattern
        elif isinstance(c.value, ZdbLiteral):
            return c.value.literal
        else:
            return c.value
    elif isinstance(c, (True_, False_)):
        return str(type(c) == True_).lower()
    elif isinstance(c, TextClause):
        return c.text
    elif isinstance(c, BinaryExpression):
        return compile_binary_clause(c, compiler, tables, format_args)
    elif isinstance(c, BooleanClauseList):
        return compile_boolean_clause_list(c, compiler, tables, format_args)
    elif isinstance(c, Column):
        return compile_column_clause(c, compiler, tables, format_args)
    elif isinstance(c, Grouping):
        return compile_grouping(c, compiler, tables, format_args)
    elif isinstance(c, Null):
        return "NULL"
    raise ValueError("Unsupported clause")
test_re.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def test_compile(self):
        # Test return value when given string and pattern as parameter
        pattern = re.compile('random pattern')
        self.assertIsInstance(pattern, re._pattern_type)
        same_pattern = re.compile(pattern)
        self.assertIsInstance(same_pattern, re._pattern_type)
        self.assertIs(same_pattern, pattern)
        # Test behaviour when not given a string or pattern as parameter
        self.assertRaises(TypeError, re.compile, 0)
bot.py 文件源码 项目:SignalBotFramework 作者: JankySolutions 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def register_handler(self, handler, regex, group):
        if not isinstance(regex, re._pattern_type):
            regex = re.compile(regex)
        self.handlers.append((handler, regex, group))
netcfg.py 文件源码 项目:ansible-provider-docs 作者: alibaba 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self, indent=1, contents=None, ignore_lines=None):
        self._indent = indent
        self._items = list()
        self._config_text = None

        if ignore_lines:
            for item in ignore_lines:
                if not isinstance(item, re._pattern_type):
                    item = re.compile(item)
                DEFAULT_IGNORE_LINES_RE.add(item)

        if contents:
            self.load(contents)
__init__.py 文件源码 项目:widgetastic.patternfly 作者: RedHatQE 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _repr_step(image, step):
        if isinstance(step, re._pattern_type):
            # Make it look like r'pattern'
            step_repr = 'r' + re.sub(r'^[^"\']', '', repr(step.pattern))
        else:
            step_repr = step
        if image is None:
            return step_repr
        else:
            return '{}[{}]'.format(step_repr, image)
futhon_parser_test.py 文件源码 项目:futhon 作者: delihiros 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_regex_string(self):
        parser = futhon_parser.FuthonParser()
        self.assertIsInstance(parser.parse("#\"\""),
                              re._pattern_type)
        self.assertIsInstance(parser.parse("#\"hello\""),
                              re._pattern_type)
attribute_sets.py 文件源码 项目:ReGraph 作者: Kappa-Dev 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _regex_to_string(a):
    if isinstance(a, str):
        return a
    elif isinstance(a, re._pattern_type):
        return a.pattern
    elif isinstance(a, RegexSet):
        if a.pattern is not None:
            return a.pattern
        else:
            return None
    else:
        raise AttributeSetError("Cannot convert regex to string!")


问题


面经


文章

微信
公众号

扫码关注公众号