Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

simplify portability imports to make them more portable themselves

  • Loading branch information...
commit aa753aaffe5c4cd899c3e16f09a72e5e549eaac1 1 parent 53e7c49
scoder authored February 20, 2012
8  src/lxml/builder.py
@@ -54,13 +54,13 @@ def callable(f):
54 54
         return hasattr(f, '__call__')
55 55
 
56 56
 try:
57  
-    basestring = __builtins__["basestring"]
58  
-except (NameError, KeyError):
  57
+    basestring
  58
+except NameError:
59 59
     basestring = str
60 60
 
61 61
 try:
62  
-    unicode = __builtins__["unicode"]
63  
-except (NameError, KeyError):
  62
+    unicode
  63
+except NameError:
64 64
     unicode = str
65 65
 
66 66
 
12  src/lxml/html/__init__.py
@@ -54,18 +54,18 @@
54 54
     # Python 2.3
55 55
     from sets import Set as set
56 56
 try:
57  
-    bytes = __builtins__["bytes"]
58  
-except (KeyError, NameError):
  57
+    bytes
  58
+except NameError:
59 59
     # Python < 2.6
60 60
     bytes = str
61 61
 try:
62  
-    unicode = __builtins__["unicode"]
63  
-except (KeyError, NameError):
  62
+    unicode
  63
+except NameError:
64 64
     # Python 3
65 65
     unicode = str
66 66
 try:
67  
-    basestring = __builtins__["basestring"]
68  
-except (KeyError, NameError):
  67
+    basestring
  68
+except NameError:
69 69
     # Python 3
70 70
     basestring = (str, bytes)
71 71
 
23  src/lxml/html/clean.py
@@ -17,32 +17,23 @@
17 17
 from lxml.html import xhtml_to_html, _transform_result
18 18
 
19 19
 try:
20  
-    set
  20
+    unichr
21 21
 except NameError:
22 22
     # Python 3
23  
-    from sets import Set as set
24  
-
25  
-try:
26  
-    unichr = __builtins__['unichr']
27  
-except (NameError, KeyError):
28  
-    # Python 3
29 23
     unichr = chr
30  
-
31 24
 try:
32  
-    unicode = __builtins__['unicode']
33  
-except (NameError, KeyError):
  25
+    unicode
  26
+except NameError:
34 27
     # Python 3
35 28
     unicode = str
36  
-
37 29
 try:
38  
-    bytes = __builtins__['bytes']
39  
-except (NameError, KeyError):
  30
+    bytes
  31
+except NameError:
40 32
     # Python < 2.6
41 33
     bytes = str
42  
-
43 34
 try:
44  
-    basestring = __builtins__['basestring']
45  
-except (NameError, KeyError):
  35
+    basestring
  36
+except NameError:
46 37
     basestring = (str, bytes)
47 38
 
48 39
 
4  src/lxml/html/diff.py
@@ -12,8 +12,8 @@
12 12
     # Python 3
13 13
     _unicode = str
14 14
 try:
15  
-    basestring = __builtins__["basestring"]
16  
-except (KeyError, NameError):
  15
+    basestring
  16
+except NameError:
17 17
     # Python 3
18 18
     basestring = str
19 19
 
5  src/lxml/html/formfill.py
@@ -3,9 +3,10 @@
3 3
 from lxml.html import _forms_xpath, _options_xpath, _nons, _transform_result
4 4
 from lxml.html import defs
5 5
 import copy
  6
+
6 7
 try:
7  
-    basestring = __builtins__["basestring"]
8  
-except (KeyError, NameError):
  8
+    basestring
  9
+except NameError:
9 10
     # Python 3
10 11
     basestring = str
11 12
 
12  src/lxml/isoschematron/__init__.py
@@ -9,18 +9,18 @@
9 9
 
10 10
 # some compat stuff, borrowed from lxml.html
11 11
 try:
12  
-    bytes = __builtins__["bytes"]
13  
-except (KeyError, NameError):
  12
+    bytes
  13
+except NameError:
14 14
     # Python < 2.6
15 15
     bytes = str
16 16
 try:
17  
-    unicode = __builtins__["unicode"]
18  
-except (KeyError, NameError):
  17
+    unicode
  18
+except NameError:
19 19
     # Python 3
20 20
     unicode = str
21 21
 try:
22  
-    basestring = __builtins__["basestring"]
23  
-except (KeyError, NameError):
  22
+    basestring
  23
+except NameError:
24 24
     # Python 3
25 25
     basestring = str
26 26
 
4  src/lxml/tests/test_css.py
@@ -8,8 +8,8 @@
8 8
                       'css_shakespear.html')
9 9
 
10 10
 try:
11  
-    basestring = __builtins__['basestring']
12  
-except (NameError, KeyError):
  11
+    basestring
  12
+except NameError:
13 13
     basestring = (str, bytes)
14 14
 
15 15
 # Data borrowed from http://mootools.net/slickspeed/
4  src/lxml/tests/test_htmlparser.py
@@ -15,8 +15,8 @@
15 15
 from common_imports import SillyFileLike, HelperTestCase, write_to_file
16 16
 
17 17
 try:
18  
-    unicode = __builtins__["unicode"]
19  
-except (NameError, KeyError):
  18
+    unicode
  19
+except NameError:
20 20
     unicode = str
21 21
 
22 22
 class HtmlParserTestCase(HelperTestCase):
4  src/lxml/tests/test_unicode.py
@@ -9,8 +9,8 @@
9 9
 from common_imports import _str, _bytes
10 10
 
11 11
 try:
12  
-    unicode = __builtins__["unicode"]
13  
-except (NameError, KeyError):
  12
+    unicode
  13
+except NameError:
14 14
     unicode = str
15 15
 
16 16
 ascii_uni = _str('a')
8  src/lxml/tests/test_xslt.py
@@ -13,13 +13,13 @@
13 13
 is_python3 = sys.version_info[0] >= 3
14 14
 
15 15
 try:
16  
-    unicode = __builtins__["unicode"]
17  
-except (NameError, KeyError): # Python 3
  16
+    unicode
  17
+except NameError: # Python 3
18 18
     unicode = str
19 19
 
20 20
 try:
21  
-    basestring = __builtins__["basestring"]
22  
-except (NameError, KeyError): # Python 3
  21
+    basestring
  22
+except NameError: # Python 3
23 23
     basestring = str
24 24
 
25 25
 from common_imports import etree, BytesIO, HelperTestCase, fileInTestDir

0 notes on commit aa753aa

Please sign in to comment.
Something went wrong with that request. Please try again.