@@ -41,9 +41,9 @@ def wrapper(func_or_str):
4141 else :
4242 func = func_or_str
4343 doc = func .__doc__
44-
44+
4545 doc = str_change_func (doc )
46-
46+
4747 if func :
4848 func .__doc__ = doc
4949 return func
@@ -52,97 +52,97 @@ def wrapper(func_or_str):
5252
5353if sys .version_info [0 ] >= 3 :
5454 PY3 = True
55-
55+
5656 input = input
5757 builtin_mod_name = "builtins"
58-
58+
5959 str_to_unicode = no_code
6060 unicode_to_str = no_code
6161 str_to_bytes = encode
6262 bytes_to_str = decode
6363 cast_bytes_py2 = no_code
64-
64+
6565 def isidentifier (s , dotted = False ):
6666 if dotted :
6767 return all (isidentifier (a ) for a in s .split ("." ))
6868 return s .isidentifier ()
69-
69+
7070 open = orig_open
71-
71+
7272 MethodType = types .MethodType
73-
73+
7474 def execfile (fname , glob , loc = None ):
7575 loc = loc if (loc is not None ) else glob
7676 exec compile (open (fname , 'rb' ).read (), fname , 'exec' ) in glob , loc
77-
77+
7878 # Refactor print statements in doctests.
7979 _print_statement_re = re .compile (r"\bprint (?P<expr>.*)$" , re .MULTILINE )
8080 def _print_statement_sub (match ):
8181 expr = match .groups ('expr' )
8282 return "print(%s)" % expr
83-
83+
8484 @_modify_str_or_docstring
8585 def doctest_refactor_print (doc ):
8686 """Refactor 'print x' statements in a doctest to print(x) style. 2to3
8787 unfortunately doesn't pick up on our doctests.
88-
88+
8989 Can accept a string or a function, so it can be used as a decorator."""
9090 return _print_statement_re .sub (_print_statement_sub , doc )
91-
91+
9292 # Abstract u'abc' syntax:
9393 @_modify_str_or_docstring
9494 def u_format (s ):
9595 """"{u}'abc'" --> "'abc'" (Python 3)
96-
96+
9797 Accepts a string or a function, so it can be used as a decorator."""
9898 return s .format (u = '' )
9999
100100else :
101101 PY3 = False
102-
102+
103103 input = raw_input
104104 builtin_mod_name = "__builtin__"
105-
105+
106106 str_to_unicode = decode
107107 unicode_to_str = encode
108108 str_to_bytes = no_code
109109 bytes_to_str = no_code
110110 cast_bytes_py2 = cast_bytes
111-
111+
112112 import re
113113 _name_re = re .compile (r"[a-zA-Z_][a-zA-Z0-9_]*$" )
114114 def isidentifier (s , dotted = False ):
115115 if dotted :
116116 return all (isidentifier (a ) for a in s .split ("." ))
117117 return bool (_name_re .match (s ))
118-
118+
119119 class open (object ):
120120 """Wrapper providing key part of Python 3 open() interface."""
121121 def __init__ (self , fname , mode = "r" , encoding = "utf-8" ):
122122 self .f = orig_open (fname , mode )
123123 self .enc = encoding
124-
124+
125125 def write (self , s ):
126126 return self .f .write (s .encode (self .enc ))
127-
127+
128128 def read (self , size = - 1 ):
129129 return self .f .read (size ).decode (self .enc )
130-
130+
131131 def close (self ):
132132 return self .f .close ()
133-
133+
134134 def __enter__ (self ):
135135 return self
136-
136+
137137 def __exit__ (self , etype , value , traceback ):
138138 self .f .close ()
139-
139+
140140 def MethodType (func , instance ):
141141 return types .MethodType (func , instance , type (instance ))
142-
142+
143143 # don't override system execfile on 2.x:
144144 execfile = execfile
145-
145+
146146 def doctest_refactor_print (func_or_str ):
147147 return func_or_str
148148
@@ -151,7 +151,7 @@ def doctest_refactor_print(func_or_str):
151151 @_modify_str_or_docstring
152152 def u_format (s ):
153153 """"{u}'abc'" --> "u'abc'" (Python 2)
154-
154+
155155 Accepts a string or a function, so it can be used as a decorator."""
156156 return s .format (u = 'u' )
157157
0 commit comments