Permalink
Browse files

simplify portability imports to make them more portable themselves

  • Loading branch information...
1 parent 53e7c49 commit aa753aaffe5c4cd899c3e16f09a72e5e549eaac1 @scoder scoder committed Feb 20, 2012
View
@@ -54,13 +54,13 @@ def callable(f):
return hasattr(f, '__call__')
try:
- basestring = __builtins__["basestring"]
-except (NameError, KeyError):
+ basestring
+except NameError:
basestring = str
try:
- unicode = __builtins__["unicode"]
-except (NameError, KeyError):
+ unicode
+except NameError:
unicode = str
View
@@ -54,18 +54,18 @@
# Python 2.3
from sets import Set as set
try:
- bytes = __builtins__["bytes"]
-except (KeyError, NameError):
+ bytes
+except NameError:
# Python < 2.6
bytes = str
try:
- unicode = __builtins__["unicode"]
-except (KeyError, NameError):
+ unicode
+except NameError:
# Python 3
unicode = str
try:
- basestring = __builtins__["basestring"]
-except (KeyError, NameError):
+ basestring
+except NameError:
# Python 3
basestring = (str, bytes)
View
@@ -17,32 +17,23 @@
from lxml.html import xhtml_to_html, _transform_result
try:
- set
+ unichr
except NameError:
- # Python 3
- from sets import Set as set
-
-try:
- unichr = __builtins__['unichr']
-except (NameError, KeyError):
# Python 3
unichr = chr
-
try:
- unicode = __builtins__['unicode']
-except (NameError, KeyError):
+ unicode
+except NameError:
# Python 3
unicode = str
-
try:
- bytes = __builtins__['bytes']
-except (NameError, KeyError):
+ bytes
+except NameError:
# Python < 2.6
bytes = str
-
try:
- basestring = __builtins__['basestring']
-except (NameError, KeyError):
+ basestring
+except NameError:
basestring = (str, bytes)
View
@@ -12,8 +12,8 @@
# Python 3
_unicode = str
try:
- basestring = __builtins__["basestring"]
-except (KeyError, NameError):
+ basestring
+except NameError:
# Python 3
basestring = str
@@ -3,9 +3,10 @@
from lxml.html import _forms_xpath, _options_xpath, _nons, _transform_result
from lxml.html import defs
import copy
+
try:
- basestring = __builtins__["basestring"]
-except (KeyError, NameError):
+ basestring
+except NameError:
# Python 3
basestring = str
@@ -9,18 +9,18 @@
# some compat stuff, borrowed from lxml.html
try:
- bytes = __builtins__["bytes"]
-except (KeyError, NameError):
+ bytes
+except NameError:
# Python < 2.6
bytes = str
try:
- unicode = __builtins__["unicode"]
-except (KeyError, NameError):
+ unicode
+except NameError:
# Python 3
unicode = str
try:
- basestring = __builtins__["basestring"]
-except (KeyError, NameError):
+ basestring
+except NameError:
# Python 3
basestring = str
@@ -8,8 +8,8 @@
'css_shakespear.html')
try:
- basestring = __builtins__['basestring']
-except (NameError, KeyError):
+ basestring
+except NameError:
basestring = (str, bytes)
# Data borrowed from http://mootools.net/slickspeed/
@@ -15,8 +15,8 @@
from common_imports import SillyFileLike, HelperTestCase, write_to_file
try:
- unicode = __builtins__["unicode"]
-except (NameError, KeyError):
+ unicode
+except NameError:
unicode = str
class HtmlParserTestCase(HelperTestCase):
@@ -9,8 +9,8 @@
from common_imports import _str, _bytes
try:
- unicode = __builtins__["unicode"]
-except (NameError, KeyError):
+ unicode
+except NameError:
unicode = str
ascii_uni = _str('a')
@@ -13,13 +13,13 @@
is_python3 = sys.version_info[0] >= 3
try:
- unicode = __builtins__["unicode"]
-except (NameError, KeyError): # Python 3
+ unicode
+except NameError: # Python 3
unicode = str
try:
- basestring = __builtins__["basestring"]
-except (NameError, KeyError): # Python 3
+ basestring
+except NameError: # Python 3
basestring = str
from common_imports import etree, BytesIO, HelperTestCase, fileInTestDir

0 comments on commit aa753aa

Please sign in to comment.