當前位置: 首頁>>代碼示例>>Python>>正文


Python re.purge方法代碼示例

本文整理匯總了Python中re.purge方法的典型用法代碼示例。如果您正苦於以下問題:Python re.purge方法的具體用法?Python re.purge怎麽用?Python re.purge使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在re的用法示例。


在下文中一共展示了re.purge方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_other_escapes

# 需要導入模塊: import re [as 別名]
# 或者: from re import purge [as 別名]
def test_other_escapes(self):
        self.assertRaises(re.error, re.compile, "\\")
        self.assertEqual(re.match(r"\(", '(').group(), '(')
        self.assertIsNone(re.match(r"\(", ')'))
        self.assertEqual(re.match(r"\\", '\\').group(), '\\')
        self.assertEqual(re.match(r"[\]]", ']').group(), ']')
        self.assertIsNone(re.match(r"[\]]", '['))
        self.assertEqual(re.match(r"[a\-c]", '-').group(), '-')
        self.assertIsNone(re.match(r"[a\-c]", 'b'))
        self.assertEqual(re.match(r"[\^a]+", 'a^').group(), 'a^')
        self.assertIsNone(re.match(r"[\^a]+", 'b'))
        re.purge()  # for warnings
        for c in 'ceghijklmopquyzCEFGHIJKLMNOPQRTUVXY':
            warn = FutureWarning if c in 'Uu' else DeprecationWarning
            with check_py3k_warnings(('', warn)):
                self.assertEqual(re.match('\\%c$' % c, c).group(), c)
                self.assertIsNone(re.match('\\%c' % c, 'a'))
        for c in 'ceghijklmopquyzABCEFGHIJKLMNOPQRTUVXYZ':
            warn = FutureWarning if c in 'Uu' else DeprecationWarning
            with check_py3k_warnings(('', warn)):
                self.assertEqual(re.match('[\\%c]$' % c, c).group(), c)
                self.assertIsNone(re.match('[\\%c]' % c, 'a')) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:24,代碼來源:test_re.py

示例2: test_locale_caching

# 需要導入模塊: import re [as 別名]
# 或者: from re import purge [as 別名]
def test_locale_caching(self):
        # Issue #22410
        oldlocale = locale.setlocale(locale.LC_CTYPE)
        self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale)
        for loc in 'en_US.iso88591', 'en_US.utf8':
            try:
                locale.setlocale(locale.LC_CTYPE, loc)
            except locale.Error:
                # Unsupported locale on this system
                self.skipTest('test needs %s locale' % loc)

        re.purge()
        self.check_en_US_iso88591()
        self.check_en_US_utf8()
        re.purge()
        self.check_en_US_utf8()
        self.check_en_US_iso88591() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:test_re.py

示例3: test_other_escapes

# 需要導入模塊: import re [as 別名]
# 或者: from re import purge [as 別名]
def test_other_escapes(self):
        self.checkPatternError("\\", 'bad escape (end of pattern)', 0)
        self.assertEqual(re.match(r"\(", '(').group(), '(')
        self.assertIsNone(re.match(r"\(", ')'))
        self.assertEqual(re.match(r"\\", '\\').group(), '\\')
        self.assertEqual(re.match(r"[\]]", ']').group(), ']')
        self.assertIsNone(re.match(r"[\]]", '['))
        self.assertEqual(re.match(r"[a\-c]", '-').group(), '-')
        self.assertIsNone(re.match(r"[a\-c]", 'b'))
        self.assertEqual(re.match(r"[\^a]+", 'a^').group(), 'a^')
        self.assertIsNone(re.match(r"[\^a]+", 'b'))
        re.purge()  # for warnings
        for c in 'ceghijklmopqyzCEFGHIJKLMNOPQRTVXY':
            with self.subTest(c):
                with self.assertWarns(DeprecationWarning):
                    self.assertEqual(re.fullmatch('\\%c' % c, c).group(), c)
                    self.assertIsNone(re.match('\\%c' % c, 'a'))
        for c in 'ceghijklmopqyzABCEFGHIJKLMNOPQRTVXYZ':
            with self.subTest(c):
                with self.assertWarns(DeprecationWarning):
                    self.assertEqual(re.fullmatch('[\\%c]' % c, c).group(), c)
                    self.assertIsNone(re.match('[\\%c]' % c, 'a')) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:24,代碼來源:test_re.py

示例4: trace_memory_clean_caches

