OLD | NEW |
(Empty) | |
| 1 # copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
| 2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
| 3 # |
| 4 # This file is part of astroid. |
| 5 # |
| 6 # astroid is free software: you can redistribute it and/or modify it under |
| 7 # the terms of the GNU Lesser General Public License as published by the Free |
| 8 # Software Foundation, either version 2.1 of the License, or (at your option) an
y |
| 9 # later version. |
| 10 # |
| 11 # astroid is distributed in the hope that it will be useful, but WITHOUT |
| 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 14 # details. |
| 15 # |
| 16 # You should have received a copy of the GNU Lesser General Public License along |
| 17 # with astroid. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
| 19 """Astroid hooks for six.moves.""" |
| 20 |
| 21 import sys |
| 22 from textwrap import dedent |
| 23 |
| 24 from astroid import MANAGER, register_module_extender |
| 25 from astroid.builder import AstroidBuilder |
| 26 |
| 27 |
| 28 def six_moves_transform_py2(): |
| 29 return AstroidBuilder(MANAGER).string_build(dedent(''' |
| 30 import urllib as _urllib |
| 31 import urllib2 as _urllib2 |
| 32 import urlparse as _urlparse |
| 33 |
| 34 class Moves(object): |
| 35 import BaseHTTPServer |
| 36 import CGIHTTPServer |
| 37 import SimpleHTTPServer |
| 38 |
| 39 from StringIO import StringIO |
| 40 from cStringIO import StringIO as cStringIO |
| 41 from UserDict import UserDict |
| 42 from UserList import UserList |
| 43 from UserString import UserString |
| 44 |
| 45 import __builtin__ as builtins |
| 46 import thread as _thread |
| 47 import dummy_thread as _dummy_thread |
| 48 import ConfigParser as configparser |
| 49 import copy_reg as copyreg |
| 50 from itertools import (imap as map, |
| 51 ifilter as filter, |
| 52 ifilterfalse as filterfalse, |
| 53 izip_longest as zip_longest, |
| 54 izip as zip) |
| 55 import htmlentitydefs as html_entities |
| 56 import HTMLParser as html_parser |
| 57 import httplib as http_client |
| 58 import cookielib as http_cookiejar |
| 59 import Cookie as http_cookies |
| 60 import Queue as queue |
| 61 import repr as reprlib |
| 62 from pipes import quote as shlex_quote |
| 63 import SocketServer as socketserver |
| 64 import SimpleXMLRPCServer as xmlrpc_server |
| 65 import xmlrpclib as xmlrpc_client |
| 66 import _winreg as winreg |
| 67 import robotparser as urllib_robotparser |
| 68 |
| 69 input = raw_input |
| 70 intern = intern |
| 71 range = xrange |
| 72 xrange = xrange |
| 73 reduce = reduce |
| 74 reload_module = reload |
| 75 |
| 76 class UrllibParse(object): |
| 77 ParseResult = _urlparse.ParseResult |
| 78 SplitResult = _urlparse.SplitResult |
| 79 parse_qs = _urlparse.parse_qs |
| 80 parse_qsl = _urlparse.parse_qsl |
| 81 urldefrag = _urlparse.urldefrag |
| 82 urljoin = _urlparse.urljoin |
| 83 urlparse = _urlparse.urlparse |
| 84 urlsplit = _urlparse.urlsplit |
| 85 urlunparse = _urlparse.urlunparse |
| 86 urlunsplit = _urlparse.urlunsplit |
| 87 quote = _urllib.quote |
| 88 quote_plus = _urllib.quote_plus |
| 89 unquote = _urllib.unquote |
| 90 unquote_plus = _urllib.unquote_plus |
| 91 urlencode = _urllib.urlencode |
| 92 splitquery = _urllib.splitquery |
| 93 splittag = _urllib.splittag |
| 94 splituser = _urllib.splituser |
| 95 uses_fragment = _urlparse.uses_fragment |
| 96 uses_netloc = _urlparse.uses_netloc |
| 97 uses_params = _urlparse.uses_params |
| 98 uses_query = _urlparse.uses_query |
| 99 uses_relative = _urlparse.uses_relative |
| 100 |
| 101 class UrllibError(object): |
| 102 URLError = _urllib2.URLError |
| 103 HTTPError = _urllib2.HTTPError |
| 104 ContentTooShortError = _urllib.ContentTooShortError |
| 105 |
| 106 class DummyModule(object): |
| 107 pass |
| 108 |
| 109 class UrllibRequest(object): |
| 110 urlopen = _urllib2.urlopen |
| 111 install_opener = _urllib2.install_opener |
| 112 build_opener = _urllib2.build_opener |
| 113 pathname2url = _urllib.pathname2url |
| 114 url2pathname = _urllib.url2pathname |
| 115 getproxies = _urllib.getproxies |
| 116 Request = _urllib2.Request |
| 117 OpenerDirector = _urllib2.OpenerDirector |
| 118 HTTPDefaultErrorHandler = _urllib2.HTTPDefaultErrorHandler |
| 119 HTTPRedirectHandler = _urllib2.HTTPRedirectHandler |
| 120 HTTPCookieProcessor = _urllib2.HTTPCookieProcessor |
| 121 ProxyHandler = _urllib2.ProxyHandler |
| 122 BaseHandler = _urllib2.BaseHandler |
| 123 HTTPPasswordMgr = _urllib2.HTTPPasswordMgr |
| 124 HTTPPasswordMgrWithDefaultRealm = _urllib2.HTTPPasswordMgrWithDefaul
tRealm |
| 125 AbstractBasicAuthHandler = _urllib2.AbstractBasicAuthHandler |
| 126 HTTPBasicAuthHandler = _urllib2.HTTPBasicAuthHandler |
| 127 ProxyBasicAuthHandler = _urllib2.ProxyBasicAuthHandler |
| 128 AbstractDigestAuthHandler = _urllib2.AbstractDigestAuthHandler |
| 129 HTTPDigestAuthHandler = _urllib2.HTTPDigestAuthHandler |
| 130 ProxyDigestAuthHandler = _urllib2.ProxyDigestAuthHandler |
| 131 HTTPHandler = _urllib2.HTTPHandler |
| 132 HTTPSHandler = _urllib2.HTTPSHandler |
| 133 FileHandler = _urllib2.FileHandler |
| 134 FTPHandler = _urllib2.FTPHandler |
| 135 CacheFTPHandler = _urllib2.CacheFTPHandler |
| 136 UnknownHandler = _urllib2.UnknownHandler |
| 137 HTTPErrorProcessor = _urllib2.HTTPErrorProcessor |
| 138 urlretrieve = _urllib.urlretrieve |
| 139 urlcleanup = _urllib.urlcleanup |
| 140 proxy_bypass = _urllib.proxy_bypass |
| 141 |
| 142 urllib_parse = UrllibParse() |
| 143 urllib_error = UrllibError() |
| 144 urllib = DummyModule() |
| 145 urllib.request = UrllibRequest() |
| 146 urllib.parse = UrllibParse() |
| 147 urllib.error = UrllibError() |
| 148 |
| 149 moves = Moves() |
| 150 |
| 151 ''')) |
| 152 |
| 153 |
| 154 def six_moves_transform_py3(): |
| 155 return AstroidBuilder(MANAGER).string_build(dedent(''' |
| 156 class Moves(object): |
| 157 import _io |
| 158 cStringIO = _io.StringIO |
| 159 filter = filter |
| 160 from itertools import filterfalse |
| 161 input = input |
| 162 from sys import intern |
| 163 map = map |
| 164 range = range |
| 165 from imp import reload as reload_module |
| 166 from functools import reduce |
| 167 from shlex import quote as shlex_quote |
| 168 from io import StringIO |
| 169 from collections import UserDict, UserList, UserString |
| 170 xrange = range |
| 171 zip = zip |
| 172 from itertools import zip_longest |
| 173 import builtins |
| 174 import configparser |
| 175 import copyreg |
| 176 import _dummy_thread |
| 177 import http.cookiejar as http_cookiejar |
| 178 import http.cookies as http_cookies |
| 179 import html.entities as html_entities |
| 180 import html.parser as html_parser |
| 181 import http.client as http_client |
| 182 import http.server |
| 183 BaseHTTPServer = CGIHTTPServer = SimpleHTTPServer = http.server |
| 184 import pickle as cPickle |
| 185 import queue |
| 186 import reprlib |
| 187 import socketserver |
| 188 import _thread |
| 189 import winreg |
| 190 import xmlrpc.server as xmlrpc_server |
| 191 import xmlrpc.client as xmlrpc_client |
| 192 import urllib.robotparser as urllib_robotparser |
| 193 import email.mime.multipart as email_mime_multipart |
| 194 import email.mime.nonmultipart as email_mime_nonmultipart |
| 195 import email.mime.text as email_mime_text |
| 196 import email.mime.base as email_mime_base |
| 197 import urllib.parse as urllib_parse |
| 198 import urllib.error as urllib_error |
| 199 import tkinter |
| 200 import tkinter.dialog as tkinter_dialog |
| 201 import tkinter.filedialog as tkinter_filedialog |
| 202 import tkinter.scrolledtext as tkinter_scrolledtext |
| 203 import tkinter.simpledialog as tkinder_simpledialog |
| 204 import tkinter.tix as tkinter_tix |
| 205 import tkinter.ttk as tkinter_ttk |
| 206 import tkinter.constants as tkinter_constants |
| 207 import tkinter.dnd as tkinter_dnd |
| 208 import tkinter.colorchooser as tkinter_colorchooser |
| 209 import tkinter.commondialog as tkinter_commondialog |
| 210 import tkinter.filedialog as tkinter_tkfiledialog |
| 211 import tkinter.font as tkinter_font |
| 212 import tkinter.messagebox as tkinter_messagebox |
| 213 import urllib.request |
| 214 import urllib.robotparser as urllib_robotparser |
| 215 import urllib.parse as urllib_parse |
| 216 import urllib.error as urllib_error |
| 217 moves = Moves() |
| 218 ''')) |
| 219 |
| 220 if sys.version_info[0] == 2: |
| 221 TRANSFORM = six_moves_transform_py2 |
| 222 else: |
| 223 TRANSFORM = six_moves_transform_py3 |
| 224 |
| 225 register_module_extender(MANAGER, 'six', TRANSFORM) |
OLD | NEW |