From fe34384d6ab71dc2ca3e90b1c46b44a966f0cd25 Mon Sep 17 00:00:00 2001 From: Joshua Boverhof Date: Thu, 29 Apr 2004 01:40:49 +0000 Subject: [PATCH] ---------------------------------------------------------------------- Modified Files: Utility.py XMLSchema.py -- just moved SplitQName out of here and into Utility Added Files: Namespaces.py -- WSDL, SOAP, SCHEMA, XMLNS namespaces here. Doesn't require PyXml ---------------------------------------------------------------------- --- Namespaces.py | 31 +++++++++++++++++++++++++++++++ Utility.py | 32 ++++++++++++++++++++++++++++---- XMLSchema.py | 35 ++--------------------------------- 3 files changed, 61 insertions(+), 37 deletions(-) create mode 100755 Namespaces.py diff --git a/Namespaces.py b/Namespaces.py new file mode 100755 index 0000000..71f2f74 --- /dev/null +++ b/Namespaces.py @@ -0,0 +1,31 @@ +#! /usr/bin/env python +"""Namespace module, so you don't need PyXML +""" + +try: + from xml.ns import SOAP, SCHEMA, WSDL, XMLNS +except: + class SOAP: + ENV = "http://schemas.xmlsoap.org/soap/envelope/" + ENC = "http://schemas.xmlsoap.org/soap/encoding/" + ACTOR_NEXT = "http://schemas.xmlsoap.org/soap/actor/next" + + class SCHEMA: + XSD1 = "http://www.w3.org/1999/XMLSchema" + XSD2 = "http://www.w3.org/2000/10/XMLSchema" + XSD3 = "http://www.w3.org/2001/XMLSchema" + XSI1 = "http://www.w3.org/1999/XMLSchema-instance" + XSI2 = "http://www.w3.org/2000/10/XMLSchema-instance" + XSI3 = "http://www.w3.org/2001/XMLSchema-instance" + BASE = XSD3 + + class WSDL: + BASE = 'http://schemas.xmlsoap.org/wsdl/' + BIND_HTTP = 'http://schemas.xmlsoap.org/wsdl/http/' + BIND_MIME = 'http://schemas.xmlsoap.org/wsdl/mime/' + BIND_SOAP = 'http://schemas.xmlsoap.org/wsdl/soap/' + + class XMLNS: + BASE = "http://www.w3.org/2000/xmlns/" + XML = "http://www.w3.org/XML/1998/namespace" + HTML = "http://www.w3.org/TR/REC-html40" diff --git a/Utility.py b/Utility.py index deda60c..46860aa 100755 --- a/Utility.py +++ b/Utility.py @@ -10,18 +10,42 @@ ident = "$Id$" import types +import string, httplib, smtplib, urllib, socket, weakref +import xml.dom.minidom from string import join, strip, split from UserDict import UserDict from StringIO import StringIO -import xml.dom.minidom, weakref - -import string, httplib, smtplib, urllib, socket from TimeoutSocket import TimeoutSocket, TimeoutError -from StringIO import StringIO from urlparse import urlparse from httplib import HTTPConnection, HTTPSConnection from exceptions import Exception +try: + from xml.dom.ext import SplitQName +except: + def SplitQName(qname): + '''SplitQName(qname) -> (string, string) + + Split Qualified Name into a tuple of len 2, consisting + of the prefix and the local name. + + (prefix, localName) + + Special Cases: + xmlns -- (localName, 'xmlns') + None -- (None, localName) + ''' + + l = qname.split(':') + if len(l) == 1: + l.insert(0, None) + elif len(l) == 2: + if l[0] == 'xmlns': + l.reverse() + else: + return + return tuple(l) + class RecursionError(Exception): """Used to indicate a HTTP redirect recursion.""" pass diff --git a/XMLSchema.py b/XMLSchema.py index e53bc63..99a5022 100755 --- a/XMLSchema.py +++ b/XMLSchema.py @@ -16,40 +16,9 @@ ident = "$Id$" import types, weakref, urllib, sys from threading import RLock -try: - from xml.ns import XMLNS -except ImportError: - # ref: - # http://cvs.sourceforge.net/viewcvs.py/pyxml/xml/xml/ns.py?view=markup - class XMLNS: - """XMLNS, Namespaces in XML - - XMLNS (14-Jan-1999) is a W3C Recommendation. It is specified in - http://www.w3.org/TR/REC-xml-names - BASE -- the basic namespace defined by the specification - XML -- the namespace for XML 1.0 - HTML -- the namespace for HTML4.0 - """ - - BASE = "http://www.w3.org/2000/xmlns/" - XML = "http://www.w3.org/XML/1998/namespace" - HTML = "http://www.w3.org/TR/REC-html40" - -from Utility import DOM, DOMException, Collection +from Namespaces import XMLNS +from Utility import DOM, DOMException, Collection, SplitQName from StringIO import StringIO -try: - from xml.dom.ext import SplitQName -except ImportError, ex: - def SplitQName(qname): - l = qname.split(':') - if len(l) == 1: - l.insert(0, None) - elif len(l) == 2: - if l[0] == 'xmlns': - l.reverse() - else: - return - return tuple(l) def GetSchema(component): """convience function for finding the parent XMLSchema instance.