# 需要導入模塊: import re [as 別名]
# 或者: from re import purge [as 別名]
def trace_memory_clean_caches(self):
        """ Avoid polluting results with some builtin python caches """

        urllib.parse.clear_cache()
        re.purge()
        linecache.clearcache()
        copyreg.clear_extension_cache()

        if hasattr(fnmatch, "purge"):
            fnmatch.purge()  # pylint: disable=no-member
        elif hasattr(fnmatch, "_purge"):
            fnmatch._purge()  # pylint: disable=no-member

        if hasattr(encodings, "_cache") and len(encodings._cache) > 0:
            encodings._cache = {}

        for handler in context.log.handlers:
            handler.flush() 
開發者ID:pricingassistant,項目名稱:mrq,代碼行數:20,代碼來源:job.py

示例5: test_other_escapes

# 需要導入模塊: import re [as 別名]
# 或者: from re import purge [as 別名]
def test_other_escapes(self):
        self.checkPatternError("\\", 'bad escape (end of pattern)', 0)
        self.assertEqual(re.match(r"\(", '(').group(), '(')
        self.assertIsNone(re.match(r"\(", ')'))
        self.assertEqual(re.match(r"\\", '\\').group(), '\\')
        self.assertEqual(re.match(r"[\]]", ']').group(), ']')
        self.assertIsNone(re.match(r"[\]]", '['))
        self.assertEqual(re.match(r"[a\-c]", '-').group(), '-')
        self.assertIsNone(re.match(r"[a\-c]", 'b'))
        self.assertEqual(re.match(r"[\^a]+", 'a^').group(), 'a^')
        self.assertIsNone(re.match(r"[\^a]+", 'b'))
        re.purge()  # for warnings
        for c in 'ceghijklmopqyzCEFGHIJKLMNOPQRTVXY':
            with self.subTest(c):
                with self.assertWarns(DeprecationWarning) as warns:
                    self.assertEqual(re.fullmatch('\\%c' % c, c).group(), c)
                    self.assertIsNone(re.match('\\%c' % c, 'a'))
                self.assertRegex(str(warns.warnings[0].message), 'bad escape')
                self.assertEqual(warns.warnings[0].filename, __file__)
        for c in 'ceghijklmopqyzABCEFGHIJKLMNOPQRTVXYZ':
            with self.subTest(c):
                with self.assertWarns(DeprecationWarning) as warns:
                    self.assertEqual(re.fullmatch('[\\%c]' % c, c).group(), c)
                    self.assertIsNone(re.match('[\\%c]' % c, 'a'))
                self.assertRegex(str(warns.warnings[0].message), 'bad escape')
                self.assertEqual(warns.warnings[0].filename, __file__) 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:28,代碼來源:test_re.py

示例6: dash_R_cleanup

# 需要導入模塊: import re [as 別名]
# 或者: from re import purge [as 別名]
def dash_R_cleanup(fs, ps, pic):
    import gc, copy_reg
    import _strptime, linecache, dircache
    import urlparse, urllib, urllib2, mimetypes, doctest
    import struct, filecmp
    from distutils.dir_util import _path_created

    # Restore some original values.
    warnings.filters[:] = fs
    copy_reg.dispatch_table.clear()
    copy_reg.dispatch_table.update(ps)
    sys.path_importer_cache.clear()
    sys.path_importer_cache.update(pic)

    # Clear assorted module caches.
    _path_created.clear()
    re.purge()
    _strptime._regex_cache.clear()
    urlparse.clear_cache()
    urllib.urlcleanup()
    urllib2.install_opener(None)
    dircache.reset()
    linecache.clearcache()
    mimetypes._default_mime_types()
    struct._cache.clear()
    filecmp._cache.clear()
    doctest.master = None

    # Collect cyclic trash.
    gc.collect() 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:32,代碼來源:regrtest.py

示例7: test_regex_equality_nocache

# 需要導入模塊: import re [as 別名]
# 或者: from re import purge [as 別名]
def test_regex_equality_nocache(self):
        pattern = r'^(?:[a-z0-9\.\-]*)://'
        left = RegexValidator(pattern)
        re.purge()
        right = RegexValidator(pattern)

        self.assertEqual(
            left,
            right,
        ) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:12,代碼來源:tests.py

示例8: test_inline_flags

