File tree Expand file tree Collapse file tree 1 file changed +6
-12
lines changed Expand file tree Collapse file tree 1 file changed +6
-12
lines changed Original file line number Diff line number Diff line change @@ -129,13 +129,10 @@ def to_unicode_optional_iterator(x):
129
129
if isinstance (x , basestring ):
130
130
return to_unicode (x )
131
131
132
- try :
133
- l = list (x )
134
- except TypeError , e :
135
- assert 'is not iterable' in str (e )
132
+ if not hasattr (x , '__iter__' ):
136
133
return x
137
- else :
138
- return [ to_unicode (e ) for e in l ]
134
+
135
+ return [ to_unicode (e ) for e in list ( x ) ]
139
136
140
137
def to_utf8_optional_iterator (x ):
141
138
"""
@@ -145,13 +142,10 @@ def to_utf8_optional_iterator(x):
145
142
if isinstance (x , basestring ):
146
143
return to_utf8 (x )
147
144
148
- try :
149
- l = list (x )
150
- except TypeError , e :
151
- assert 'is not iterable' in str (e )
145
+ if not hasattr (x , '__iter__' ):
152
146
return x
153
- else :
154
- return [ to_utf8_if_string (e ) for e in l ]
147
+
148
+ return [ to_utf8_if_string (e ) for e in list ( x ) ]
155
149
156
150
def escape (s ):
157
151
"""Escape a URL including any /."""
You can’t perform that action at this time.
0 commit comments