blob: a48f258109b62ad3b3cdf1acbcada5cf4305f391 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
=== src/lxml/apihelpers.pxi
==================================================================
--- src/lxml/apihelpers.pxi (revision 3804)
+++ src/lxml/apihelpers.pxi (revision 3805)
@@ -1107,20 +1107,16 @@
Returns None if not a file object.
"""
# file instances have a name attribute
- try:
- return source.name
- except AttributeError:
- pass
+ filename = getattr3(source, 'name', None)
+ if filename is not None:
+ return filename
# gzip file instances have a filename attribute
- try:
- return source.filename
- except AttributeError:
- pass
+ filename = getattr3(source, 'filename', None)
+ if filename is not None:
+ return filename
# urllib2 provides a geturl() method
- try:
- geturl = source.geturl
- except AttributeError:
- # can't determine filename
- return None
- else:
+ geturl = getattr3(source, 'geturl', None)
+ if geturl is not None:
return geturl()
+ # can't determine filename
+ return None
|