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