Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 125 lines (103 sloc) 3.055 kB
680b5df @vsajip Port to Python3
vsajip authored
1 """Stuff that differs in different Python versions"""
493407a @ianb factor out any()
ianb authored
2
c7129ea @hltbra fixed python2.4 backwards compatibility
hltbra authored
3 import sys
4 import os
5 import shutil
6
e91f167 @jezdez Moved pkgutil to its own file to keep the backwardcompat module a lit…
jezdez authored
7 __all__ = ['any', 'WindowsError', 'md5', 'copytree']
3e0f8fb @ianb Move all things pyflakes complains about into backwardcompat; extract…
ianb authored
8
9 try:
03ff9fa @jezdez Fixed #53 - Fixed backwards compat import error on Windows
jezdez authored
10 WindowsError = WindowsError
3e0f8fb @ianb Move all things pyflakes complains about into backwardcompat; extract…
ianb authored
11 except NameError:
680b5df @vsajip Port to Python3
vsajip authored
12 class NeverUsedException(Exception):
13 """this exception should never be raised"""
14 WindowsError = NeverUsedException
3e0f8fb @ianb Move all things pyflakes complains about into backwardcompat; extract…
ianb authored
15 try:
16 from hashlib import md5
17 except ImportError:
18 import md5 as md5_module
19 md5 = md5_module.new
493407a @ianb factor out any()
ianb authored
20
21 try:
e91f167 @jezdez Moved pkgutil to its own file to keep the backwardcompat module a lit…
jezdez authored
22 from pkgutil import walk_packages
23 except ImportError:
24 # let's fall back as long as we can
680b5df @vsajip Port to Python3
vsajip authored
25 from pip._pkgutil import walk_packages
e91f167 @jezdez Moved pkgutil to its own file to keep the backwardcompat module a lit…
jezdez authored
26
27 try:
77517e0 @ianb Python 2.6 requires any=any to make the name importable
ianb authored
28 any = any
493407a @ianb factor out any()
ianb authored
29 except NameError:
ac2bfb5 @jezdez Fixed minor cosmetic issues to please pep8 tests.
jezdez authored
30
493407a @ianb factor out any()
ianb authored
31 def any(seq):
32 for item in seq:
33 if item:
34 return True
35 return False
c7129ea @hltbra fixed python2.4 backwards compatibility
hltbra authored
36
1fdbce0 Use the detected console encoding instead of utf-8 for decoding
Alex Grönholm authored
37 console_encoding = sys.__stdout__.encoding
38
680b5df @vsajip Port to Python3
vsajip authored
39 if sys.version_info >= (3,):
e33be61 @pnasrat Fix #297 adding deflate and gzip handling
pnasrat authored
40 from io import StringIO, BytesIO
680b5df @vsajip Port to Python3
vsajip authored
41 from functools import reduce
42 from urllib.error import URLError, HTTPError
43 from queue import Queue, Empty
44 from urllib.request import url2pathname
45 from urllib.request import urlretrieve
46 from email import message as emailmessage
47 import urllib.parse as urllib
48 import urllib.request as urllib2
49 import configparser as ConfigParser
50 import xmlrpc.client as xmlrpclib
51 import urllib.parse as urlparse
52 import http.client as httplib
2860dc7 @pnasrat Fix whitespace, etc for pep8 compliance
pnasrat authored
53
680b5df @vsajip Port to Python3
vsajip authored
54 def cmp(a, b):
55 return (a > b) - (a < b)
2860dc7 @pnasrat Fix whitespace, etc for pep8 compliance
pnasrat authored
56
680b5df @vsajip Port to Python3
vsajip authored
57 def b(s):
58 return s.encode('utf-8')
2860dc7 @pnasrat Fix whitespace, etc for pep8 compliance
pnasrat authored
59
680b5df @vsajip Port to Python3
vsajip authored
60 def u(s):
61 return s.decode('utf-8')
2860dc7 @pnasrat Fix whitespace, etc for pep8 compliance
pnasrat authored
62
1fdbce0 Use the detected console encoding instead of utf-8 for decoding
Alex Grönholm authored
63 def console_to_str(s):
64 return s.decode(console_encoding)
65 bytes = bytes
680b5df @vsajip Port to Python3
vsajip authored
66 string_types = (str,)
67 raw_input = input
68 else:
69 from cStringIO import StringIO
70 from urllib2 import URLError, HTTPError
71 from Queue import Queue, Empty
72 from urllib import url2pathname, urlretrieve
73 from email import Message as emailmessage
74 import urllib
75 import urllib2
76 import urlparse
77 import ConfigParser
78 import xmlrpclib
79 import httplib
2860dc7 @pnasrat Fix whitespace, etc for pep8 compliance
pnasrat authored
80
680b5df @vsajip Port to Python3
vsajip authored
81 def b(s):
82 return s
2860dc7 @pnasrat Fix whitespace, etc for pep8 compliance
pnasrat authored
83
680b5df @vsajip Port to Python3
vsajip authored
84 def u(s):
85 return s
2860dc7 @pnasrat Fix whitespace, etc for pep8 compliance
pnasrat authored
86
1fdbce0 Use the detected console encoding instead of utf-8 for decoding
Alex Grönholm authored
87 def console_to_str(s):
88 return s
89 bytes = str
680b5df @vsajip Port to Python3
vsajip authored
90 string_types = (basestring,)
91 reduce = reduce
92 cmp = cmp
93 raw_input = raw_input
e33be61 @pnasrat Fix #297 adding deflate and gzip handling
pnasrat authored
94 BytesIO = StringIO
680b5df @vsajip Port to Python3
vsajip authored
95
96 try:
97 from email.parser import FeedParser
98 except ImportError:
99 # python lesser than 2.5
100 from email.FeedParser import FeedParser
101
102 from distutils.sysconfig import get_python_lib, get_python_version
ac2bfb5 @jezdez Fixed minor cosmetic issues to please pep8 tests.
jezdez authored
103
2860dc7 @pnasrat Fix whitespace, etc for pep8 compliance
pnasrat authored
104
c7129ea @hltbra fixed python2.4 backwards compatibility
hltbra authored
105 def copytree(src, dst):
3851210 @hltbra fixed version comparsion (right side) from strings to intergers
hltbra authored
106 if sys.version_info < (2, 5):
c7129ea @hltbra fixed python2.4 backwards compatibility
hltbra authored
107 before_last_dir = os.path.dirname(dst)
108 if not os.path.exists(before_last_dir):
109 os.makedirs(before_last_dir)
110 shutil.copytree(src, dst)
111 shutil.copymode(src, dst)
112 else:
113 shutil.copytree(src, dst)
94dfe26 @jezdez Fixed using pkgutil for Python 2.4 by adding pkgutil itself to the ba…
jezdez authored
114
115
e80c387 @jezdez Added support for mirrors as defined in PEP 381. This feature is disa…
jezdez authored
116 def product(*args, **kwds):
117 # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
118 # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
680b5df @vsajip Port to Python3
vsajip authored
119 pools = list(map(tuple, args)) * kwds.get('repeat', 1)
e80c387 @jezdez Added support for mirrors as defined in PEP 381. This feature is disa…
jezdez authored
120 result = [[]]
121 for pool in pools:
122 result = [x+[y] for x in result for y in pool]
123 for prod in result:
124 yield tuple(prod)
Something went wrong with that request. Please try again.