[SOLVED] deepcopy problem

In [30]: DOC = "<a><b>spam</b></a>"

In [31]: doc = bindery.parse(DOC)

In [33]: import copy

In [34]: ddoc = copy.deepcopy(doc)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/home/lm/<ipython console> in <module>()

/usr/lib/python2.5/copy.pyc in deepcopy(x, memo, _nil)
    171             copier = getattr(x, "__deepcopy__", None)
    172             if copier:
--> 173                 y = copier(memo)
    174             else:
    175                 reductor = dispatch_table.get(cls)

/usr/lib/python2.5/copy.pyc in deepcopy(x, memo, _nil)
    160     copier = _deepcopy_dispatch.get(cls)
    161     if copier:
--> 162         y = copier(x, memo)
    163     else:
    164         try:

/usr/lib/python2.5/copy.pyc in _deepcopy_tuple(x, memo)
    232     y = []
    233     for a in x:
--> 234         y.append(deepcopy(a, memo))
    235     d = id(x)
    236     try:

/usr/lib/python2.5/copy.pyc in deepcopy(x, memo, _nil)
    160     copier = _deepcopy_dispatch.get(cls)
    161     if copier:
--> 162         y = copier(x, memo)
    163     else:
    164         try:

/usr/lib/python2.5/copy.pyc in _deepcopy_tuple(x, memo)
    232     y = []
    233     for a in x:
--> 234         y.append(deepcopy(a, memo))
    235     d = id(x)
    236     try:

/usr/lib/python2.5/copy.pyc in deepcopy(x, memo, _nil)
    171             copier = getattr(x, "__deepcopy__", None)
    172             if copier:
--> 173                 y = copier(memo)
    174             else:
    175                 reductor = dispatch_table.get(cls)

/home/lm/Projects/testinAmara/lib/python2.5/site-packages/amara/bindery/nodes.pyc in xml_child_inserted(self, child)
    199             exclusions = []
    200             while not name_chosen:
--> 201                 pname = self.factory_entity.xml_pyname(child.xml_namespace, child.xml_local, exclusions)
    202                 existing = getattr(self, pname, None)
    203                 if existing is None or existing.xml_name == child.xml_name:

