Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/docutils/_compat.py @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author | bcclaywell |
---|---|
date | Mon, 12 Oct 2015 17:43:33 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d67268158946 |
---|---|
1 # $Id: _compat.py 7486 2012-07-11 12:25:14Z milde $ | |
2 # Author: Georg Brandl <georg@python.org> | |
3 # Copyright: This module has been placed in the public domain. | |
4 | |
5 """ | |
6 Python 2/3 compatibility definitions. | |
7 | |
8 This module currently provides the following helper symbols: | |
9 | |
10 * bytes (name of byte string type; str in 2.x, bytes in 3.x) | |
11 * b (function converting a string literal to an ASCII byte string; | |
12 can be also used to convert a Unicode string into a byte string) | |
13 * u_prefix (unicode repr prefix: 'u' in 2.x, '' in 3.x) | |
14 (Required in docutils/test/test_publisher.py) | |
15 * BytesIO (a StringIO class that works with bytestrings) | |
16 """ | |
17 | |
18 import sys | |
19 | |
20 if sys.version_info < (3,0): | |
21 b = bytes = str | |
22 u_prefix = 'u' | |
23 from StringIO import StringIO as BytesIO | |
24 else: | |
25 import builtins | |
26 bytes = builtins.bytes | |
27 u_prefix = '' | |
28 def b(s): | |
29 if isinstance(s, str): | |
30 return s.encode('latin1') | |
31 elif isinstance(s, bytes): | |
32 return s | |
33 else: | |
34 raise TypeError("Invalid argument %r for b()" % (s,)) | |
35 # using this hack since 2to3 "fixes" the relative import | |
36 # when using ``from io import BytesIO`` | |
37 BytesIO = __import__('io').BytesIO | |
38 | |
39 if sys.version_info < (2,5): | |
40 import __builtin__ | |
41 | |
42 def __import__(name, globals={}, locals={}, fromlist=[], level=-1): | |
43 """Compatibility definition for Python 2.4. | |
44 | |
45 Silently ignore the `level` argument missing in Python < 2.5. | |
46 """ | |
47 # we need the level arg because the default changed in Python 3.3 | |
48 return __builtin__.__import__(name, globals, locals, fromlist) |