logo       


Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: helper functions for accepting elementtrees/elements/documents as input: msg#00207

Subject: Re: helper functions for accepting elementtrees/elements/documents as input
Stefan Behnel wrote:
I noticed that many of the API classes accept _ElementTree object, although it
would make just as much sense to apply them to elements or (internally) to
documents. So here are three helper functions that you can use at the top of
API functions to check what actually came in and to determine how to extract
the document that is refered to and the context node within the document.

This simplifies clumsy expressions like
XSLT(ElementTree(XML("...")))
and the like to
XSLT(XML("..."))

I checked them into my branch, although they may need modification later,
depending on Geerts work.

While I agree that cleaning up how this works might be a good thing, I wonder what this means for ElementTree compatibility. I.e. it'll become a lot easier to write lxml code that doesn't work in ElementTree.

Perhaps we should check with Fredrik Lundh what he thinks first.

[snip]
Index: src/lxml/etree.pyx
===================================================================
--- src/lxml/etree.pyx  (Revision 19828)
+++ src/lxml/etree.pyx  (Arbeitskopie)
@@ -1093,6 +1093,36 @@


 # Private helper functions
+cdef _Document _documentOrRaise(object input):
+    cdef _Document doc
+    doc = _documentOf(input)
+    if doc is None:
+        raise TypeError, "Invalid input object: %s" % type(input)
+    else:
+        return doc
+
+cdef _Document _documentOf(object input):
+    # call this to get the document of a
+    # _Document, _ElementTree or _NodeBase object
+    if isinstance(input, _ElementTree):
+        return (<_ElementTree>input)._doc
+    elif isinstance(input, _NodeBase):
+        return (<_NodeBase>input)._doc
+    elif isinstance(input, _Document):
+        return <_Document>input
+    else:
+        return None
+
+cdef _NodeBase _rootNodeOf(object input):
+    # call this to get the root node of a
+    # _Document, _ElementTree or _NodeBase object
+    if hasattr(input, 'getroot'): # Document/ElementTree
+        return <_NodeBase>(input.getroot())
+    elif isinstance(input, _NodeBase):
+        return <_NodeBase>input
+    else:
+        return None
+
 cdef xmlDoc* _fakeRootDoc(xmlDoc* c_base_doc, xmlNode* c_node):
     # build a temporary document that has the given node as root node
     # note that copy and original must not be modified during its lifetime!!


Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
db.firebase.por...    text.xml.xalan....    qnx.openqnx.dev...    user-groups.zar...    internationaliz...    kde.devel.konve...    finance.e-gold....    emacs.latex.pre...    gis.therion/200...    web.webmin.gene...    yellowdog.gener...    vserver/2003-08...    redhat.release....    sysutils.tivoli...    xfree86.expert/...    mail.becky.user...    hardware.netapp...    netbsd.ports.xe...    python.distutil...    boot-loaders.gr...    culture.interne...    java.springfram...    activedir/2006-...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe