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


Python re._pattern_type方法代码示例

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


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

示例1: _matches

# 需要导入模块: import re [as 别名]
# 或者: from re import _pattern_type [as 别名]
def _matches(data, **kwargs):
    for key, match in kwargs.items():
        try:
            given_value = data[key]
        except KeyError:
            return False
        else:
            if isinstance(match, re._pattern_type):
                if not match.match(given_value):
                    return False
            elif callable(match):
                if not match(given_value):
                    return False
            else:
                if match != given_value:
                    return False
    return True 
开发者ID:beavyHQ,项目名称:beavy,代码行数:19,代码来源:fetching.py

示例2: _publish_match

# 需要导入模块: import re [as 别名]
# 或者: from re import _pattern_type [as 别名]
def _publish_match(self, publish, names=False, name_only=False):
        """
        Check if publish name matches list of names or regex patterns
        """
        if names:
            for name in names:
                if not name_only and isinstance(name, re._pattern_type):
                    if re.match(name, publish.name):
                        return True
                else:
                    operand = name if name_only else [name, './%s' % name]
                    if publish in operand:
                        return True
            return False
        else:
            return True 
开发者ID:tcpcloud,项目名称:python-aptly,代码行数:18,代码来源:__init__.py

示例3: preprocess_string

# 需要导入模块: import re [as 别名]
# 或者: from re import _pattern_type [as 别名]
def preprocess_string(self, html_string):
        """Here we can modify the text, before it's parsed."""
        if not html_string:
            return html_string
        # Remove silly  » and – chars.
        html_string = html_string.replace(u' \xbb', u'')
        html_string = html_string.replace(u'–', u'-')
        try:
            preprocessors = self.preprocessors
        except AttributeError:
            return html_string
        for src, sub in preprocessors:
            # re._pattern_type is present only since Python 2.5.
            if callable(getattr(src, 'sub', None)):
                html_string = src.sub(sub, html_string)
            elif isinstance(src, str):
                html_string = html_string.replace(src, sub)
            elif callable(src):
                try:
                    html_string = src(html_string)
                except Exception, e:
                    _msg = '%s: caught exception preprocessing html'
                    self._logger.error(_msg, self._cname, exc_info=True)
                    continue
        ##print html_string.encode('utf8') 
开发者ID:skarlekar,项目名称:faces,代码行数:27,代码来源:utils.py

示例4: filter_var_list

# 需要导入模块: import re [as 别名]
# 或者: from re import _pattern_type [as 别名]
def filter_var_list(self, var_list):
        """Filter checkpoint vars for those to be restored.

        Args:
            checkpoint_vars (list): Vars that can be restored from checkpoint.
            to_restore (list[str] or regex, optional): Selects vars to restore.

        Returns:
            list: Variables to be restored from checkpoint.

        """
        if not self.to_restore:
            return var_list
        elif isinstance(self.to_restore, re._pattern_type):
            return {name: var for name, var in var_list.items()
                    if self.to_restore.match(name)}
        elif isinstance(self.to_restore, list):
            return {name: var for name, var in var_list.items()
                    if name in self.to_restore}
        raise TypeError('to_restore ({}) unsupported.'.format(type(self.to_restore))) 
开发者ID:neuroailab,项目名称:tfutils,代码行数:22,代码来源:db_interface.py

示例5: _get

# 需要导入模块: import re [as 别名]
# 或者: from re import _pattern_type [as 别名]
def _get(cls, lb, pattern=None, minimal=False):
        names = cls._lbcall(lb, 'get_list')

        if not names:
            return []

        if pattern is not None:
            if not isinstance(pattern, re._pattern_type):
                pattern = re.compile(pattern)
            names = [name for name in names if pattern.match(name)]

        return cls._get_objects(lb, names, minimal)

    ###########################################################################
    # Public API
    ########################################################################### 
开发者ID:tdevelioglu,项目名称:python-f5,代码行数:18,代码来源:pool.py

示例6: _filter_nodes

# 需要导入模块: import re [as 别名]
# 或者: from re import _pattern_type [as 别名]
def _filter_nodes(self, cond, nodes=None):
        if nodes is None:
            nodes = self.nodes
        res = []
        for n in nodes:
            match = True
            for k, v in cond.iteritems():
                attr = getattr(n, k)
                if isinstance(v, re._pattern_type) and \
                    isinstance(attr, basestring) and v.match(attr) is None:
                    match = False
                    break
                elif attr != v:
                    match = False
                    break
            if match:
                res.append(n)
        return res 
开发者ID:NetEaseGame,项目名称:ATX,代码行数:20,代码来源:android_layout.py

示例7: is_re

# 需要导入模块: import re [as 别名]
# 或者: from re import _pattern_type [as 别名]
def is_re(obj):
    """
    Check if the object is a regex pattern instance.

    Parameters
    ----------
    obj : The object to check.

    Returns
    -------
    is_regex : bool
        Whether `obj` is a regex pattern.

    Examples
    --------
    >>> is_re(re.compile(".*"))
    True
    >>> is_re("foo")
    False
    """

    return isinstance(obj, re._pattern_type) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:24,代码来源:inference.py

示例8: _js_select_by

