Commit 83c44e08 authored by YOU's avatar YOU Committed by Dylan Trotter

Chore third party libs (use stdlib whenever possible) (#145)

* move functools.py to stdlib
* move md5.py to stdlib
*  move re.py re_tests.py sre_*.py to stdlib
parent 88e43ac0
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""MD5 message digest algorithm."""
import _md5
new = _md5.new
md5 = _md5.new
digest_size = _md5.digest_size
blocksize = 1
# $Id$
#
# Copyright (C) 2005 Gregory P. Smith (greg@krypto.org)
# Licensed to PSF under a Contributor Agreement.
# import warnings
# warnings.warn("the md5 module is deprecated; use hashlib instead",
# DeprecationWarning, 2)
# from hashlib import md5
import _md5
new = _md5.new
md5 = _md5.new
digest_size = 16
......@@ -104,6 +104,10 @@ This module also defines an exception 'error'.
import sre_compile
import sre_parse
# try:
# import _locale
# except ImportError:
# _locale = None
_locale = None
BRANCH = "branch"
SUBPATTERN = "subpattern"
......@@ -194,10 +198,8 @@ def compile(pattern, flags=0):
def purge():
"Clear the regular expression cache"
# _cache.clear()
# _cache_repl.clear()
globals()['_cache'] = {}
globals()['_cache_repl'] = {}
_cache.clear()
_cache_repl.clear()
def template(pattern, flags=0):
"Compile a template pattern, returning a pattern object"
......@@ -252,8 +254,7 @@ def _compile(*key):
raise error, v # invalid expression
if not bypass_cache:
if len(_cache) >= _MAXCACHE:
# _cache.clear()
globals()['_cache'] = {}
_cache.clear()
if p.flags & LOCALE:
if not _locale:
return p
......@@ -274,8 +275,7 @@ def _compile_repl(*key):
except error, v:
raise error, v # invalid expression
if len(_cache_repl) >= _MAXCACHE:
# _cache_repl.clear()
globals()['_cache_repl'] = {}
_cache_repl.clear()
_cache_repl[key] = p
return p
......
......@@ -10,16 +10,14 @@
"""Internal support module for sre"""
# TODO: Support from foo import * syntax.
import sre_constants
for name in sre_constants.__all__:
globals()[name] = getattr(sre_constants, name)
# XXX: show string offset and offending character for all errors
import sys
newdict = lambda _ : {}
# from sre_constants import *
import sre_constants
for name in sre_constants.__all__:
globals()[name] = getattr(sre_constants, name)
SPECIAL_CHARS = ".\\[{()*+?^$|"
REPEAT_CHARS = "*+?{"
......@@ -73,7 +71,7 @@ class Pattern(object):
self.flags = 0
self.open = []
self.groups = 1
self.groupdict = newdict("module")
self.groupdict = {}
self.lookbehind = 0
def opengroup(self, name=None):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment