diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-02 14:23:42 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-01-02 14:23:42 -0500 |
| commit | 350aed3fdb9f1e73e69655e53f44ca6a91c196da (patch) | |
| tree | 3d2a128667b5f6ca6d0b4e1f4865fc98aac6b60b /examples/elementtree | |
| parent | 71f92436bdc86f30e2c21d8f5244733601e8c39e (diff) | |
| download | sqlalchemy-350aed3fdb9f1e73e69655e53f44ca6a91c196da.tar.gz | |
- whitespace removal bonanza
Diffstat (limited to 'examples/elementtree')
| -rw-r--r-- | examples/elementtree/__init__.py | 6 | ||||
| -rw-r--r-- | examples/elementtree/optimized_al.py | 18 | ||||
| -rw-r--r-- | examples/elementtree/pickle.py | 6 |
3 files changed, 15 insertions, 15 deletions
diff --git a/examples/elementtree/__init__.py b/examples/elementtree/__init__.py index 33805c0cb..8d47f4ace 100644 --- a/examples/elementtree/__init__.py +++ b/examples/elementtree/__init__.py @@ -21,15 +21,15 @@ In order of complexity: the load in a non-recursive fashion and is much more efficient. E.g.:: - + # parse an XML file and persist in the database doc = ElementTree.parse("test.xml") session.add(Document(file, doc)) session.commit() - + # locate documents with a certain path/attribute structure for document in find_document('/somefile/header/field2[@attr=foo]'): # dump the XML print document - + """
\ No newline at end of file diff --git a/examples/elementtree/optimized_al.py b/examples/elementtree/optimized_al.py index d6110a132..102f6c373 100644 --- a/examples/elementtree/optimized_al.py +++ b/examples/elementtree/optimized_al.py @@ -18,8 +18,8 @@ e = create_engine('sqlite://', echo=True) meta = MetaData() ####################### PART II - Table Metadata ############################# - -# stores a top level record of an XML document. + +# stores a top level record of an XML document. documents = Table('documents', meta, Column('document_id', Integer, primary_key=True), Column('filename', String(30), unique=True), @@ -48,12 +48,12 @@ meta.create_all(e) ########################### PART III - Model ################################# # our document class. contains a string name, -# and the ElementTree root element. +# and the ElementTree root element. class Document(object): def __init__(self, name, element): self.filename = name self.element = element - + def __str__(self): buf = StringIO.StringIO() self.element.write(buf) @@ -101,10 +101,10 @@ class ElementTreeMarshal(object): def __get__(self, document, owner): if document is None: return self - + if hasattr(document, '_element'): return document._element - + nodes = {} root = None for node in document._nodes: @@ -120,10 +120,10 @@ class ElementTreeMarshal(object): elem.attrib[attr.name] = attr.value elem.text = node.text elem.tail = node.tail - + document._element = ElementTree.ElementTree(root) return document._element - + def __set__(self, document, element): def traverse(node): n = _Node() @@ -137,7 +137,7 @@ class ElementTreeMarshal(object): traverse(element.getroot()) document._element = element - + def __delete__(self, document): del document._element document._nodes = [] diff --git a/examples/elementtree/pickle.py b/examples/elementtree/pickle.py index 5e53e6798..28bee4672 100644 --- a/examples/elementtree/pickle.py +++ b/examples/elementtree/pickle.py @@ -22,7 +22,7 @@ meta = MetaData() def are_elements_equal(x, y): return x == y -# stores a top level record of an XML document. +# stores a top level record of an XML document. # the "element" column will store the ElementTree document as a BLOB. documents = Table('documents', meta, Column('document_id', Integer, primary_key=True), @@ -33,7 +33,7 @@ documents = Table('documents', meta, meta.create_all(e) # our document class. contains a string name, -# and the ElementTree root element. +# and the ElementTree root element. class Document(object): def __init__(self, name, element): self.filename = name @@ -47,7 +47,7 @@ mapper(Document, documents) # get ElementTree document filename = os.path.join(os.path.dirname(__file__), "test.xml") doc = ElementTree.parse(filename) - + # save to DB session = Session(e) session.add(Document("test.xml", doc)) |