/home/lm/Projects/testinAmara/lib/python2.5/site-packages/amara/bindery/nodes.pyc in xml_pyname(self, ns, local, parent)
    485         '''
    486         try:
--> 487             python_id = self._names[(local, ns)]
    488         except KeyError:
    489             python_id = str(self.PY_REPLACE_PAT.sub('_', local))

AttributeError: 'entity_base' object has no attribute '_names'

[SOLVED] changing attribute value

DOC = '<a b="spam"><b>spam</b></a>'
EXPECTED = '<a b="eggs"><b>spam</b></a>'
doc = bindery.parse(DOC)
doc.a.xml_attributes[u'b'] = u"eggs"

Traceback (most recent call last):
  File "mutation.py", line 477, in testSetAttribute2
    doc = bindery.parse(DOC)
  File "/home/lm/Projects/testinAmara/lib/python2.5/site-packages/amara/bindery/__init__.py", line 17, in parse
    return tree.parse(obj, uri, entity_factory=entity_factory, standalone=standalone, validate=validate)
  File "/home/lm/Projects/testinAmara/lib/python2.5/site-packages/amara/tree.py", line 33, in parse
    return _parse(inputsource(obj, uri), flags, entity_factory=entity_factory)
  File "/home/lm/Projects/testinAmara/lib/python2.5/site-packages/amara/bindery/nodes.py", line 203, in xml_child_inserted
    if existing is None or existing.xml_name == child.xml_name:
AttributeError: 'unicode' object has no attribute 'xml_name'

[SOLVED] deleting attribute

DOC = '<a b="spam"><b>spam</b></a>'
EXPECTED = '<a><b>spam</b></a>'
doc = bindery.parse(DOC)
del doc.a.b
self.compare_output(doc, XMLDECL+EXPECTED)
return


Traceback (most recent call last):
  File "mutation.py", line 461, in testDelAttribute1
    doc = bindery.parse(DOC)
  File "/home/lm/Projects/testinAmara/lib/python2.5/site-packages/amara/bindery/__init__.py", line 17, in parse
    return tree.parse(obj, uri, entity_factory=entity_factory, standalone=standalone, validate=validate)
  File "/home/lm/Projects/testinAmara/lib/python2.5/site-packages/amara/tree.py", line 33, in parse
    return _parse(inputsource(obj, uri), flags, entity_factory=entity_factory)
  File "/home/lm/Projects/testinAmara/lib/python2.5/site-packages/amara/bindery/nodes.py", line 203, in xml_child_inserted
    if existing is None or existing.xml_name == child.xml_name:
AttributeError: 'unicode' object has no attribute 'xml_name'

[SOLVED] del doc.a[u'b']

del doesn't delete element

from amara import bindery, xml_print
DOC = "<a><b>spam</b><b>eggs</b></a>"
doc = bindery.parse(DOC)
del doc.a[u'b']
print xml_print(doc)

[SOLVED]doc.a.b[0] = u"eggs"

from amara import bindery
DOC = "<a><b>spam</b></a>"
doc = bindery.parse(DOC)
doc.a.b[0] = u"eggs"


Traceback (most recent call last):
  File "test.py", line 4, in <module>
    doc.a.b[0] = u"eggs"
AttributeError: __setitem__

[SOLVED] doc.A.xml_append_fragment(u'<B>\u00AB\u00BB</B>'.encode('latin-1'))

see uche's email at akara-dev

EXPECTED = u'<A><B>\u00AB\u00BB</B></A>'.encode('utf-8')
doc = bindery.nodes.entity_base()
A = doc.xml_element_factory(None, u'A')
doc.xml_append(A)
doc.A.xml_append_fragment(u'<B>\u00AB\u00BB</B>'.encode('latin-1'))


ERROR: testTemplate6 (__main__.TestBasicMods)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "mutation.py", line 247, in testTemplate6
    doc.A.xml_append_fragment(u'<B>\u00AB\u00BB</B>'.encode('latin-1'))
  File "/home/lm/Projects/testinAmara/lib/python2.5/site-packages/amara/bindery/nodes.py", line 248, in xml_append_fragment
    doc = parse(frag)
  File "/home/lm/Projects/testinAmara/lib/python2.5/site-packages/amara/bindery/__init__.py", line 17, in parse
    return tree.parse(obj, uri, entity_factory=entity_factory, standalone=standalone, validate=validate)
  File "/home/lm/Projects/testinAmara/lib/python2.5/site-packages/amara/tree.py", line 33, in parse
    return _parse(inputsource(obj, uri), flags, entity_factory=entity_factory)
  File "/home/lm/Projects/testinAmara/lib/python2.5/site-packages/amara/lib/_inputsource.py", line 45, in __new__
    stream = iri.DEFAULT_RESOLVER.resolve(uri)
  File "/home/lm/Projects/testinAmara/lib/python2.5/site-packages/amara/lib/iri.py", line 1102, in resolve
    uri=uri, msg=str(e))
IriError: Error retrieving resource 'file:///home/lm/Projects/Amara2Tests/bindery/%3CB%3E%AB%BB%3C/B%3E (/home/lm/Projects/Amara2Tests/bindery/<B>\xab\xbb</B>)': [Errno 2] No such file or directory: '/home/lm/Projects/Amara2Tests/bindery/<B>\xab\xbb</B>'

[SOLVED] xml_system_id and xml_public_id

>>> doc = bindery.nodes.entity_base()
>>> doc.xml_system_id = u"http://www.garshol.priv.no/download/xsa/xsa.dtd"
>>> doc.xml_public_id = u"-//LM Garshol//DTD XML Software Autoupdate 1.0//EN//XML"
>>> xml_print(doc)
<?xml version="1.0" encoding="UTF-8"?>
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)

/home/lm/Projects/testinAmara/lib/python2.5/site-packages/amara/writers/_treevisitor.pyc in xml_print(root, stream, encoding, **kwargs)
    255     #    as_html = hasattr(root.ownerDocument or root, 'getElementsByName')
    256     v = visitor(stream, encoding, **kwargs)
--> 257     v.visit(root)
    258     return
    259 

/home/lm/Projects/testinAmara/lib/python2.5/site-packages/amara/writers/_treevisitor.pyc in visit(self, node)
     73             raise ValueError('Unknown node type %r' % node_type)
     74         else:
---> 75             visit(self, node)
     76         return
     77 

/home/lm/Projects/testinAmara/lib/python2.5/site-packages/amara/writers/_treevisitor.pyc in visit_document(self, node)
     98                 if child.xml_type == tree.entity.xml_type:
     99                     break
--> 100             self.printer.doctype(child.xml_qname, node.xml_public_id, node.xml_system_id)
    101         #hasDocTypeNode = False
    102         #if hasattr(node, 'doctype'):

UnboundLocalError: local variable 'child' referenced before assignment

[SOLVED] indexed object doesn't support item deletion

EXPECTED = '<A><B id="1">One</B><B id="2">Two</B></A>'
DOC = EXPECTED
doc = bindery.parse(DOC)
del doc.A.B[1]

ERROR: testReplace (__main__.TestBasicMods)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "mutation.py", line 318, in testReplace
    del doc.A.B[1]
TypeError: 'B' object doesn't support item deletion

LuisMiguel/Testing_bindery (last edited 2009-08-19 16:58:11 by LmMorillas)