# 需要導入模塊: import re [as 別名]
# 或者: from re import purge [as 別名]
def test_inline_flags(self):
        # Bug #1700
        upper_char = unichr(0x1ea0) # Latin Capital Letter A with Dot Bellow
        lower_char = unichr(0x1ea1) # Latin Small Letter A with Dot Bellow

        p = re.compile(upper_char, re.I | re.U)
        q = p.match(lower_char)
        self.assertTrue(q)

        p = re.compile(lower_char, re.I | re.U)
        q = p.match(upper_char)
        self.assertTrue(q)

        p = re.compile('(?i)' + upper_char, re.U)
        q = p.match(lower_char)
        self.assertTrue(q)

        p = re.compile('(?i)' + lower_char, re.U)
        q = p.match(upper_char)
        self.assertTrue(q)

        p = re.compile('(?iu)' + upper_char)
        q = p.match(lower_char)
        self.assertTrue(q)

        p = re.compile('(?iu)' + lower_char)
        q = p.match(upper_char)
        self.assertTrue(q)

        self.assertTrue(re.match('(?ixu) ' + upper_char, lower_char))
        self.assertTrue(re.match('(?ixu) ' + lower_char, upper_char))

        # Incompatibilities
        re.purge()
        with check_py3k_warnings():
            re.compile('', re.LOCALE|re.UNICODE)
        with check_py3k_warnings():
            re.compile('(?L)', re.UNICODE)
        with check_py3k_warnings():
            re.compile('(?u)', re.LOCALE)
        with check_py3k_warnings():
            re.compile('(?Lu)')
        with check_py3k_warnings():
            re.compile('(?uL)') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:46,代碼來源:test_re.py

示例9: dash_R_cleanup

# 需要導入模塊: import re [as 別名]
# 或者: from re import purge [as 別名]
def dash_R_cleanup(fs, ps, pic, zdc, abcs):
    import gc, copy_reg
    import _strptime, linecache
    dircache = test_support.import_module('dircache', deprecated=True)
    import urlparse, urllib, urllib2, mimetypes, doctest
    import struct, filecmp
    from distutils.dir_util import _path_created

    # Clear the warnings registry, so they can be displayed again
    for mod in sys.modules.values():
        if hasattr(mod, '__warningregistry__'):
            del mod.__warningregistry__

    # Restore some original values.
    warnings.filters[:] = fs
    copy_reg.dispatch_table.clear()
    copy_reg.dispatch_table.update(ps)
    sys.path_importer_cache.clear()
    sys.path_importer_cache.update(pic)
    try:
        import zipimport
    except ImportError:
        pass # Run unmodified on platforms without zipimport support
    else:
        zipimport._zip_directory_cache.clear()
        zipimport._zip_directory_cache.update(zdc)

    # clear type cache
    sys._clear_type_cache()

    # Clear ABC registries, restoring previously saved ABC registries.
    for abc, registry in abcs.items():
        abc._abc_registry = registry.copy()
        abc._abc_cache.clear()
        abc._abc_negative_cache.clear()

    # Clear assorted module caches.
    _path_created.clear()
    re.purge()
    _strptime._regex_cache.clear()
    urlparse.clear_cache()
    urllib.urlcleanup()
    urllib2.install_opener(None)
    dircache.reset()
    linecache.clearcache()
    mimetypes._default_mime_types()
    filecmp._cache.clear()
    struct._clearcache()
    doctest.master = None
    try:
        import ctypes
    except ImportError:
        # Don't worry about resetting the cache if ctypes is not supported
        pass
    else:
        ctypes._reset_cache()

    # Collect cyclic trash.
    gc.collect() 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:61,代碼來源:regrtest.py

示例10: dash_R_cleanup

# 需要導入模塊: import re [as 別名]
# 或者: from re import purge [as 別名]
def dash_R_cleanup(fs, ps, pic, abcs):
    import gc, copy_reg
    import _strptime, linecache
    dircache = test_support.import_module('dircache', deprecated=True)
    import urlparse, urllib, urllib2, mimetypes, doctest
    import struct, filecmp
    from distutils.dir_util import _path_created

    # Clear the warnings registry, so they can be displayed again
    for mod in sys.modules.values():
        if hasattr(mod, '__warningregistry__'):
            del mod.__warningregistry__

    # Restore some original values.
    warnings.filters[:] = fs
    copy_reg.dispatch_table.clear()
    copy_reg.dispatch_table.update(ps)
    sys.path_importer_cache.clear()
    sys.path_importer_cache.update(pic)

    # clear type cache
    sys._clear_type_cache()

    # Clear ABC registries, restoring previously saved ABC registries.
    for abc, registry in abcs.items():
        abc._abc_registry = registry.copy()
        abc._abc_cache.clear()
        abc._abc_negative_cache.clear()

    # Clear assorted module caches.
    _path_created.clear()
    re.purge()
    _strptime._regex_cache.clear()
    urlparse.clear_cache()
    urllib.urlcleanup()
    urllib2.install_opener(None)
    dircache.reset()
    linecache.clearcache()
    mimetypes._default_mime_types()
    filecmp._cache.clear()
    struct._clearcache()
    doctest.master = None

    # Collect cyclic trash.
    gc.collect() 
開發者ID:Acmesec,項目名稱:CTFCrackTools-V2,代碼行數:47,代碼來源:regrtest.py


注:本文中的re.purge方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。