[Lxml-checkins] r46623 - lxml/trunk/src/lxml
scoder at codespeak.net
scoder at codespeak.net
Sat Sep 15 12:06:23 CEST 2007
Author: scoder
Date: Sat Sep 15 12:06:23 2007
New Revision: 46623
Modified:
lxml/trunk/src/lxml/apihelpers.pxi
Log:
small optimisation
Modified: lxml/trunk/src/lxml/apihelpers.pxi
==============================================================================
--- lxml/trunk/src/lxml/apihelpers.pxi (original)
+++ lxml/trunk/src/lxml/apihelpers.pxi Sat Sep 15 12:06:23 2007
@@ -821,12 +821,20 @@
Returns None if not a file object.
"""
# file instances have a name attribute
- if hasattr(source, 'name'):
+ try:
return source.name
+ except AttributeError:
+ pass
# gzip file instances have a filename attribute
- if hasattr(source, 'filename'):
+ try:
return source.filename
- # urllib2
- if hasattr(source, 'geturl'):
- return source.geturl()
- return None
+ except AttributeError:
+ pass
+ # urllib2 provides a geturl() method
+ try:
+ geturl = source.geturl
+ except AttributeError:
+ # can't determine filename
+ return None
+ else:
+ return geturl()
More information about the lxml-checkins
mailing list