##// END OF EJS Templates
byteify-strings: passe sysstr to attr function and wrapper...
marmoute -
r51666:8250ecb5 default
parent child Browse files
Show More
@@ -212,9 +212,7 b' def replacetokens(tokens, opts):'
212 fn = t.string
212 fn = t.string
213
213
214 # *attr() builtins don't accept byte strings to 2nd argument.
214 # *attr() builtins don't accept byte strings to 2nd argument.
215 if (
215 if fn in (
216 fn
217 in (
218 'getattr',
216 'getattr',
219 'setattr',
217 'setattr',
220 'hasattr',
218 'hasattr',
@@ -222,8 +220,6 b' def replacetokens(tokens, opts):'
222 'wrapfunction',
220 'wrapfunction',
223 'wrapclass',
221 'wrapclass',
224 'addattr',
222 'addattr',
225 )
226 and (opts['allow-attr-methods'] or not _isop(i - 1, '.'))
227 ):
223 ):
228 arg1idx = _findargnofcall(1)
224 arg1idx = _findargnofcall(1)
229 if arg1idx is not None:
225 if arg1idx is not None:
@@ -312,12 +308,6 b' def main():'
312 help='rewrite iteritems() and itervalues()',
308 help='rewrite iteritems() and itervalues()',
313 ),
309 ),
314 ap.add_argument(
310 ap.add_argument(
315 '--allow-attr-methods',
316 action='store_true',
317 default=False,
318 help='also handle attr*() when they are methods',
319 ),
320 ap.add_argument(
321 '--treat-as-kwargs',
311 '--treat-as-kwargs',
322 nargs="+",
312 nargs="+",
323 default=[],
313 default=[],
@@ -328,7 +318,6 b' def main():'
328 opts = {
318 opts = {
329 'dictiter': args.dictiter,
319 'dictiter': args.dictiter,
330 'treat-as-kwargs': set(args.treat_as_kwargs),
320 'treat-as-kwargs': set(args.treat_as_kwargs),
331 'allow-attr-methods': args.allow_attr_methods,
332 }
321 }
333 for fname in args.files:
322 for fname in args.files:
334 fname = os.path.realpath(fname)
323 fname = os.path.realpath(fname)
@@ -110,19 +110,6 b' Test attr*() as methods'
110 > def f():
110 > def f():
111 > pass
111 > pass
112 > EOF
112 > EOF
113 $ byteify_strings testfile.py --allow-attr-methods
114 setattr(o, 'a', 1)
115 util.setattr(o, 'ae', 1)
116 util.getattr(o, 'alksjdf', b'default')
117 util.addattr(o, 'asdf')
118 util.hasattr(o, 'lksjdf', b'default')
119 util.safehasattr(o, 'lksjdf', b'default')
120 @eh.wrapfunction(func, 'lksjdf')
121 def f():
122 pass
123 @eh.wrapclass(klass, 'lksjdf')
124 def f():
125 pass
126
113
127 Test without attr*() as methods
114 Test without attr*() as methods
128
115
@@ -142,15 +129,15 b' Test without attr*() as methods'
142 > EOF
129 > EOF
143 $ byteify_strings testfile.py
130 $ byteify_strings testfile.py
144 setattr(o, 'a', 1)
131 setattr(o, 'a', 1)
145 util.setattr(o, b'ae', 1)
132 util.setattr(o, 'ae', 1)
146 util.getattr(o, b'alksjdf', b'default')
133 util.getattr(o, 'alksjdf', b'default')
147 util.addattr(o, b'asdf')
134 util.addattr(o, 'asdf')
148 util.hasattr(o, b'lksjdf', b'default')
135 util.hasattr(o, 'lksjdf', b'default')
149 util.safehasattr(o, b'lksjdf', b'default')
136 util.safehasattr(o, 'lksjdf', b'default')
150 @eh.wrapfunction(func, b'lksjdf')
137 @eh.wrapfunction(func, 'lksjdf')
151 def f():
138 def f():
152 pass
139 pass
153 @eh.wrapclass(klass, b'lksjdf')
140 @eh.wrapclass(klass, 'lksjdf')
154 def f():
141 def f():
155 pass
142 pass
156
143
General Comments 0
You need to be logged in to leave comments. Login now