[Lxml-checkins] r52597 - lxml/branch/lxml-2.0/src/lxml
scoder at codespeak.net
scoder at codespeak.net
Sun Mar 16 13:54:08 CET 2008
Author: scoder
Date: Sun Mar 16 13:54:06 2008
New Revision: 52597
Modified:
lxml/branch/lxml-2.0/src/lxml/parser.pxi
Log:
merge -c 52596
Modified: lxml/branch/lxml-2.0/src/lxml/parser.pxi
==============================================================================
--- lxml/branch/lxml-2.0/src/lxml/parser.pxi (original)
+++ lxml/branch/lxml-2.0/src/lxml/parser.pxi Sun Mar 16 13:54:06 2008
@@ -1302,10 +1302,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:
@@ -1317,16 +1329,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
More information about the lxml-checkins
mailing list