Mercurial > public > mercurial-scm > hg-stable
comparison contrib/byteify-strings.py @ 39140:da130c5cef90
byteify-strings: prevent "__name__ == '__main__'" from being transformed
This was okay for import-time code transformer, but shouldn't be applied to
source code.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 12 Aug 2018 14:03:22 +0900 |
parents | f77bbd34a1df |
children | 970aaf38c3fc |
comparison
equal
deleted
inserted
replaced
39139:08b2ae9fc030 | 39140:da130c5cef90 |
---|---|
166 # It changes iteritems/values to items/values as they are not | 166 # It changes iteritems/values to items/values as they are not |
167 # present in Python 3 world. | 167 # present in Python 3 world. |
168 elif opts['dictiter'] and fn in ('iteritems', 'itervalues'): | 168 elif opts['dictiter'] and fn in ('iteritems', 'itervalues'): |
169 yield adjusttokenpos(t._replace(string=fn[4:]), coloffset) | 169 yield adjusttokenpos(t._replace(string=fn[4:]), coloffset) |
170 continue | 170 continue |
171 | |
172 # Looks like "if __name__ == '__main__'". | |
173 if (t.type == token.NAME and t.string == '__name__' | |
174 and _isop(i + 1, '==')): | |
175 _ensuresysstr(i + 2) | |
171 | 176 |
172 # Emit unmodified token. | 177 # Emit unmodified token. |
173 yield adjusttokenpos(t, coloffset) | 178 yield adjusttokenpos(t, coloffset) |
174 | 179 |
175 def process(fin, fout, opts): | 180 def process(fin, fout, opts): |