1Six: Python 2 and 3 Compatibility Library 2========================================= 3 4.. module:: six 5 :synopsis: Python 2 and 3 compatibility 6 7.. moduleauthor:: Benjamin Peterson <benjamin@python.org> 8.. sectionauthor:: Benjamin Peterson <benjamin@python.org> 9 10 11Six provides simple utilities for wrapping over differences between Python 2 and 12Python 3. It is intended to support codebases that work on both Python 2 and 3 13without modification. six consists of only one Python file, so it is painless 14to copy into a project. 15 16Six can be downloaded on `PyPi <http://pypi.python.org/pypi/six/>`_. Its bug 17tracker and code hosting is on `BitBucket <http://bitbucket.org/gutworth/six>`_. 18 19The name, "six", comes from the fact that 2*3 equals 6. Why not addition? 20Multiplication is more powerful, and, anyway, "five" has already been snatched 21away by the (admittedly now moribund) Zope Five project. 22 23 24Indices and tables 25------------------ 26 27* :ref:`genindex` 28* :ref:`search` 29 30 31Package contents 32---------------- 33 34.. data:: PY2 35 36 A boolean indicating if the code is running on Python 2. 37 38.. data:: PY3 39 40 A boolean indicating if the code is running on Python 3. 41 42 43Constants 44>>>>>>>>> 45 46Six provides constants that may differ between Python versions. Ones ending 47``_types`` are mostly useful as the second argument to ``isinstance`` or 48``issubclass``. 49 50 51.. data:: class_types 52 53 Possible class types. In Python 2, this encompasses old-style and new-style 54 classes. In Python 3, this is just new-styles. 55 56 57.. data:: integer_types 58 59 Possible integer types. In Python 2, this is :func:`py2:long` and 60 :func:`py2:int`, and in Python 3, just :func:`py3:int`. 61 62 63.. data:: string_types 64 65 Possible types for text data. This is :func:`py2:basestring` in Python 2 and 66 :func:`py3:str` in Python 3. 67 68 69.. data:: text_type 70 71 Type for representing (Unicode) textual data. This is :func:`py2:unicode` in 72 Python 2 and :func:`py3:str` in Python 3. 73 74 75.. data:: binary_type 76 77 Type for representing binary data. This is :func:`py2:str` in Python 2 and 78 :func:`py3:bytes` in Python 3. 79 80 81.. data:: MAXSIZE 82 83 The maximum size of a container like :func:`py3:list` or :func:`py3:dict`. 84 This is equivalent to :data:`py3:sys.maxsize` in Python 2.6 and later 85 (including 3.x). Note, this is temptingly similar to, but not the same as 86 :data:`py2:sys.maxint` in Python 2. There is no direct equivalent to 87 :data:`py2:sys.maxint` in Python 3 because its integer type has no limits 88 aside from memory. 89 90 91Here's example usage of the module:: 92 93 import six 94 95 def dispatch_types(value): 96 if isinstance(value, six.integer_types): 97 handle_integer(value) 98 elif isinstance(value, six.class_types): 99 handle_class(value) 100 elif isinstance(value, six.string_types): 101 handle_string(value) 102 103 104Object model compatibility 105>>>>>>>>>>>>>>>>>>>>>>>>>> 106 107Python 3 renamed the attributes of several intepreter data structures. The 108following accessors are available. Note that the recommended way to inspect 109functions and methods is the stdlib :mod:`py3:inspect` module. 110 111 112.. function:: get_unbound_function(meth) 113 114 Get the function out of unbound method *meth*. In Python 3, unbound methods 115 don't exist, so this function just returns *meth* unchanged. Example 116 usage:: 117 118 from six import get_unbound_function 119 120 class X(object): 121 def method(self): 122 pass 123 method_function = get_unbound_function(X.method) 124 125 126.. function:: get_method_function(meth) 127 128 Get the function out of method object *meth*. 129 130 131.. function:: get_method_self(meth) 132 133 Get the ``self`` of bound method *meth*. 134 135 136.. function:: get_function_closure(func) 137 138 Get the closure (list of cells) associated with *func*. This is equivalent 139 to ``func.__closure__`` on Python 2.6+ and ``func.func_closure`` on Python 140 2.5. 141 142 143.. function:: get_function_code(func) 144 145 Get the code object associated with *func*. This is equivalent to 146 ``func.__code__`` on Python 2.6+ and ``func.func_code`` on Python 2.5. 147 148 149.. function:: get_function_defaults(func) 150 151 Get the defaults tuple associated with *func*. This is equivalent to 152 ``func.__defaults__`` on Python 2.6+ and ``func.func_defaults`` on Python 153 2.5. 154 155 156.. function:: get_function_globals(func) 157 158 Get the globals of *func*. This is equivalent to ``func.__globals__`` on 159 Python 2.6+ and ``func.func_globals`` on Python 2.5. 160 161 162.. function:: next(it) 163 advance_iterator(it) 164 165 Get the next item of iterator *it*. :exc:`py3:StopIteration` is raised if 166 the iterator is exhausted. This is a replacement for calling ``it.next()`` 167 in Python 2 and ``next(it)`` in Python 3. 168 169 170.. function:: callable(obj) 171 172 Check if *obj* can be called. Note ``callable`` has returned in Python 3.2, 173 so using six's version is only necessary when supporting Python 3.0 or 3.1. 174 175 176.. function:: iterkeys(dictionary, **kwargs) 177 178 Returns an iterator over *dictionary*\'s keys. This replaces 179 ``dictionary.iterkeys()`` on Python 2 and ``dictionary.keys()`` on 180 Python 3. *kwargs* are passed through to the underlying method. 181 182 183.. function:: itervalues(dictionary, **kwargs) 184 185 Returns an iterator over *dictionary*\'s values. This replaces 186 ``dictionary.itervalues()`` on Python 2 and ``dictionary.values()`` on 187 Python 3. *kwargs* are passed through to the underlying method. 188 189 190.. function:: iteritems(dictionary, **kwargs) 191 192 Returns an iterator over *dictionary*\'s items. This replaces 193 ``dictionary.iteritems()`` on Python 2 and ``dictionary.items()`` on 194 Python 3. *kwargs* are passed through to the underlying method. 195 196 197.. function:: iterlists(dictionary, **kwargs) 198 199 Calls ``dictionary.iterlists()`` on Python 2 and ``dictionary.lists()`` on 200 Python 3. No builtin Python mapping type has such a method; this method is 201 intended for use with multi-valued dictionaries like `Werkzeug's 202 <http://werkzeug.pocoo.org/docs/datastructures/#werkzeug.datastructures.MultiDict>`_. 203 *kwargs* are passed through to the underlying method. 204 205 206.. function:: viewkeys(dictionary) 207 208 Return a view over *dictionary*\'s keys. This replaces 209 :meth:`py2:dict.viewkeys` on Python 2.7 and :meth:`py3:dict.keys` on 210 Python 3. 211 212 213.. function:: viewvalues(dictionary) 214 215 Return a view over *dictionary*\'s values. This replaces 216 :meth:`py2:dict.viewvalues` on Python 2.7 and :meth:`py3:dict.values` on 217 Python 3. 218 219 220.. function:: viewitems(dictionary) 221 222 Return a view over *dictionary*\'s items. This replaces 223 :meth:`py2:dict.viewitems` on Python 2.7 and :meth:`py3:dict.items` on 224 Python 3. 225 226 227.. function:: create_bound_method(func, obj) 228 229 Return a method object wrapping *func* and bound to *obj*. On both Python 2 230 and 3, this will return a :func:`py3:types.MethodType` object. The reason 231 this wrapper exists is that on Python 2, the ``MethodType`` constructor 232 requires the *obj*'s class to be passed. 233 234 235.. class:: Iterator 236 237 A class for making portable iterators. The intention is that it be subclassed 238 and subclasses provide a ``__next__`` method. In Python 2, :class:`Iterator` 239 has one method: ``next``. It simply delegates to ``__next__``. An alternate 240 way to do this would be to simply alias ``next`` to ``__next__``. However, 241 this interacts badly with subclasses that override 242 ``__next__``. :class:`Iterator` is empty on Python 3. (In fact, it is just 243 aliased to :class:`py3:object`.) 244 245 246.. decorator:: wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS, updated=functools.WRAPPER_UPDATES) 247 248 This is exactly the :func:`py3:functools.wraps` decorator, but it sets the 249 ``__wrapped__`` attribute on what it decorates as :func:`py3:functools.wraps` 250 does on Python versions after 3.2. 251 252 253Syntax compatibility 254>>>>>>>>>>>>>>>>>>>> 255 256These functions smooth over operations which have different syntaxes between 257Python 2 and 3. 258 259 260.. function:: exec_(code, globals=None, locals=None) 261 262 Execute *code* in the scope of *globals* and *locals*. *code* can be a 263 string or a code object. If *globals* or *locals* are not given, they will 264 default to the scope of the caller. If just *globals* is given, it will also 265 be used as *locals*. 266 267 .. note:: 268 269 Python 3's :func:`py3:exec` doesn't take keyword arguments, so calling 270 :func:`exec` with them should be avoided. 271 272 273.. function:: print_(*args, *, file=sys.stdout, end="\\n", sep=" ", flush=False) 274 275 Print *args* into *file*. Each argument will be separated with *sep* and 276 *end* will be written to the file after the last argument is printed. If 277 *flush* is true, ``file.flush()`` will be called after all data is written. 278 279 .. note:: 280 281 In Python 2, this function imitates Python 3's :func:`py3:print` by not 282 having softspace support. If you don't know what that is, you're probably 283 ok. :) 284 285 286.. function:: raise_from(exc_value, exc_value_from) 287 288 Raise an exception from a context. On Python 3, this is equivalent to 289 ``raise exc_value from exc_value_from``. On Python 2, which does not support 290 exception chaining, it is equivalent to ``raise exc_value``. 291 292 293.. function:: reraise(exc_type, exc_value, exc_traceback=None) 294 295 Reraise an exception, possibly with a different traceback. In the simple 296 case, ``reraise(*sys.exc_info())`` with an active exception (in an except 297 block) reraises the current exception with the last traceback. A different 298 traceback can be specified with the *exc_traceback* parameter. Note that 299 since the exception reraising is done within the :func:`reraise` function, 300 Python will attach the call frame of :func:`reraise` to whatever traceback is 301 raised. 302 303 304.. function:: with_metaclass(metaclass, *bases) 305 306 Create a new class with base classes *bases* and metaclass *metaclass*. This 307 is designed to be used in class declarations like this: :: 308 309 from six import with_metaclass 310 311 class Meta(type): 312 pass 313 314 class Base(object): 315 pass 316 317 class MyClass(with_metaclass(Meta, Base)): 318 pass 319 320 Another way to set a metaclass on a class is with the :func:`add_metaclass` 321 decorator. 322 323 324.. decorator:: add_metaclass(metaclass) 325 326 Class decorator that replaces a normally-constructed class with a 327 metaclass-constructed one. Example usage: :: 328 329 @add_metaclass(Meta) 330 class MyClass(object): 331 pass 332 333 That code produces a class equivalent to :: 334 335 class MyClass(object, metaclass=Meta): 336 pass 337 338 on Python 3 or :: 339 340 class MyClass(object): 341 __metaclass__ = MyMeta 342 343 on Python 2. 344 345 Note that class decorators require Python 2.6. However, the effect of the 346 decorator can be emulated on Python 2.5 like so:: 347 348 class MyClass(object): 349 pass 350 MyClass = add_metaclass(Meta)(MyClass) 351 352 353Binary and text data 354>>>>>>>>>>>>>>>>>>>> 355 356Python 3 enforces the distinction between byte strings and text strings far more 357rigoriously than Python 2 does; binary data cannot be automatically coerced to 358or from text data. six provides several functions to assist in classifying 359string data in all Python versions. 360 361 362.. function:: b(data) 363 364 A "fake" bytes literal. *data* should always be a normal string literal. In 365 Python 2, :func:`b` returns a 8-bit string. In Python 3, *data* is encoded 366 with the latin-1 encoding to bytes. 367 368 369 .. note:: 370 371 Since all Python versions 2.6 and after support the ``b`` prefix, 372 :func:`b`, code without 2.5 support doesn't need :func:`b`. 373 374 375.. function:: u(text) 376 377 A "fake" unicode literal. *text* should always be a normal string literal. 378 In Python 2, :func:`u` returns unicode, and in Python 3, a string. Also, in 379 Python 2, the string is decoded with the ``unicode-escape`` codec, which 380 allows unicode escapes to be used in it. 381 382 383 .. note:: 384 385 In Python 3.3, the ``u`` prefix has been reintroduced. Code that only 386 supports Python 3 versions greater than 3.3 thus does not need 387 :func:`u`. 388 389 .. note:: 390 391 On Python 2, :func:`u` doesn't know what the encoding of the literal 392 is. Each byte is converted directly to the unicode codepoint of the same 393 value. Because of this, it's only safe to use :func:`u` with strings of 394 ASCII data. 395 396 397.. function:: unichr(c) 398 399 Return the (Unicode) string representing the codepoint *c*. This is 400 equivalent to :func:`py2:unichr` on Python 2 and :func:`py3:chr` on Python 3. 401 402 403.. function:: int2byte(i) 404 405 Converts *i* to a byte. *i* must be in ``range(0, 256)``. This is 406 equivalent to :func:`py2:chr` in Python 2 and ``bytes((i,))`` in Python 3. 407 408 409.. function:: byte2int(bs) 410 411 Converts the first byte of *bs* to an integer. This is equivalent to 412 ``ord(bs[0])`` on Python 2 and ``bs[0]`` on Python 3. 413 414 415.. function:: indexbytes(buf, i) 416 417 Return the byte at index *i* of *buf* as an integer. This is equivalent to 418 indexing a bytes object in Python 3. 419 420 421.. function:: iterbytes(buf) 422 423 Return an iterator over bytes in *buf* as integers. This is equivalent to 424 a bytes object iterator in Python 3. 425 426 427.. data:: StringIO 428 429 This is an fake file object for textual data. It's an alias for 430 :class:`py2:StringIO.StringIO` in Python 2 and :class:`py3:io.StringIO` in 431 Python 3. 432 433 434.. data:: BytesIO 435 436 This is a fake file object for binary data. In Python 2, it's an alias for 437 :class:`py2:StringIO.StringIO`, but in Python 3, it's an alias for 438 :class:`py3:io.BytesIO`. 439 440 441.. decorator:: python_2_unicode_compatible 442 443 A class decorator that takes a class defining a ``__str__`` method. On 444 Python 3, the decorator does nothing. On Python 2, it aliases the 445 ``__str__`` method to ``__unicode__`` and creates a new ``__str__`` method 446 that returns the result of ``__unicode__()`` encoded with UTF-8. 447 448 449unittest assertions 450>>>>>>>>>>>>>>>>>>> 451 452Six contains compatibility shims for unittest assertions that have been renamed. 453The parameters are the same as their aliases, but you must pass the test method 454as the first argument. For example:: 455 456 import six 457 import unittest 458 459 class TestAssertCountEqual(unittest.TestCase): 460 def test(self): 461 six.assertCountEqual(self, (1, 2), [2, 1]) 462 463Note these functions are only available on Python 2.7 or later. 464 465.. function:: assertCountEqual() 466 467 Alias for :meth:`~py3:unittest.TestCase.assertCountEqual` on Python 3 and 468 :meth:`~py2:unittest.TestCase.assertItemsEqual` on Python 2. 469 470 471.. function:: assertRaisesRegex() 472 473 Alias for :meth:`~py3:unittest.TestCase.assertRaisesRegex` on Python 3 and 474 :meth:`~py2:unittest.TestCase.assertRaisesRegexp` on Python 2. 475 476 477.. function:: assertRegex() 478 479 Alias for :meth:`~py3:unittest.TestCase.assertRegex` on Python 3 and 480 :meth:`~py2:unittest.TestCase.assertRegexpMatches` on Python 2. 481 482 483Renamed modules and attributes compatibility 484>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 485 486.. module:: six.moves 487 :synopsis: Renamed modules and attributes compatibility 488 489Python 3 reorganized the standard library and moved several functions to 490different modules. Six provides a consistent interface to them through the fake 491:mod:`six.moves` module. For example, to load the module for parsing HTML on 492Python 2 or 3, write:: 493 494 from six.moves import html_parser 495 496Similarly, to get the function to reload modules, which was moved from the 497builtin module to the ``imp`` module, use:: 498 499 from six.moves import reload_module 500 501For the most part, :mod:`six.moves` aliases are the names of the modules in 502Python 3. When the new Python 3 name is a package, the components of the name 503are separated by underscores. For example, ``html.parser`` becomes 504``html_parser``. In some cases where several modules have been combined, the 505Python 2 name is retained. This is so the appropiate modules can be found when 506running on Python 2. For example, ``BaseHTTPServer`` which is in 507``http.server`` in Python 3 is aliased as ``BaseHTTPServer``. 508 509Some modules which had two implementations have been merged in Python 3. For 510example, ``cPickle`` no longer exists in Python 3; it was merged with 511``pickle``. In these cases, fetching the fast version will load the fast one on 512Python 2 and the merged module in Python 3. 513 514The :mod:`py2:urllib`, :mod:`py2:urllib2`, and :mod:`py2:urlparse` modules have 515been combined in the :mod:`py3:urllib` package in Python 3. The 516:mod:`six.moves.urllib` package is a version-independent location for this 517functionality; its structure mimics the structure of the Python 3 518:mod:`py3:urllib` package. 519 520.. note:: 521 522 In order to make imports of the form:: 523 524 from six.moves.cPickle import loads 525 526 work, six places special proxy objects in in :data:`py3:sys.modules`. These 527 proxies lazily load the underlying module when an attribute is fetched. This 528 will fail if the underlying module is not available in the Python 529 interpreter. For example, ``sys.modules["six.moves.winreg"].LoadKey`` would 530 fail on any non-Windows platform. Unfortunately, some applications try to 531 load attributes on every module in :data:`py3:sys.modules`. six mitigates 532 this problem for some applications by pretending attributes on unimportable 533 modules don't exist. This hack doesn't work in every case, though. If you are 534 encountering problems with the lazy modules and don't use any from imports 535 directly from ``six.moves`` modules, you can workaround the issue by removing 536 the six proxy modules:: 537 538 d = [name for name in sys.modules if name.startswith("six.moves.")] 539 for name in d: 540 del sys.modules[name] 541 542Supported renames: 543 544+------------------------------+-------------------------------------+-------------------------------------+ 545| Name | Python 2 name | Python 3 name | 546+==============================+=====================================+=====================================+ 547| ``builtins`` | :mod:`py2:__builtin__` | :mod:`py3:builtins` | 548+------------------------------+-------------------------------------+-------------------------------------+ 549| ``configparser`` | :mod:`py2:ConfigParser` | :mod:`py3:configparser` | 550+------------------------------+-------------------------------------+-------------------------------------+ 551| ``copyreg`` | :mod:`py2:copy_reg` | :mod:`py3:copyreg` | 552+------------------------------+-------------------------------------+-------------------------------------+ 553| ``cPickle`` | :mod:`py2:cPickle` | :mod:`py3:pickle` | 554+------------------------------+-------------------------------------+-------------------------------------+ 555| ``cStringIO`` | :func:`py2:cStringIO.StringIO` | :class:`py3:io.StringIO` | 556+------------------------------+-------------------------------------+-------------------------------------+ 557| ``dbm_gnu`` | :func:`py2:gdbm` | :class:`py3:dbm.gnu` | 558+------------------------------+-------------------------------------+-------------------------------------+ 559| ``_dummy_thread`` | :mod:`py2:dummy_thread` | :mod:`py3:_dummy_thread` | 560+------------------------------+-------------------------------------+-------------------------------------+ 561| ``email_mime_multipart`` | :mod:`py2:email.MIMEMultipart` | :mod:`py3:email.mime.multipart` | 562+------------------------------+-------------------------------------+-------------------------------------+ 563| ``email_mime_nonmultipart`` | :mod:`py2:email.MIMENonMultipart` | :mod:`py3:email.mime.nonmultipart` | 564+------------------------------+-------------------------------------+-------------------------------------+ 565| ``email_mime_text`` | :mod:`py2:email.MIMEText` | :mod:`py3:email.mime.text` | 566+------------------------------+-------------------------------------+-------------------------------------+ 567| ``email_mime_base`` | :mod:`py2:email.MIMEBase` | :mod:`py3:email.mime.base` | 568+------------------------------+-------------------------------------+-------------------------------------+ 569| ``filter`` | :func:`py2:itertools.ifilter` | :func:`py3:filter` | 570+------------------------------+-------------------------------------+-------------------------------------+ 571| ``filterfalse`` | :func:`py2:itertools.ifilterfalse` | :func:`py3:itertools.filterfalse` | 572+------------------------------+-------------------------------------+-------------------------------------+ 573| ``http_cookiejar`` | :mod:`py2:cookielib` | :mod:`py3:http.cookiejar` | 574+------------------------------+-------------------------------------+-------------------------------------+ 575| ``http_cookies`` | :mod:`py2:Cookie` | :mod:`py3:http.cookies` | 576+------------------------------+-------------------------------------+-------------------------------------+ 577| ``html_entities`` | :mod:`py2:htmlentitydefs` | :mod:`py3:html.entities` | 578+------------------------------+-------------------------------------+-------------------------------------+ 579| ``html_parser`` | :mod:`py2:HTMLParser` | :mod:`py3:html.parser` | 580+------------------------------+-------------------------------------+-------------------------------------+ 581| ``http_client`` | :mod:`py2:httplib` | :mod:`py3:http.client` | 582+------------------------------+-------------------------------------+-------------------------------------+ 583| ``BaseHTTPServer`` | :mod:`py2:BaseHTTPServer` | :mod:`py3:http.server` | 584+------------------------------+-------------------------------------+-------------------------------------+ 585| ``CGIHTTPServer`` | :mod:`py2:CGIHTTPServer` | :mod:`py3:http.server` | 586+------------------------------+-------------------------------------+-------------------------------------+ 587| ``SimpleHTTPServer`` | :mod:`py2:SimpleHTTPServer` | :mod:`py3:http.server` | 588+------------------------------+-------------------------------------+-------------------------------------+ 589| ``input`` | :func:`py2:raw_input` | :func:`py3:input` | 590+------------------------------+-------------------------------------+-------------------------------------+ 591| ``intern`` | :func:`py2:intern` | :func:`py3:sys.intern` | 592+------------------------------+-------------------------------------+-------------------------------------+ 593| ``map`` | :func:`py2:itertools.imap` | :func:`py3:map` | 594+------------------------------+-------------------------------------+-------------------------------------+ 595| ``queue`` | :mod:`py2:Queue` | :mod:`py3:queue` | 596+------------------------------+-------------------------------------+-------------------------------------+ 597| ``range`` | :func:`py2:xrange` | :func:`py3:range` | 598+------------------------------+-------------------------------------+-------------------------------------+ 599| ``reduce`` | :func:`py2:reduce` | :func:`py3:functools.reduce` | 600+------------------------------+-------------------------------------+-------------------------------------+ 601| ``reload_module`` | :func:`py2:reload` | :func:`py3:imp.reload` | 602+------------------------------+-------------------------------------+-------------------------------------+ 603| ``reprlib`` | :mod:`py2:repr` | :mod:`py3:reprlib` | 604+------------------------------+-------------------------------------+-------------------------------------+ 605| ``shlex_quote`` | :mod:`py2:pipes.quote` | :mod:`py3:shlex.quote` | 606+------------------------------+-------------------------------------+-------------------------------------+ 607| ``socketserver`` | :mod:`py2:SocketServer` | :mod:`py3:socketserver` | 608+------------------------------+-------------------------------------+-------------------------------------+ 609| ``_thread`` | :mod:`py2:thread` | :mod:`py3:_thread` | 610+------------------------------+-------------------------------------+-------------------------------------+ 611| ``tkinter`` | :mod:`py2:Tkinter` | :mod:`py3:tkinter` | 612+------------------------------+-------------------------------------+-------------------------------------+ 613| ``tkinter_dialog`` | :mod:`py2:Dialog` | :mod:`py3:tkinter.dialog` | 614+------------------------------+-------------------------------------+-------------------------------------+ 615| ``tkinter_filedialog`` | :mod:`py2:FileDialog` | :mod:`py3:tkinter.FileDialog` | 616+------------------------------+-------------------------------------+-------------------------------------+ 617| ``tkinter_scrolledtext`` | :mod:`py2:ScrolledText` | :mod:`py3:tkinter.scrolledtext` | 618+------------------------------+-------------------------------------+-------------------------------------+ 619| ``tkinter_simpledialog`` | :mod:`py2:SimpleDialog` | :mod:`py3:tkinter.simpledialog` | 620+------------------------------+-------------------------------------+-------------------------------------+ 621| ``tkinter_ttk`` | :mod:`py2:ttk` | :mod:`py3:tkinter.ttk` | 622+------------------------------+-------------------------------------+-------------------------------------+ 623| ``tkinter_tix`` | :mod:`py2:Tix` | :mod:`py3:tkinter.tix` | 624+------------------------------+-------------------------------------+-------------------------------------+ 625| ``tkinter_constants`` | :mod:`py2:Tkconstants` | :mod:`py3:tkinter.constants` | 626+------------------------------+-------------------------------------+-------------------------------------+ 627| ``tkinter_dnd`` | :mod:`py2:Tkdnd` | :mod:`py3:tkinter.dnd` | 628+------------------------------+-------------------------------------+-------------------------------------+ 629| ``tkinter_colorchooser`` | :mod:`py2:tkColorChooser` | :mod:`py3:tkinter.colorchooser` | 630+------------------------------+-------------------------------------+-------------------------------------+ 631| ``tkinter_commondialog`` | :mod:`py2:tkCommonDialog` | :mod:`py3:tkinter.commondialog` | 632+------------------------------+-------------------------------------+-------------------------------------+ 633| ``tkinter_tkfiledialog`` | :mod:`py2:tkFileDialog` | :mod:`py3:tkinter.filedialog` | 634+------------------------------+-------------------------------------+-------------------------------------+ 635| ``tkinter_font`` | :mod:`py2:tkFont` | :mod:`py3:tkinter.font` | 636+------------------------------+-------------------------------------+-------------------------------------+ 637| ``tkinter_messagebox`` | :mod:`py2:tkMessageBox` | :mod:`py3:tkinter.messagebox` | 638+------------------------------+-------------------------------------+-------------------------------------+ 639| ``tkinter_tksimpledialog`` | :mod:`py2:tkSimpleDialog` | :mod:`py3:tkinter.simpledialog` | 640+------------------------------+-------------------------------------+-------------------------------------+ 641| ``urllib.parse`` | See :mod:`six.moves.urllib.parse` | :mod:`py3:urllib.parse` | 642+------------------------------+-------------------------------------+-------------------------------------+ 643| ``urllib.error`` | See :mod:`six.moves.urllib.error` | :mod:`py3:urllib.error` | 644+------------------------------+-------------------------------------+-------------------------------------+ 645| ``urllib.request`` | See :mod:`six.moves.urllib.request` | :mod:`py3:urllib.request` | 646+------------------------------+-------------------------------------+-------------------------------------+ 647| ``urllib.response`` | See :mod:`six.moves.urllib.response`| :mod:`py3:urllib.response` | 648+------------------------------+-------------------------------------+-------------------------------------+ 649| ``urllib.robotparser`` | :mod:`py2:robotparser` | :mod:`py3:urllib.robotparser` | 650+------------------------------+-------------------------------------+-------------------------------------+ 651| ``urllib_robotparser`` | :mod:`py2:robotparser` | :mod:`py3:urllib.robotparser` | 652+------------------------------+-------------------------------------+-------------------------------------+ 653| ``UserDict`` | :class:`py2:UserDict.UserDict` | :class:`py3:collections.UserDict` | 654+------------------------------+-------------------------------------+-------------------------------------+ 655| ``UserList`` | :class:`py2:UserList.UserList` | :class:`py3:collections.UserList` | 656+------------------------------+-------------------------------------+-------------------------------------+ 657| ``UserString`` | :class:`py2:UserString.UserString` | :class:`py3:collections.UserString` | 658+------------------------------+-------------------------------------+-------------------------------------+ 659| ``winreg`` | :mod:`py2:_winreg` | :mod:`py3:winreg` | 660+------------------------------+-------------------------------------+-------------------------------------+ 661| ``xmlrpc_client`` | :mod:`py2:xmlrpclib` | :mod:`py3:xmlrpc.client` | 662+------------------------------+-------------------------------------+-------------------------------------+ 663| ``xmlrpc_server`` | :mod:`py2:SimpleXMLRPCServer` | :mod:`py3:xmlrpc.server` | 664+------------------------------+-------------------------------------+-------------------------------------+ 665| ``xrange`` | :func:`py2:xrange` | :func:`py3:range` | 666+------------------------------+-------------------------------------+-------------------------------------+ 667| ``zip`` | :func:`py2:itertools.izip` | :func:`py3:zip` | 668+------------------------------+-------------------------------------+-------------------------------------+ 669| ``zip_longest`` | :func:`py2:itertools.izip_longest` | :func:`py3:itertools.zip_longest` | 670+------------------------------+-------------------------------------+-------------------------------------+ 671 672urllib parse 673<<<<<<<<<<<< 674 675.. module:: six.moves.urllib.parse 676 :synopsis: Stuff from :mod:`py2:urlparse` and :mod:`py2:urllib` in Python 2 and :mod:`py3:urllib.parse` in Python 3 677 678Contains functions from Python 3's :mod:`py3:urllib.parse` and Python 2's: 679 680:mod:`py2:urlparse`: 681 682* :func:`py2:urlparse.ParseResult` 683* :func:`py2:urlparse.SplitResult` 684* :func:`py2:urlparse.urlparse` 685* :func:`py2:urlparse.urlunparse` 686* :func:`py2:urlparse.parse_qs` 687* :func:`py2:urlparse.parse_qsl` 688* :func:`py2:urlparse.urljoin` 689* :func:`py2:urlparse.urldefrag` 690* :func:`py2:urlparse.urlsplit` 691* :func:`py2:urlparse.urlunsplit` 692* :func:`py2:urlparse.splitquery` 693* :func:`py2:urlparse.uses_fragment` 694* :func:`py2:urlparse.uses_netloc` 695* :func:`py2:urlparse.uses_params` 696* :func:`py2:urlparse.uses_query` 697* :func:`py2:urlparse.uses_relative` 698 699and :mod:`py2:urllib`: 700 701* :func:`py2:urllib.quote` 702* :func:`py2:urllib.quote_plus` 703* :func:`py2:urllib.splittag` 704* :func:`py2:urllib.splituser` 705* :func:`py2:urllib.unquote` 706* :func:`py2:urllib.unquote_plus` 707* :func:`py2:urllib.urlencode` 708 709 710urllib error 711<<<<<<<<<<<< 712 713.. module:: six.moves.urllib.error 714 :synopsis: Stuff from :mod:`py2:urllib` and :mod:`py2:urllib2` in Python 2 and :mod:`py3:urllib.error` in Python 3 715 716Contains exceptions from Python 3's :mod:`py3:urllib.error` and Python 2's: 717 718:mod:`py2:urllib`: 719 720* :exc:`py2:urllib.ContentTooShortError` 721 722and :mod:`py2:urllib2`: 723 724* :exc:`py2:urllib2.URLError` 725* :exc:`py2:urllib2.HTTPError` 726 727 728urllib request 729<<<<<<<<<<<<<< 730 731.. module:: six.moves.urllib.request 732 :synopsis: Stuff from :mod:`py2:urllib` and :mod:`py2:urllib2` in Python 2 and :mod:`py3:urllib.request` in Python 3 733 734Contains items from Python 3's :mod:`py3:urllib.request` and Python 2's: 735 736:mod:`py2:urllib`: 737 738* :func:`py2:urllib.pathname2url` 739* :func:`py2:urllib.url2pathname` 740* :func:`py2:urllib.getproxies` 741* :func:`py2:urllib.urlretrieve` 742* :func:`py2:urllib.urlcleanup` 743* :class:`py2:urllib.URLopener` 744* :class:`py2:urllib.FancyURLopener` 745* :func:`py2:urllib.proxy_bypass` 746 747and :mod:`py2:urllib2`: 748 749* :func:`py2:urllib2.urlopen` 750* :func:`py2:urllib2.install_opener` 751* :func:`py2:urllib2.build_opener` 752* :class:`py2:urllib2.Request` 753* :class:`py2:urllib2.OpenerDirector` 754* :class:`py2:urllib2.HTTPDefaultErrorHandler` 755* :class:`py2:urllib2.HTTPRedirectHandler` 756* :class:`py2:urllib2.HTTPCookieProcessor` 757* :class:`py2:urllib2.ProxyHandler` 758* :class:`py2:urllib2.BaseHandler` 759* :class:`py2:urllib2.HTTPPasswordMgr` 760* :class:`py2:urllib2.HTTPPasswordMgrWithDefaultRealm` 761* :class:`py2:urllib2.AbstractBasicAuthHandler` 762* :class:`py2:urllib2.HTTPBasicAuthHandler` 763* :class:`py2:urllib2.ProxyBasicAuthHandler` 764* :class:`py2:urllib2.AbstractDigestAuthHandler` 765* :class:`py2:urllib2.HTTPDigestAuthHandler` 766* :class:`py2:urllib2.ProxyDigestAuthHandler` 767* :class:`py2:urllib2.HTTPHandler` 768* :class:`py2:urllib2.HTTPSHandler` 769* :class:`py2:urllib2.FileHandler` 770* :class:`py2:urllib2.FTPHandler` 771* :class:`py2:urllib2.CacheFTPHandler` 772* :class:`py2:urllib2.UnknownHandler` 773* :class:`py2:urllib2.HTTPErrorProcessor` 774 775 776urllib response 777<<<<<<<<<<<<<<< 778 779.. module:: six.moves.urllib.response 780 :synopsis: Stuff from :mod:`py2:urllib` in Python 2 and :mod:`py3:urllib.response` in Python 3 781 782Contains classes from Python 3's :mod:`py3:urllib.response` and Python 2's: 783 784:mod:`py2:urllib`: 785 786* :class:`py2:urllib.addbase` 787* :class:`py2:urllib.addclosehook` 788* :class:`py2:urllib.addinfo` 789* :class:`py2:urllib.addinfourl` 790 791 792Advanced - Customizing renames 793<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 794 795.. currentmodule:: six 796 797It is possible to add additional names to the :mod:`six.moves` namespace. 798 799 800.. function:: add_move(item) 801 802 Add *item* to the :mod:`six.moves` mapping. *item* should be a 803 :class:`MovedAttribute` or :class:`MovedModule` instance. 804 805 806.. function:: remove_move(name) 807 808 Remove the :mod:`six.moves` mapping called *name*. *name* should be a 809 string. 810 811 812Instances of the following classes can be passed to :func:`add_move`. Neither 813have any public members. 814 815 816.. class:: MovedModule(name, old_mod, new_mod) 817 818 Create a mapping for :mod:`six.moves` called *name* that references different 819 modules in Python 2 and 3. *old_mod* is the name of the Python 2 module. 820 *new_mod* is the name of the Python 3 module. 821 822 823.. class:: MovedAttribute(name, old_mod, new_mod, old_attr=None, new_attr=None) 824 825 Create a mapping for :mod:`six.moves` called *name* that references different 826 attributes in Python 2 and 3. *old_mod* is the name of the Python 2 module. 827 *new_mod* is the name of the Python 3 module. If *new_attr* is not given, it 828 defaults to *old_attr*. If neither is given, they both default to *name*. 829