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


Python regex.error方法代码示例

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


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

示例1: gather_relevant_pids

# 需要导入模块: import regex [as 别名]
# 或者: from regex import error [as 别名]
def gather_relevant_pids():
    url_pids = set()
    for result in sparql_queries.url_pids():
        url_pids.add(result)
    ext_id_pids_to_urls = defaultdict(dict)
    for result in sparql_queries.external_id_pids_and_urls():
        for pid, formatters in result.items():
            for formatter_url, formatter_regex in formatters.items():
                if formatter_regex:
                    try:
                        compiled_regex = re.compile(formatter_regex)
                    except re.error:
                        LOGGER.debug(
                            "Using 'regex' third-party library. Formatter regex not supported by the 're' standard library: %s",
                            formatter_regex,
                        )
                        try:
                            compiled_regex = regex.compile(formatter_regex)
                        except regex.error:
                            LOGGER.debug(
                                "Giving up. Formatter regex not supported by 'regex': %s",
                                formatter_regex,
                            )
                            compiled_regex = None
                else:
                    compiled_regex = None
                ext_id_pids_to_urls[pid][formatter_url] = compiled_regex
    return url_pids, ext_id_pids_to_urls 
开发者ID:Wikidata,项目名称:soweego,代码行数:30,代码来源:data_gathering.py

示例2: test_refang_never_excepts_from_urlparse

# 需要导入模块: import regex [as 别名]
# 或者: from regex import error [as 别名]
def test_refang_never_excepts_from_urlparse(self):
        try:
            iocextract.refang_url('hxxp__test]')
            iocextract.refang_url('CDATA[^h00ps://test.com/]]>')
        except ValueError as e:
            self.fail('Unhandled parsing error in refang: {e}'.format(e=e)) 
开发者ID:InQuest,项目名称:python-iocextract,代码行数:8,代码来源:tests.py

示例3: test_extract_custom_iocs_excepts_on_bad_regex

# 需要导入模块: import regex [as 别名]
# 或者: from regex import error [as 别名]
def test_extract_custom_iocs_excepts_on_bad_regex(self):
        # Note: have to use list() here because exceptions are only raised when
        # the generator is executed.
        with self.assertRaises(re.error):
            list(iocextract.extract_custom_iocs('', [r'(mismatched paren']))
            list(iocextract.extract_custom_iocs('', [r'[mismatched bracket']))

        with self.assertRaises(IndexError):
            list(iocextract.extract_custom_iocs('', [r'no capture group']))
            list(iocextract.extract_custom_iocs('', [r''])) 
开发者ID:InQuest,项目名称:python-iocextract,代码行数:12,代码来源:tests.py

示例4: error

# 需要导入模块: import regex [as 别名]
# 或者: from regex import error [as 别名]
def error(message):
    '''log error message, see the :mod:`logging` module'''
    logging.error(message)
    raise ValueError("UMI-tools failed with an error. Check the log file") 
开发者ID:CGATOxford,项目名称:UMI-tools,代码行数:6,代码来源:Utilities.py

示例5: __init__

# 需要导入模块: import regex [as 别名]
# 或者: from regex import error [as 别名]
def __init__(self, lang):
        self._whitelist = set()
        regexes = []
        lang = lang.lower().replace('_', '-')
        while True:
            path = os.path.join(datadir, lang)
            try:
                file = open(path, 'rt', encoding='UTF-8')
            except FileNotFoundError:
                [lang, *suffix] = lang.rsplit('-', 1)
                if suffix:
                    continue
                else:
                    break
            macros = Macros()
            n = None  # hi, pylint
            def error(reason):  # no coverage
                return SyntaxError(reason, (file.name, n, 1, whole_line))
            with file:
                for n, line in enumerate(file, 1):
                    whole_line = line
                    if line.startswith('#'):
                        continue
                    line = line.split()
                    if not line:
                        continue
                    if line[0] == '*':
                        [word] = line[1:]
                        self._whitelist.add(word)
                        self._whitelist.add(word.upper())
                        self._whitelist.add(word.title())
                    elif line[0][0] == '@':
                        if (len(line) >= 4) and (line[0] == '@define') and (line[2] == '='):
                            (_, name, _, *definition) = line
                            definition = r'(?:{re})'.format(re=r'\s+'.join(definition))
                            try:
                                re.compile(definition)
                            except re.error as exc:  # no coverage
                                raise error(exc)
                            try:
                                macros[name] = macros.expand(definition)  # pylint: disable=unsubscriptable-object
                            except KeyError:  # no coverage
                                raise error('duplicate macro definition: {}'.format(name))
                        else:
                            raise error('malformed @-command')  # no coverage
                    else:
                        regex = r'\s+'.join(line)
                        regex = macros.expand(regex)
                        try:
                            re.compile(regex)
                        except re.error as exc:  # no coverage
                            raise error(exc)
                        regexes += [regex]
            break
        if regexes:
            regex = r'\b(?:(?i){0})\b'.format(
                '|'.join(regexes)
            )
            self._find = re.compile(regex).finditer
        else:
            self._find = _find_nothing 
开发者ID:jwilk,项目名称:mwic,代码行数:63,代码来源:intdict.py

示例6: extract_custom_iocs

# 需要导入模块: import regex [as 别名]
# 或者: from regex import error [as 别名]
def extract_custom_iocs(data, regex_list):
    """Extract using custom regex strings.

    Will always yield only the first *group* match from each regex.

    Always use a single capture group! Do this::

        [
            r'(my regex)',  # This yields 'my regex' if the pattern matches.
            r'my (re)gex',  # This yields 're' if the pattern matches.
        ]

    NOT this::

        [
            r'my regex',  # BAD! This doesn't yield anything.
            r'(my) (re)gex',  # BAD! This yields 'my' if the pattern matches.
        ]

    For complicated regexes, you can combine capture and non-capture groups,
    like this::

        [
            r'(?:my|your) (re)gex',  # This yields 're' if the pattern matches.
        ]

    Note the (?: ) syntax for noncapture groups vs the ( ) syntax for the capture
    group.

    :param data: Input text
    :param regex_list: List of strings to treat as regex and match against data.
    :rtype: Iterator[:class:`str`]
    """
    # Compile all the regex strings first, so we can error out quickly.
    regex_objects = []
    for regex_string in regex_list:
        regex_objects.append(re.compile(regex_string))

    # Iterate over regex objects, running each against input data.
    for regex_object in regex_objects:
        for ioc in regex_object.finditer(data):
            yield ioc.group(1) 
开发者ID:InQuest,项目名称:python-iocextract,代码行数:44,代码来源:iocextract.py


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