# 需要导入模块: import re [as 别名]
# 或者: from re import _pattern_type [as 别名]
def _js_select_by(self, term, number):
        if isinstance(term, Pattern):
            js_rx = term.pattern
            js_rx = js_rx.replace('\\A', '^', 1)
            js_rx = js_rx.replace('\\Z', '$', 1)
            js_rx = js_rx.replace('\\z', '$', 1)
            js_rx = re.sub(r'\(\?#.+\)', '', js_rx)
            js_rx = re.sub(r'\(\?-\w+:', '(', js_rx)
        elif type(term) in [six.text_type, six.binary_type]:
            js_rx = '^{}$'.format(term)
        else:
            raise TypeError('expected String or Regexp, got {}'.format(term))

        for way in ['text', 'label', 'value']:
            self._element_call(lambda: self._execute_js('selectOptions{}'.format(way.capitalize()),
                                                        self, js_rx, str(number)))
            if self._is_matching_option(way, term):
                return self.selected_options[0].text

        self._raise_no_value_found(term) 
开发者ID:watir,项目名称:nerodia,代码行数:22,代码来源:select.py

示例9: _label_element_string

# 需要导入模块: import re [as 别名]
# 或者: from re import _pattern_type [as 别名]
def _label_element_string(self):
        label = self.selector.pop('label_element', None)
        if label is None:
            return ''

        key = 'contains_text' if isinstance(label, Pattern) else 'text'

        value = self._process_attribute(key, label)

        if 'contains_text' in self.built:
            self.built['label_element'] = self.built.pop('contains_text')

        # TODO: This conditional can be removed when we remove this deprecation
        if isinstance(label, Pattern):
            self.built['label_element'] = label
            return ''
        else:
            return "[@id=//label[{0}]/@for or parent::label[{0}]]".format(value) 
开发者ID:watir,项目名称:nerodia,代码行数:20,代码来源:selector_builder.py

示例10: _match_attributes

# 需要导入模块: import re [as 别名]
# 或者: from re import _pattern_type [as 别名]
def _match_attributes(self, obj, until=True):
        from ..elements.element import Element

        def check(key):
            expected = obj.get(key)
            if isinstance(self, Element) and not hasattr(self, key):
                actual = self.get_attribute(key)
            else:
                attr = getattr(self, key)
                actual = attr() if callable(attr) else attr
            if isinstance(expected, Pattern):
                return re.search(expected, actual) is not None
            else:
                return expected == actual

        def func(*args):
            truthy = all if until else any
            return truthy(check(key) for key in obj)
        return func 
开发者ID:watir,项目名称:nerodia,代码行数:21,代码来源:wait.py

示例11: _xpath_adjacent

# 需要导入模块: import re [as 别名]
# 或者: from re import _pattern_type [as 别名]
def _xpath_adjacent(self, **kwargs):
        from .elements.html_elements import HTMLElement, HTMLElementCollection
        import nerodia

        plural = kwargs.pop('plural', None)
        index = kwargs.pop('index', None)
        tag_name = kwargs.get('tag_name')

        if not (plural or any(isinstance(val, Pattern) for val in kwargs.values())):
            kwargs['index'] = index or 0

        if not plural and tag_name:
            klass = nerodia.element_class_for(tag_name)
        elif not plural:
            klass = HTMLElement
        elif tag_name:
            klass = nerodia.element_class_for('{}_collection'.format(tag_name),
                                              HTMLElementCollection)
        else:
            klass = HTMLElementCollection

        return klass(self, kwargs) 
开发者ID:watir,项目名称:nerodia,代码行数:24,代码来源:adjacent.py

示例12: test_compile

# 需要导入模块: import re [as 别名]
# 或者: from re import _pattern_type [as 别名]
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) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:11,代码来源:test_re.py

示例13: is_re

# 需要导入模块: import re [as 别名]
# 或者: from re import _pattern_type [as 别名]
def is_re(obj):
    return isinstance(obj, re._pattern_type) 
开发者ID:J535D165,项目名称:recordlinkage,代码行数:4,代码来源:types.py

示例14: render_user_value

# 需要导入模块: import re [as 别名]
# 或者: from re import _pattern_type [as 别名]
def render_user_value(val):
  """Takes a subexpression user value, and attempts to render it in the most
  useful way possible.

  Currently this will use render_re for compiled regular expressions, and will
  fall back to repr() for everything else.

  It should be the goal of this function to return an `eval`able string that
  would yield the equivalent value in a python interpreter.
  """
  if isinstance(val, re._pattern_type):
    return render_re(val)
  return repr(val) 
开发者ID:luci,项目名称:recipes-py,代码行数:15,代码来源:magic_check_fn.py

示例15: process_test_data

# 需要导入模块: import re [as 别名]
# 或者: from re import _pattern_type [as 别名]
def process_test_data(raw_data: list, previous_results: dict) -> Dict[str, Dict[str, object]]:
    leaks = []
    result = {}
    
    url = None
    if 'url' in raw_data:
        url = raw_data['url']['data'].decode()

    for trial, pattern in TRIALS:
        if url:
            if callable(trial):
                trial = trial(url)
                if trial is None:
                    continue
        if trial not in raw_data:
            # Test raw data too old or particular request failed.
            continue
        response = json.loads(raw_data[trial]['data'].decode())
        if response['status_code'] == 200:
            # The pattern can have three different types.
            # - If it is a simple string, we only check if it is contained in the response
            if isinstance(pattern, str):
                if pattern in response['text']:
                    leaks.append(trial)
            # - If it is a RegEx object, we perform a pattern match
            elif isinstance(pattern, re._pattern_type):
                if re.match(response['text']):
                    leaks.append(trial)
            # - If it is callable, we call it with the response text and check the return value
            elif callable(pattern):
                if pattern(response['text']):
                    leaks.append(trial)

    result['leaks'] = leaks
    return result 
开发者ID:PrivacyScore,项目名称:PrivacyScore,代码行数:37,代码来源:serverleak.py


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