@@ -94,10 +94,12 @@ def _show_debug_messages():
9494 _logger .addHandler (handler )
9595
9696try :
97+ from thirdparty import six
9798 from thirdparty .six .moves import cStringIO as _cStringIO
9899 from thirdparty .six .moves import html_entities as _html_entities
99100 from thirdparty .six .moves import urllib as _urllib
100101except ImportError :
102+ import six
101103 from six .moves import cStringIO as _cStringIO
102104 from six .moves import html_entities as _html_entities
103105 from six .moves import urllib as _urllib
@@ -173,7 +175,7 @@ def urlencode(query,doseq=False,):
173175 # non-sequence items should not work with len()
174176 x = len (query )
175177 # non-empty strings will fail this
176- if len (query ) and type (query [0 ]) != types . TupleType :
178+ if len (query ) and type (query [0 ]) != tuple :
177179 raise TypeError ()
178180 # zero-length sequences of all types will get here and succeed,
179181 # but that's a minor nit - since the original implementation
@@ -246,7 +248,7 @@ def unescape_charref(data, encoding):
246248 name , base = name [1 :], 16
247249 elif not name .isdigit ():
248250 base = 16
249- uc = unichr (int (name , base ))
251+ uc = six . unichr (int (name , base ))
250252 if encoding is None :
251253 return uc
252254 else :
@@ -270,7 +272,7 @@ def get_entitydefs():
270272 entitydefs ["&%s;" % name ] = uc
271273 else :
272274 for name , codepoint in _html_entities .name2codepoint .items ():
273- entitydefs ["&%s;" % name ] = unichr (codepoint )
275+ entitydefs ["&%s;" % name ] = six . unichr (codepoint )
274276 return entitydefs
275277
276278
@@ -1126,7 +1128,7 @@ def _ParseFileEx(file, base_uri,
11261128 if action is None :
11271129 action = base_uri
11281130 else :
1129- action = unicode (action , "utf8" ) if action and not isinstance (action , unicode ) else action
1131+ action = six . text_type (action , "utf8" ) if action and isinstance (action , six . binary_type ) else action
11301132 action = _urljoin (base_uri , action )
11311133 # would be nice to make HTMLForm class (form builder) pluggable
11321134 form = HTMLForm (
@@ -1321,8 +1323,8 @@ def __init__(self, type, name, attrs, index=None):
13211323 self .__dict__ ["type" ] = type .lower ()
13221324 self .__dict__ ["name" ] = name
13231325 self ._value = attrs .get ("value" )
1324- self .disabled = attrs . has_key ( "disabled" )
1325- self .readonly = attrs . has_key ( "readonly" )
1326+ self .disabled = "disabled" in attrs
1327+ self .readonly = "readonly" in attrs
13261328 self .id = attrs .get ("id" )
13271329
13281330 self .attrs = attrs .copy ()
@@ -3398,6 +3400,7 @@ def _switch_click(self, return_type, request_class=_urllib.request.Request):
33983400 return self ._request_data ()
33993401 else :
34003402 req_data = self ._request_data ()
3403+
34013404 req = request_class (req_data [0 ], req_data [1 ])
34023405 for key , val in req_data [2 ]:
34033406 add_hdr = req .add_header
0 commit comments