Code

Changes between Version 9 and Version 10 of PortingNotesFor2To3


Ignore:
Timestamp:
12/25/11 17:09:01 (2 years ago)
Author:
vsajip
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PortingNotesFor2To3

    v9 v10  
    1212  replace `u'foo'` with `u('foo')` and `b'bar'` with `b('bar')` throughout the source. 
    1313  The same applies to the constants with double quotes (`u"foo"` or `b"bar"`, which should be replaced by 
    14   `u("foo")` or `b("bar")` respectively). 
     14  `u("foo")` or `b("bar")` respectively). '''Note:''' this is needed for Python 2.5 compatibility only. For compatibility only with Python 2.6 and later, add `from __future__ import unicode_literals` in all modules where you are using Unicode literals, and remove the `u` prefix from the Unicode literals, as you don't need it. If you need native strings, use `from django.utils.py3 import n` and replace those literals with n(...). This will return str on both 2.x and 3.x. If you need byte strings, use b'foo'. 
    1515 
    1616* If you need to make any code conditional on 2.x vs. 3.x, you can do `from django.utils.py3 import PY3` and use `PY3` 
     
    2525 
    2626* If you see octal constants (such as `0777`), replace them with the hex value (`0x1ff` for the `0777` case), and if 
    27   possible, place the octal constant in a comment so anyone can see what it was originally. 
     27  possible, place the octal constant in a comment so anyone can see what it was originally. '''Note:''' this is only needed for 2.5 compatibility. For 2.6+ compatibility, you can use the 3.x octal form `0o777`. 
     28 
    2829* If you see code of the type `except ExceptionTypeOrTupleOfExceptionTypes, name_to_bind_to:`, see if `name_to _bind_to` 
    2930  is used in the scope (exception handling clause, or later in the same function or method). If not used, just change the 
    3031  `except:` statement to `except ExceptionTypeOrTupleOfExceptionTypes:` and you're done. If used, do one more thing: 
    3132  put the code `name_to_bind_to = sys.exc_info()[1]` just before `name_to_bind_to` is first used, and make sure that 
    32   the `sys` module is imported. 
     33  the `sys` module is imported. '''Note:''' this is only needed for 2.5 compatibility. For 2.6+ compatibility, you can use 
     34  the 3.x form `except ExceptionTypeOrTupleOfExceptionTypes as name_to_bind_to`. Note that in 3.x, names bound like this are 
     35  not in the local scope, and so not visible outside the exception clause. 
    3336 
    3437* If `unicode` occurs in the source (i.e. not in comments), do `from django.utils.py3 import text_type` and replace