Skip to content
This repository
Browse code

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

  • Loading branch information...
commit c1ff4ca12af20ce584efe40599fc49257987155b 1 parent 1a57315
Armin Ronacher authored

Showing 2 changed files with 24 additions and 1 deletion. Show diff stats Hide diff stats

  1. +14 0 README
  2. +10 1 libmodernize/main.py
14 README
@@ -12,3 +12,17 @@
12 12 compatible codebase. The code that it generates has a runtime
13 13 dependency on `six`.
14 14
  15 + Unicode Literal Control:
  16 +
  17 + - By default modernize will wrap literals with the six helpers.
  18 + This is useful if you want to support Python 3.1 and Python 3.2
  19 + without bigger changes.
  20 + - Alternatively there is the ``--compat-unicode`` flag which
  21 + does not change unicode literals at all which means that you
  22 + can take advantage of PEP 414.
  23 + - The last alternative is the ``--future-unicode`` flag which
  24 + imports the ``unicode_literals`` from the ``__future__`` module.
  25 + This requires Python 2.6 and later and will require that you
  26 + mark bytestrings with ``b''`` and native strings in ``str(b'')``
  27 + or something similar that survives the transformation.
  28 +
11 libmodernize/main.py
@@ -35,6 +35,9 @@ def main(args=None):
35 35 help="Write back modified files")
36 36 parser.add_option("-n", "--nobackups", action="store_true", default=False,
37 37 help="Don't write backups for modified files.")
  38 + parser.add_option("--compat-unicode", action="store_true", default=False,
  39 + help="Leave u'' and b'' prefixes unchanged (requires "
  40 + "Python 3.3 and higher).")
38 41 parser.add_option("--future-unicode", action="store_true", default=False,
39 42 help="Use unicode_strings future_feature instead of the six.u function "
40 43 "(only useful for Python 2.6+).")
@@ -77,10 +80,16 @@ def main(args=None):
77 80
78 81 # Initialize the refactoring tool
79 82 unwanted_fixes = set(options.nofix)
80   - if options.future_unicode:
  83 +
  84 + # Remove unicode fixers depending on command line options
  85 + if options.compat_unicode:
  86 + unwanted_fixes.add('libmodernize.fixes.fix_unicode')
  87 + unwanted_fixes.add('libmodernize.fixes.fix_unicode_future')
  88 + elif options.future_unicode:
81 89 unwanted_fixes.add('libmodernize.fixes.fix_unicode')
82 90 else:
83 91 unwanted_fixes.add('libmodernize.fixes.fix_unicode_future')
  92 +
84 93 if options.no_six:
85 94 unwanted_fixes.update(six_fix_names)
86 95 explicit = set()

0 comments on commit c1ff4ca

Please sign in to comment.
Something went wrong with that request. Please try again.