當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。