Permalink
Browse files

Added a way to disable the unicode fixer and added an entry to README

  • Loading branch information...
1 parent 1a57315 commit c1ff4ca12af20ce584efe40599fc49257987155b @mitsuhiko committed Mar 14, 2012
Showing with 24 additions and 1 deletion.
  1. +14 −0 README
  2. +10 −1 libmodernize/main.py
View
14 README
@@ -12,3 +12,17 @@
compatible codebase. The code that it generates has a runtime
dependency on `six`.
+ Unicode Literal Control:
+
+ - By default modernize will wrap literals with the six helpers.
+ This is useful if you want to support Python 3.1 and Python 3.2
+ without bigger changes.
+ - Alternatively there is the ``--compat-unicode`` flag which
+ does not change unicode literals at all which means that you
+ can take advantage of PEP 414.
+ - The last alternative is the ``--future-unicode`` flag which
+ imports the ``unicode_literals`` from the ``__future__`` module.
+ This requires Python 2.6 and later and will require that you
+ mark bytestrings with ``b''`` and native strings in ``str(b'')``
+ or something similar that survives the transformation.
+
View
11 libmodernize/main.py
@@ -35,6 +35,9 @@ def main(args=None):
help="Write back modified files")
parser.add_option("-n", "--nobackups", action="store_true", default=False,
help="Don't write backups for modified files.")
+ parser.add_option("--compat-unicode", action="store_true", default=False,
+ help="Leave u'' and b'' prefixes unchanged (requires "
+ "Python 3.3 and higher).")
parser.add_option("--future-unicode", action="store_true", default=False,
help="Use unicode_strings future_feature instead of the six.u function "
"(only useful for Python 2.6+).")
@@ -77,10 +80,16 @@ def main(args=None):
# Initialize the refactoring tool
unwanted_fixes = set(options.nofix)
- if options.future_unicode:
+
+ # Remove unicode fixers depending on command line options
+ if options.compat_unicode:
+ unwanted_fixes.add('libmodernize.fixes.fix_unicode')
+ unwanted_fixes.add('libmodernize.fixes.fix_unicode_future')
+ elif options.future_unicode:
unwanted_fixes.add('libmodernize.fixes.fix_unicode')
else:
unwanted_fixes.add('libmodernize.fixes.fix_unicode_future')
+
if options.no_six:
unwanted_fixes.update(six_fix_names)
explicit = set()

0 comments on commit c1ff4ca

Please sign in to comment.