diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-04-27 19:53:57 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-04-27 19:53:57 -0400 |
commit | 4b614b9b35cd2baddb7ca67c04bee5d70ec6a172 (patch) | |
tree | 7483cd269f5823f903f96709eb864fff9b6d9383 /examples/elementtree/adjacency_list.py | |
parent | 9716a5c45e6185c5871555722d8495880f0e8c7a (diff) | |
download | sqlalchemy-4b614b9b35cd2baddb7ca67c04bee5d70ec6a172.tar.gz |
- the raw 2to3 run
- went through examples/ and cleaned out excess list() calls
Diffstat (limited to 'examples/elementtree/adjacency_list.py')
-rw-r--r-- | examples/elementtree/adjacency_list.py | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/examples/elementtree/adjacency_list.py b/examples/elementtree/adjacency_list.py index 3b9e4c523..a3ad42778 100644 --- a/examples/elementtree/adjacency_list.py +++ b/examples/elementtree/adjacency_list.py @@ -11,7 +11,7 @@ from sqlalchemy import (MetaData, Table, Column, Integer, String, ForeignKey, Unicode, and_, create_engine) from sqlalchemy.orm import mapper, relationship, Session, lazyload -import sys, os, StringIO, re +import sys, os, io, re from xml.etree import ElementTree @@ -56,7 +56,7 @@ class Document(object): self.element = element def __str__(self): - buf = StringIO.StringIO() + buf = io.StringIO() self.element.write(buf) return buf.getvalue() @@ -120,11 +120,11 @@ class ElementTreeMarshal(object): def __set__(self, document, element): def traverse(node): n = _Node() - n.tag = unicode(node.tag) - n.text = unicode(node.text) - n.tail = unicode(node.tail) + n.tag = str(node.tag) + n.text = str(node.text) + n.tail = str(node.tail) n.children = [traverse(n2) for n2 in node] - n.attributes = [_Attribute(unicode(k), unicode(v)) for k, v in node.attrib.iteritems()] + n.attributes = [_Attribute(str(k), str(v)) for k, v in node.attrib.items()] return n document._root = traverse(element.getroot()) @@ -150,23 +150,23 @@ for file in ('test.xml', 'test2.xml', 'test3.xml'): doc = ElementTree.parse(filename) session.add(Document(file, doc)) -print "\nSaving three documents...", line +print("\nSaving three documents...", line) session.commit() -print "Done." +print("Done.") -print "\nFull text of document 'text.xml':", line +print("\nFull text of document 'text.xml':", line) document = session.query(Document).filter_by(filename="test.xml").first() -print document +print(document) ############################################ PART VI - Searching for Paths ######################### # manually search for a document which contains "/somefile/header/field1:hi" -d = session.query(Document).join('_root', aliased=True).filter(_Node.tag==u'somefile').\ - join('children', aliased=True, from_joinpoint=True).filter(_Node.tag==u'header').\ +d = session.query(Document).join('_root', aliased=True).filter(_Node.tag=='somefile').\ + join('children', aliased=True, from_joinpoint=True).filter(_Node.tag=='header').\ join('children', aliased=True, from_joinpoint=True).filter( - and_(_Node.tag==u'field1', _Node.text==u'hi')).one() -print d + and_(_Node.tag=='field1', _Node.text=='hi')).one() +print(d) # generalize the above approach into an extremely impoverished xpath function: def find_document(path, compareto): @@ -188,11 +188,11 @@ def find_document(path, compareto): return query.options(lazyload('_root')).filter(_Node.text==compareto).all() for path, compareto in ( - (u'/somefile/header/field1', u'hi'), - (u'/somefile/field1', u'hi'), - (u'/somefile/header/field2', u'there'), - (u'/somefile/header/field2[@attr=foo]', u'there') + ('/somefile/header/field1', 'hi'), + ('/somefile/field1', 'hi'), + ('/somefile/header/field2', 'there'), + ('/somefile/header/field2[@attr=foo]', 'there') ): - print "\nDocuments containing '%s=%s':" % (path, compareto), line - print [d.filename for d in find_document(path, compareto)] + print("\nDocuments containing '%s=%s':" % (path, compareto), line) + print([d.filename for d in find_document(path, compareto)]) |