# This program is free software; you can redistribute it and/or modify # it under the terms of the (LGPL) GNU Lesser General Public License as # published by the Free Software Foundation; either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library Lesser General Public License for more details at # ( http://www.gnu.org/licenses/lgpl.html ). # # You should have received a copy of the GNU Lesser General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # written by: Jeff Ortel ( jortel@redhat.com ) """ Contains XML text for documents to be distributed with the suds lib. Also, contains classes for accessing these documents. """ from StringIO import StringIO from logging import getLogger log = getLogger(__name__) # # Soap section 5 encoding schema. # encoding = \ """ 'root' can be used to distinguish serialization roots from other elements that are present in a serialization but are not roots of a serialized value graph Attributes common to all elements that function as accessors or represent independent (multi-ref) values. The href attribute is intended to be used in a manner like CONREF. That is, the element content should be empty iff the href attribute appears 'Array' is a complex type for accessors identified by position """ class DocumentStore: """ The I{suds} document store provides a local repository for xml documnts. @cvar protocol: The URL protocol for the store. @type protocol: str @cvar store: The mapping of URL location to documents. @type store: dict """ protocol = 'suds' store = { 'schemas.xmlsoap.org/soap/encoding/' : encoding } def open(self, url): """ Open a document at the specified url. @param url: A document URL. @type url: str @return: A file pointer to the document. @rtype: StringIO """ protocol, location = self.split(url) if protocol == self.protocol: return self.find(location) else: return None def find(self, location): """ Find the specified location in the store. @param location: The I{location} part of a URL. @type location: str @return: An input stream to the document. @rtype: StringIO """ try: content = self.store[location] return StringIO(content) except: reason = 'location "%s" not in document store' % location raise Exception, reason def split(self, url): """ Split the url into I{protocol} and I{location} @param url: A URL. @param url: str @return: (I{url}, I{location}) @rtype: tuple """ parts = url.split('://', 1) if len(parts) == 2: return parts else: return (None, url)