blob: e8aafdf72fba2c88643f0a9d3cc878c1083dbf55 (
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
36
37
38
39
40
41
42
43
44
45
|
=== src/lxml/parser.pxi
==================================================================
--- src/lxml/parser.pxi (revision 3798)
+++ src/lxml/parser.pxi (revision 3799)
@@ -1294,10 +1294,22 @@
cdef _Document _parseDocument(source, _BaseParser parser, base_url):
cdef _Document doc
+ if _isString(source):
+ # parse the file directly from the filesystem
+ doc = _parseDocumentFromURL(_encodeFilename(source), parser)
+ # fix base URL if requested
+ if base_url is not None:
+ base_url = _encodeFilenameUTF8(base_url)
+ if doc._c_doc.URL is not NULL:
+ tree.xmlFree(doc._c_doc.URL)
+ doc._c_doc.URL = tree.xmlStrdup(_cstr(base_url))
+ return doc
+
if base_url is not None:
url = base_url
else:
url = _getFilenameForFile(source)
+
if hasattr(source, 'getvalue') and hasattr(source, 'tell'):
# StringIO - reading from start?
if source.tell() == 0:
@@ -1309,16 +1321,7 @@
return _parseFilelikeDocument(
source, _encodeFilenameUTF8(url), parser)
- # Otherwise parse the file directly from the filesystem
- filename = _encodeFilename(source)
- doc = _parseDocumentFromURL(filename, parser)
- # fix base URL if requested
- if base_url is not None:
- base_url = _encodeFilenameUTF8(base_url)
- if doc._c_doc.URL is not NULL:
- tree.xmlFree(doc._c_doc.URL)
- doc._c_doc.URL = tree.xmlStrdup(_cstr(base_url))
- return doc
+ raise TypeError("cannot parse from '%s'" % python._fqtypename(source))
cdef _Document _parseDocumentFromURL(url, _BaseParser parser):
cdef xmlDoc* c_doc
|