99# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
1010# the full text of the license.
1111
12- import cookielib
1312import os
14- import StringIO
1513import sys
16- import urllib2
17- import urlparse
18- import xmlrpclib
14+
15+ from ConfigParser import SafeConfigParser
16+ from cookielib import LoadError , LWPCookieJar , MozillaCookieJar
17+ from urllib2 import Request , HTTPError , build_opener
18+ from urlparse import urlparse , parse_qsl
19+ from StringIO import StringIO
20+ from xmlrpclib import Binary , Fault , ProtocolError , ServerProxy , Transport
1921
2022import pycurl
2123
@@ -75,7 +77,7 @@ def _decode_rfc2231_value(val):
7577
7678
7779def _build_cookiejar (cookiefile ):
78- cj = cookielib . MozillaCookieJar (cookiefile )
80+ cj = MozillaCookieJar (cookiefile )
7981 if cookiefile is None :
8082 return cj
8183 if not os .path .exists (cookiefile ):
@@ -90,17 +92,17 @@ def _build_cookiejar(cookiefile):
9092 try :
9193 cj .load ()
9294 return cj
93- except cookielib . LoadError :
95+ except LoadError :
9496 pass
9597
9698 try :
97- cj = cookielib . LWPCookieJar (cookiefile )
99+ cj = LWPCookieJar (cookiefile )
98100 cj .load ()
99- except cookielib . LoadError :
101+ except LoadError :
100102 raise BugzillaError ("cookiefile=%s not in LWP or Mozilla format" %
101103 cookiefile )
102104
103- retcj = cookielib . MozillaCookieJar (cookiefile )
105+ retcj = MozillaCookieJar (cookiefile )
104106 for cookie in cj :
105107 retcj .set_cookie (cookie )
106108 retcj .save ()
@@ -115,7 +117,7 @@ def _check_http_error(uri, request_body, response_data):
115117 import httplib
116118 import urllib
117119
118- class FakeSocket (StringIO . StringIO ):
120+ class FakeSocket (StringIO ):
119121 def makefile (self , * args , ** kwarg ):
120122 ignore = args
121123 ignore = kwarg
@@ -127,30 +129,30 @@ def makefile(self, *args, **kwarg):
127129 resp .code = httpresp .status
128130 resp .msg = httpresp .reason
129131
130- req = urllib2 . Request (uri )
132+ req = Request (uri )
131133 req .add_data (request_body )
132- opener = urllib2 . build_opener ()
134+ opener = build_opener ()
133135
134136 for handler in opener .handlers :
135137 if hasattr (handler , "http_response" ):
136138 handler .http_response (req , resp )
137- except urllib2 . HTTPError :
139+ except HTTPError :
138140 raise
139141 except :
140142 pass
141143
142144
143- class _CURLTransport (xmlrpclib . Transport ):
145+ class _CURLTransport (Transport ):
144146 def __init__ (self , url , cookiejar ,
145147 sslverify = True , sslcafile = None , debug = 0 ):
146- if hasattr (xmlrpclib . Transport , "__init__" ):
147- xmlrpclib . Transport .__init__ (self , use_datetime = False )
148+ if hasattr (Transport , "__init__" ):
149+ Transport .__init__ (self , use_datetime = False )
148150
149151 self .verbose = debug
150152
151153 # transport constructor needs full url too, as xmlrpc does not pass
152154 # scheme to request
153- self .scheme = urlparse . urlparse (url )[0 ]
155+ self .scheme = urlparse (url )[0 ]
154156 if self .scheme not in ["http" , "https" ]:
155157 raise Exception ("Invalid URL scheme: %s (%s)" % (self .scheme , url ))
156158
@@ -186,8 +188,8 @@ def _open_helper(self, url, request_body):
186188 self .c .setopt (pycurl .URL , url )
187189 self .c .setopt (pycurl .POSTFIELDS , request_body )
188190
189- b = StringIO . StringIO ()
190- headers = StringIO . StringIO ()
191+ b = StringIO ()
192+ headers = StringIO ()
191193 self .c .setopt (pycurl .WRITEFUNCTION , b .write )
192194 self .c .setopt (pycurl .HEADERFUNCTION , headers .write )
193195
@@ -216,7 +218,7 @@ def _open_helper(self, url, request_body):
216218 raise KeyboardInterrupt
217219 except pycurl .error :
218220 e = sys .exc_info ()[1 ]
219- raise xmlrpclib . ProtocolError (url , e [0 ], e [1 ], None )
221+ raise ProtocolError (url , e [0 ], e [1 ], None )
220222
221223 b .seek (0 )
222224 headers .seek (0 )
@@ -291,12 +293,12 @@ def url_to_query(url):
291293 '''
292294 q = {}
293295 (ignore , ignore , path ,
294- ignore , query , ignore ) = urlparse . urlparse (url )
296+ ignore , query , ignore ) = urlparse (url )
295297
296298 if os .path .basename (path ) not in ('buglist.cgi' , 'query.cgi' ):
297299 return {}
298300
299- for (k , v ) in urlparse . parse_qsl (query ):
301+ for (k , v ) in parse_qsl (query ):
300302 if k not in q :
301303 q [k ] = v
302304 elif isinstance (q [k ], list ):
@@ -357,9 +359,8 @@ def _init_private_data(self):
357359 self ._components_details = {}
358360
359361 def _get_user_agent (self ):
360- ret = ('Python-urllib2/%s bugzilla.py/%s %s/%s' %
361- (urllib2 .__version__ , __version__ ,
362- str (self .__class__ .__name__ ), self .version ))
362+ ret = ('Python-urllib bugzilla.py/%s %s/%s' %
363+ (__version__ , str (self .__class__ .__name__ ), self .version ))
363364 return ret
364365 user_agent = property (_get_user_agent )
365366
@@ -437,11 +438,10 @@ def readconfig(self, configpath=None):
437438 '''
438439 Read bugzillarc file(s) into memory.
439440 '''
440- import ConfigParser
441441 if not configpath :
442442 configpath = self .configpath
443443 configpath = [os .path .expanduser (p ) for p in configpath ]
444- c = ConfigParser . SafeConfigParser ()
444+ c = SafeConfigParser ()
445445 r = c .read (configpath )
446446 if not r :
447447 return
@@ -477,7 +477,7 @@ def connect(self, url=None):
477477 self ._transport = _CURLTransport (url , self ._cookiejar ,
478478 sslverify = self ._sslverify )
479479 self ._transport .user_agent = self .user_agent
480- self ._proxy = xmlrpclib . ServerProxy (url , self ._transport )
480+ self ._proxy = ServerProxy (url , self ._transport )
481481
482482
483483 self .url = url
@@ -533,7 +533,7 @@ def login(self, user=None, password=None):
533533 self .logged_in = True
534534 log .info ("login successful - dropping password from memory" )
535535 self .password = ''
536- except xmlrpclib . Fault :
536+ except Fault :
537537 r = False
538538
539539 return r
@@ -1218,7 +1218,7 @@ def _attachment_uri(self, attachid):
12181218 def attachfile (self , idlist , attachfile , description , ** kwargs ):
12191219 '''
12201220 Attach a file to the given bug IDs. Returns the ID of the attachment
1221- or raises xmlrpclib. Fault if something goes wrong.
1221+ or raises XMLRPC Fault if something goes wrong.
12221222
12231223 attachfile may be a filename (which will be opened) or a file-like
12241224 object, which must provide a 'read' method. If it's not one of these,
@@ -1259,7 +1259,7 @@ def attachfile(self, idlist, attachfile, description, **kwargs):
12591259 kwargs ["file_name" ] = kwargs .pop ("filename" )
12601260
12611261 kwargs ['summary' ] = description
1262- kwargs ['data' ] = xmlrpclib . Binary (f .read ())
1262+ kwargs ['data' ] = Binary (f .read ())
12631263 kwargs ['ids' ] = self ._listify (idlist )
12641264
12651265 if 'file_name' not in kwargs and hasattr (f , "name" ):
@@ -1290,7 +1290,7 @@ def openattachment(self, attachid):
12901290 att_uri = self ._attachment_uri (attachid )
12911291
12921292 headers = {}
1293- ret = StringIO . StringIO ()
1293+ ret = StringIO ()
12941294
12951295 def headers_cb (buf ):
12961296 if not ":" in buf :
@@ -1440,7 +1440,7 @@ def _getusers(self, ids=None, names=None, match=None):
14401440 :kwarg names: list of user names to return data on
14411441 :kwarg match: list of patterns. Returns users whose real name or
14421442 login name match the pattern.
1443- :raises xmlrpclib. Fault: Code 51: if a Bad Login Name was sent to the
1443+ :raises XMLRPC Fault: Code 51: if a Bad Login Name was sent to the
14441444 names array.
14451445 Code 304: if the user was not authorized to see user they
14461446 requested.
@@ -1467,7 +1467,7 @@ def getuser(self, username):
14671467 '''Return a bugzilla User for the given username
14681468
14691469 :arg username: The username used in bugzilla.
1470- :raises xmlrpclib. Fault: Code 51 if the username does not exist
1470+ :raises XMLRPC Fault: Code 51 if the username does not exist
14711471 :returns: User record for the username
14721472 '''
14731473 ret = self .getusers (username )
@@ -1509,7 +1509,7 @@ def createuser(self, email, name='', password=''):
15091509 :arg email: The email address to use in bugzilla
15101510 :kwarg name: Real name to associate with the account
15111511 :kwarg password: Password to set for the bugzilla account
1512- :raises xmlrpclib. Fault: Code 501 if the username already exists
1512+ :raises XMLRPC Fault: Code 501 if the username already exists
15131513 Code 500 if the email address isn't valid
15141514 Code 502 if the password is too short
15151515 Code 503 if the password is too long
0 commit comments