Dave Kuhlman
http://www.rexx.com/~dkuhlman
Email: [email protected]
Release 1.00
April 16, 2003
Copyright (c) 2003 Dave Kuhlman
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This document describes a small amount of support for using Python with Amazon WS (Amazon Web services).
This document describes additional support for developing Python access to Amazon WS (Amazon Web services). This support is usable with the "XML over HTTP" style of Amazon WS, which is mostly REST-like.
A distribution file containing this support is at amazon_ws_support-1.0.tar.gz.
This support provides modules containing classes that represent the content of the response to a request to Amazon Web services. These modules are also capable of parsing the response XML document.
This support is intended to be used with the XML over HTTP approach to Amazon Web services. One module is provided for the "lite" response document and another module is provided for the "heavy" response document.
The support modules were initially generated with generateDS.py. A copy of generateDS.py is included with the distribution. You can learn more about generateDS.py at http://www.rexx.com/~dkuhlman/#generateDS.
The distribution also includes a very small, example application get_books.py that uses the support modules.
The parser -- Parses an Amazon Web service response document and creates instances of the representation classes. The support modules (dev_lite_sup.py and dev_lite_sub.py, for example) contain functions parse(inFilename) and parseString(inString).
The super-classes -- These are the representation classes. They provide getter and setter functions for member variables, a function (build) to build an instance from the corresponding DOM object, and export function (export).
The sub-classes -- These sub-classes of the representation classes are where you hang your code.
The source code generator -- A copy of generateDS.py is included. This can be used to re-generate the XML representation classes from the XML Schema documents, which are also included.
Try this test:
python get_books.py -a [my_amazon_dev_token] pruning tree
You can create a new (empty) sub-class file with the either of the following:
./generateDS.py -s my_lite_sub.py dev-lite.xsd ./generateDS.py -s my_heavy_sub.py dev-heavy.xsd
Why would you want to do this? You can, for example, create a new sub-class file, then "decorate" the classes in it with methods that perform specialized tasks.
There is a example in get_books.py.
How to do it:
./generateDS.py -s mysubclasses.py dev-lite.xsd ./generateDS.py -s mysubclasses.py dev-heavy.xsd
class ProductInfoSub(supermod.ProductInfo): o o o def showProduct(self): for detail in self.getDetails(): detail.showProduct(count) supermod.ProductInfo.subclass = ProductInfoSub # end class ProductInfoSub class DetailsSub(supermod.Details): o o o def showProduct(self, count): name = self.getProductname() print '%d. ProductName: %s' % (count, name) authors = self.getAuthors() if authors: authors = authors.getAuthor() print 'Authors:' for author in authors: print ' %s' % author price = self.getOurprice() if price: print 'Price: %s' % price else: print 'Price not available' supermod.Details.subclass = DetailsSub # end class DetailsSub
import mysubclasses
import mysubclasses import urllib f = urllib.urlopen(url) content = f.read() f.close() doc = mysubclasses.parseString(content) doc.showProduct()
The support modules contain functions that parse an XML document returned by a request to Amazon WS. These functions return an instance of the root object, an instance of class ProductInfo.
Usage:
import dev_lite_sub root = dev_lite_sub.parse(inFileName)
Or:
import dev_heavy_sub root = dev_heavy_sub.parse(inFileName)
Where:
Returns -- An instance of class ProductInfo.
Usage:
import dev_lite_sub root = dev_lite_sub.parseString(aString)
Or:
import dev_heavy_sub root = dev_heavy_sub.parseString(aString)
Where:
Returns -- An instance of class ProductInfo.
Thanks to Amazon for the Amazon Web Services API and Web Services toolkit.
See Also:
This document was generated using the LaTeX2HTML translator.
LaTeX2HTML is Copyright © 1993, 1994, 1995, 1996, 1997, Nikos Drakos, Computer Based Learning Unit, University of Leeds, and Copyright © 1997, 1998, Ross Moore, Mathematics Department, Macquarie University, Sydney.
The application of LaTeX2HTML to the Python documentation has been heavily tailored by Fred L. Drake, Jr. Original navigation icons were contributed by Christopher Petrilli.