Giter Club home page Giter Club logo

zepheira / amara Goto Github PK

View Code? Open in Web Editor NEW
23.0 23.0 9.0 3.25 MB

Amara 2.0. Amara XML toolkit is an open-source collection of Python tools for XML processing, not just tools that happen to be written in Python, but tools built from the ground up to use Python idioms and take advantage of the many advantages of Python over other programming languages.

Home Page: http://wiki.xml3k.org/Amara2

License: Apache License 2.0

Python 33.88% XSLT 8.95% C 41.13% C++ 1.85% Shell 0.06% Objective-C 0.59% JavaScript 0.42% GLSL 0.11% HTML 13.01% Logos 0.01%

amara's People

Contributors

akuchling avatar dabeaz avatar distobj avatar juanc1to avatar lmorillas avatar uogbuji avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

amara's Issues

<xsl:variable> doesn't work on RHEL4

Below are the contents of files test.py and test.xsl. The script (test.py) works with python 2.6 installed on RHEL5 but it doesn't work on RHEL4 with python 2.6.

######### test.py

from amara.xslt import transform

html = '

Hello World

'
html = transform(html, "test.xsl")
print html

##### test.xsl

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:fn="http://www.w3.org/2005/xpath-functions">

<xsl:output omit-xml-declaration="yes" indent="yes"
encoding="ISO-8859-1"/>

<xsl:template name="decode">
<xsl:variable name="c1" select="string('Hello Pankaj')"/>
<xsl:value-of select="$c1"/>
/xsl:template

<xsl:template match="p">
xsl:copy
<xsl:call-template name="decode"/>
/xsl:copy
/xsl:template

<xsl:template match="@|node()">
xsl:copy
<xsl:apply-templates select="@
|node()"/>
/xsl:copy
/xsl:template

/xsl:stylesheet

KeyError when handling errors

When I hit an error in an XSL transform, amara triggers a KeyError while attempting to handle the error, giving the following traceback:

File "/Library/Python/2.6/site-packages/amara/xslt/tree/attribute_types.py", line 457, in prepare
col=element.columnNumber, msg=str(error))
File "/Library/Python/2.6/site-packages/amara/init.py", line 29, in init
message %= kwds
KeyError: 'text'

RuntimeError from XPath union expression

Pretty simple. I tried to do the following:

import amara 

RDFA11_EXAMPLE = """\
<div vocab="http://schema.org/"
     typeof="Person">
  <span property="name">Manu Sporny</span>
  <img rel="image" src="manu.jpg" />

  <span property="jobTitle">CEO</span>

  <div rel="address">
    <span property="streetAddress">
     1700 Kraft Drive, Suite 2408
    </span>
    ...
  </div>

  <a rel="url"
     href="http://manu.sporny.org/">
       manu.sporny.org
  </a>
</div>
"""

doc = amara.parse(RDFA11_EXAMPLE)
doc.xml_select(u'//*[@property|@resource|@rel]')

Throws the following exception:

Traceback (most recent call last):
  File "/tmp/foo.py", line 26, in <module>
    doc.xml_select(u'//*[@property|@resource|@rel]')
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/util.py", line 52, in simple_evaluate
    return ctx.evaluate(expr)
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/__init__.py", line 224, in evaluate
    return parsed.evaluate(self)
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/expressions/__init__.py", line 65, in evaluate
    return self.evaluate(context)
  File "<ast-0>", line 0, in evaluate
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 159, in _boolean
    for node in nodes:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 159, in _boolean
    for node in nodes:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 159, in _boolean
    for node in nodes:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 159, in _boolean
    for node in nodes:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 159, in _boolean
    for node in nodes:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 159, in _boolean
    for node in nodes:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 159, in _boolean
    for node in nodes:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 159, in _boolean
    for node in nodes:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 161, in _boolean
    if expr.evaluate_as_boolean(context):
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/expressions/__init__.py", line 70, in evaluate_as_boolean
    self.compile_as_boolean(compiler)
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/expressions/nodesets.py", line 155, in compile_as_boolean
    path.compile_as_boolean(compiler)
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/expressions/nodesets.py", line 78, in compile_as_boolean
    return self._make_loop(compiler, found, empty)
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/expressions/nodesets.py", line 44, in _make_loop
    for block in self._make_block(compiler):
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/expressions/nodesets.py", line 24, in _make_block
    'LOAD_ATTR', 'size',
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/compiler/assembler.py", line 41, in emit
    for opname in instructions:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 159, in _boolean
    for node in nodes:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 159, in _boolean
    for node in nodes:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 159, in _boolean
    for node in nodes:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 159, in _boolean
    for node in nodes:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 159, in _boolean
    for node in nodes:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 159, in _boolean
    for node in nodes:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 159, in _boolean
    for node in nodes:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 159, in _boolean
    for node in nodes:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 159, in _boolean
    for node in nodes:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 161, in _boolean
    if expr.evaluate_as_boolean(context):
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/expressions/__init__.py", line 70, in evaluate_as_boolean
    self.compile_as_boolean(compiler)
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/expressions/nodesets.py", line 155, in compile_as_boolean
    path.compile_as_boolean(compiler)
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/expressions/nodesets.py", line 78, in compile_as_boolean
    return self._make_loop(compiler, found, empty)
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/expressions/nodesets.py", line 44, in _make_loop
    for block in self._make_block(compiler):
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/expressions/nodesets.py", line 24, in _make_block
    'LOAD_ATTR', 'size',
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/compiler/assembler.py", line 41, in emit
    for opname in instructions:
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/locationpaths/predicates.py", line 161, in _boolean
    if expr.evaluate_as_boolean(context):
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/expressions/__init__.py", line 72, in evaluate_as_boolean
    docstring=unicode(self))
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/compiler/__init__.py", line 45, in compile
    firstlineno)
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/compiler/assembler.py", line 60, in assemble
    stacksize = self._compute_stack_size()
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/compiler/assembler.py", line 202, in _compute_stack_size
    return walk(self.entry, 0, 0)
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/compiler/assembler.py", line 192, in walk
    maxsize = walk(instr.target, size, maxsize)
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/compiler/assembler.py", line 198, in walk
    maxsize = walk(block.next, size, maxsize)
  File "/Users/uche/.local/lib/python2.7/site-packages/amara/xpath/compiler/assembler.py", line 187, in walk
    raise RuntimeError("unhandled instruction: %r" % instr)
RuntimeError: unhandled instruction: <instr at 0x10b236940: opname='<block 1, offset 0>', oparg=None, target=None>

This only seems to happen when the union expression is used. You can do any of the following without the error:

  • doc.xml_select(u'//*[@property]')
  • doc.xml_select(u'//*[@resource]')
  • doc.xml_select(u'//*[@rel]')

But any combination of 2 of the attributes in a union expression does trigger the exception.

python 3 or pypy support

I need to migrate to either pypy or python 3 after Jan 2020. Any ideas for a good migration path for a python2 project that uses akara and needs to be migrated?

structwriter memory leak (originally reported by Chimezie)

See: http://groups.google.com/group/akara/browse_thread/thread/61c3dfdee4e9301b

An example template that causes the problem (with a sequence of very large files) is below. It uses pushtree to stream elements to structwriter

def main(..etc..):
..snip..
w = structwriter(indent=u"yes",stream=someStream)
feed = w.cofeed(
ROOT(
E_CURSOR(
(RDF.RDFNS, u'rdf:RDF'))))
handler = Handle(feed,..etc..)
@coroutine
def receive_nodes(..etc..):
while True:
node = yield
handler.handle(node..,..etc..)
return
target = receive_nodes(..etc..)
pushtree(doc, u'MedlineCitation', target.send,
entity_factory=entity_base)
handler.feed.close()
target.close()
return someStream.getvalue()

Problems with common/psi.xsl of docbook xsl (docbook-xsl-1.78.1)

The traceback I receive (after a print statement in order to track which of the stylesheets in the import chain is currently being parsed) using a simple input document and running transform:

<?xml version='1.0'?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="docbook-xsl-1.78.1/fo/docbook.xsl"/>
<xsl:attribute-set name="section.title.properties">
<xsl:attribute name="text-align">center/xsl:attribute
</xsl:attribute-set>
<xsl:attribute-set name="informaltable.properties">
<xsl:attribute name="font-size">8pt/xsl:attribute
<xsl:attribute name="width">100%/xsl:attribute
</xsl:attribute-set>
</xsl:stylesheet>

<amara.lib._inputsource._inputsource object at 0x102bfc6e0> file:///Users/chimezieogbuji/Projects/MetacognitionLLC/HomeHealthCare/stylus-eater-metacognition/hha-portal/docbook/docbook-xsl-1.78.1/common/pi.xsl
Traceback (most recent call last):
[..snip..]
File "/Library/Python/2.6/site-packages/amara/xslt/init.py", line 516, in transform
proc.append_transform(inputsource(transforms))
File "/Library/Python/2.6/site-packages/amara/xslt/processor.py", line 210, in append_transform
self.transform = self._reader.parse(source)
File "/Library/Python/2.6/site-packages/amara/xslt/reader/init.py", line 861, in parse
stylesheet = self._parseSrc(source, features, properties)
File "/Library/Python/2.6/site-packages/amara/xslt/reader/init.py", line 885, in _parseSrc
parser.parse(isrc)
File "lib/src/expat/sax_handler.c", line 306, in StartElement
File "/Library/Python/2.6/site-packages/amara/xslt/reader/init.py", line 456, in startElementNS
self._combine_stylesheet(instance, (local == 'import'))
File "/Library/Python/2.6/site-packages/amara/xslt/reader/init.py", line 687, in _combine_stylesheet
self.parse(new_source)
File "/Library/Python/2.6/site-packages/amara/xslt/reader/init.py", line 861, in parse
stylesheet = self._parseSrc(source, features, properties)
File "/Library/Python/2.6/site-packages/amara/xslt/reader/init.py", line 885, in _parseSrc
parser.parse(isrc)
File "lib/src/expat/sax_handler.c", line 306, in StartElement
File "/Library/Python/2.6/site-packages/amara/xslt/reader/init.py", line 456, in startElementNS
self._combine_stylesheet(instance, (local == 'import'))
File "/Library/Python/2.6/site-packages/amara/xslt/reader/init.py", line 687, in _combine_stylesheet
self.parse(new_source)
File "/Library/Python/2.6/site-packages/amara/xslt/reader/init.py", line 861, in parse
stylesheet = self._parseSrc(source, features, properties)
File "/Library/Python/2.6/site-packages/amara/xslt/reader/init.py", line 885, in _parseSrc
parser.parse(isrc)
File "lib/src/expat/sax_handler.c", line 306, in StartElement
File "/Library/Python/2.6/site-packages/amara/xslt/reader/init.py", line 426, in startElementNS
value = attr_info.prepare(instance, value)
File "/Library/Python/2.6/site-packages/amara/xslt/tree/attribute_types.py", line 485, in prepare
return parse_xpattern(value)
File "", line 1
error: syntax error at line 1, column 38: unexpected $undefined., expecting Literal or )

Unable to install 4Suite-XML while installing amara.

(PWPYTHON)ubuntu@ip-10-85-141-174:~$ pip install amara
Requirement already satisfied (use --upgrade to upgrade): amara in ./PWPYTHON/lib/python2.7/site-packages
Downloading/unpacking 4Suite-XML>=1.0.2 (from amara)
  Downloading 4Suite-XML-1.0.2.zip (2.2MB): 2.2MB downloaded
  Running setup.py egg_info for package 4Suite-XML

Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /usr/lib/python2.7/dist-packages (from amara)
Installing collected packages: 4Suite-XML
  Running setup.py install for 4Suite-XML
    Usage:
      -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
      -c --help [cmd1 cmd2 ...]
      -c cmd --help
      -c --help-commands
      -c --help-packages

    error: option --single-version-externally-managed not recognized
    Complete output from command /home/ubuntu/PWPYTHON/bin/python -c "import setuptools;__file__='/home/ubuntu/PWPYTHON/build/4Suite-XML/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-wplyzB-record/install-record.txt --single-version-externally-managed --install-headers /home/ubuntu/PWPYTHON/include/site/python2.7:
    Usage:

  -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]

  -c --help [cmd1 cmd2 ...]

  -c cmd --help

  -c --help-commands

  -c --help-packages



error: option --single-version-externally-managed not recognized

----------------------------------------
Cleaning up...
Command /home/ubuntu/PWPYTHON/bin/python -c "import setuptools;__file__='/home/ubuntu/PWPYTHON/build/4Suite-XML/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-wplyzB-record/install-record.txt --single-version-externally-managed --install-headers /home/ubuntu/PWPYTHON/include/site/python2.7 failed with error code 1 in /home/ubuntu/PWPYTHON/build/4Suite-XML
Storing complete log in /home/ubuntu/.pip/pip.log

This is what i get when i say pip install amara.

Does amara have any dependency on 4Suite-XML ?

Try out OmniJSON for amara's JSON inclusion logic

Amara includes logic to try to find and provide a JSON library, but it's not as well-studied as other alternatives such as AnyJSON and OmniJSON. The latter has the advantage of bundling Ippolito's simplejson for a built-in default. OmniJSON is also designed to be "vendorizable," meaning it should be easy to bundle in thirdparty, or we could also just include it in the setup.py prerequisites.

Amara 2.0.0_alpha6 XML bindery leaks memory

bindery.parse(...) leaks roughly 200x more memory than the size of the XML document that it's parsing. A 1KB document leaks about 200KB of RAM, which quickly adds up for long running processes performing repeated parsing.

In addition, each parse(...) call adds un-collectable objects to Python's variable reference tracking system, and adds O(1) CPU processing time overhead - perhaps because of the ever-growing reference-tracking load.

How to reproduce:

Python 2.7.6 (default, May  7 2014, 07:34:22) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gc 
>>> len(gc.get_objects())
3803
>>> from amara import bindery
>>> len(gc.get_objects())
12113
>>> bindery.parse(open('test.xml'))
<entity at 0xb2ee60: 1 children>
>>> len(gc.get_objects())
12285
>>> bindery.parse(open('test.xml'))
<entity at 0xbed710: 1 children>
>>> len(gc.get_objects())
12832
>>> bindery.parse(open('test.xml'))
<entity at 0xbf6f80: 1 children>
>>> len(gc.get_objects())
12764
>>> bindery.parse(open('test.xml'))
<entity at 0xbf6050: 1 children>
>>> len(gc.get_objects())
13297
>>> bindery.parse(open('test.xml'))
<entity at 0xbf3830: 1 children>
>>> len(gc.get_objects())
13229
>>> bindery.parse(open('test.xml'))
<entity at 0xbf37a0: 1 children>
>>> len(gc.get_objects())
13762
>>> bindery.parse(open('test.xml'))
<entity at 0xcd60e0: 1 children>
>>> len(gc.get_objects())
13707
>>> bindery.parse(open('test.xml'))
<entity at 0xbf6050: 1 children>
>>> len(gc.get_objects())
14240

Compare this to a well behaved parser:

Python 2.7.6 (default, May  7 2014, 07:34:22) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gc
>>> import xml.etree.cElementTree as ET
>>> len(gc.get_objects())
4289
<Element '{http://www.w3.org/2005/Atom}feed' at 0x7fa03a0197b0>
3849
>>> ET.parse(open('test.xml')).getroot(); len(gc.get_objects())
<Element '{http://www.w3.org/2005/Atom}feed' at 0x7fa03a019e10>
3849
>>> ET.parse(open('test.xml')).getroot(); len(gc.get_objects())
<Element '{http://www.w3.org/2005/Atom}feed' at 0x7fa03a019990>
3849
>>> ET.parse(open('test.xml')).getroot(); len(gc.get_objects())
<Element '{http://www.w3.org/2005/Atom}feed' at 0x7fa03a019ed0>
3849
>>> ET.parse(open('test.xml')).getroot(); len(gc.get_objects())
<Element '{http://www.w3.org/2005/Atom}feed' at 0x7fa03a019870>
3849
>>> ET.parse(open('test.xml')).getroot(); len(gc.get_objects())
<Element '{http://www.w3.org/2005/Atom}feed' at 0x7fa03a019a20>
3849
>>> ET.parse(open('test.xml')).getroot(); len(gc.get_objects())
<Element '{http://www.w3.org/2005/Atom}feed' at 0x7fa03a019db0>
3849
>>> ET.parse(open('test.xml')).getroot(); len(gc.get_objects())
<Element '{http://www.w3.org/2005/Atom}feed' at 0x7fa03a019ae0>
3849
>>> 

EXSLT dates-and-times seems to be broken

I want to use the date xslt extension for some xml/xslt transformations but the implementation seems to be broken.
I use this test file to check if the date functions work:

from amara.xslt import transform

XML_DOC = """<?xml version="1.0"?>
<durations>
    <duration>P4Y8MT7H</duration>
    <duration>P17Y1MT2H</duration>
    <duration>P1Y2MT2H</duration>
</durations>"""
XSL_STYLESHEET = """<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates-and-times">
<xsl:output method="html" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<out>
    <datetime><xsl:value-of select="date:date-time()"/></datetime>
    <date><xsl:value-of select="date:date('2000-01-02T03:04:05Z')"/></date>
    <time><xsl:value-of select="date:time('2000-01-02T03:04:05Z')"/></time>
    <year><xsl:value-of select="date:year('2000-01-02T03:04:05Z')"/></year>
    <leapyear><xsl:value-of select="date:leap-year('2000-01-02T03:04:05Z')"/></leapyear>
    <monthinyear><xsl:value-of select="date:month-in-year('2000-01-02T03:04:05Z')"/></monthinyear>
    <monthname><xsl:value-of select="date:month-name('2000-01-02T03:04:05Z')"/></monthname>
    <monthabbreviation><xsl:value-of select="date:month-abbreviation('2000-01-02T03:04:05Z')"/></monthabbreviation>
    <weekinyear><xsl:value-of select="date:week-in-year('2000-01-02T03:04:05Z')"/></weekinyear>
    <dayinyear><xsl:value-of select="date:day-in-year('2000-01-02T03:04:05Z')"/></dayinyear>
    <dayinmonth><xsl:value-of select="date:day-in-month('2000-01-02T03:04:05Z')"/></dayinmonth>
    <dayofweekinmonth><xsl:value-of select="date:day-of-week-in-month('2000-01-02T03:04:05Z')"/></dayofweekinmonth>
    <dayinweek><xsl:value-of select="date:day-in-week('2000-01-02T03:04:05Z')"/></dayinweek>
    <dayname><xsl:value-of select="date:day-name('2000-01-02T03:04:05Z')"/></dayname>
    <dayabbreviation><xsl:value-of select="date:day-abbreviation('2000-01-02T03:04:05Z')"/></dayabbreviation>
    <hourinday><xsl:value-of select="date:hour-in-day('2000-01-02T03:04:05Z')"/></hourinday>
    <minuteinhour><xsl:value-of select="date:minute-in-hour('2000-01-02T03:04:05Z')"/></minuteinhour>
    <secondinminute><xsl:value-of select="date:second-in-minute('2000-01-02T03:04:05Z')"/></secondinminute>
    <formatdate><xsl:value-of select="date:format-date('2000-01-02T03:04:05Z', 'EEE, d MMM yyyy HH:mm:ss')"/></formatdate>
    <weekinmonth><xsl:value-of select="date:week-in-month('2000-01-02T03:04:05Z')"/></weekinmonth>
    <difference><xsl:value-of select="date:difference('2000-01-01T00:00:00Z', '2000-01-02T03:04:05Z')"/></difference>
    <add><xsl:value-of select="date:add('2000-01-02T03:04:05Z', 'P1DT1H1M1S')"/></add>
    <addduration><xsl:value-of select="date:add-duration('P4DT4H4M4S', 'P1DT2H3M4S')"/></addduration>
    <sum><xsl:value-of select="date:sum(//duration)"/></sum>
    <seconds><xsl:value-of select="date:seconds('2000-01-02T03:04:05Z')"/></seconds>
    <duration><xsl:value-of select="date:duration('93784')"/></duration>
</out>
</xsl:template>
</xsl:stylesheet>"""

print transform(XML_DOC, XSL_STYLESHEET)

Runing this file fails with a stack trace. It seems like the implementation in amara/xslt/exslt/datetime.py is broken (missing imports,...).
Did I do something wrong or can somebody else confirm this?

pushtree memory leak

As reported by Mark Baker originally:

I observed a memory leak with a pushtree based parser I was writing, and reduced the problem [with a test program]. After letting it run for a little while in pdb, objgraph showed this;

(Pdb) objgraph.show_most_common_types(limit=5)
text 1476636
element 870756
comment 465962
tuple 12205
function 3119

from amara.pushtree import pushtree

def blah(r):
pass

data = open("bigfile.xml","r")
pushtree(data,'RECORD',blah)

For more info please see: https://foundry.zepheira.com/issues/1294

XPath last() function fails

XPath last() function doesn't return the last item of a nodeset. When last() function is used in xpath expressions, the result is allways an empty nodeset.

See the test of the test suite:

xml file tests/xslt/borrowed/dh_20000530_01.xml

<nodes>
  <node>a</node>
  <node>b</node>
  <node>c</node>
</nodes>

amara code

 >>> doc = amara.parse('dh_20000530_01.xml')
 >>> doc.xml_select(u'/nodes/node[last()]')
 nodeset()
 >>> doc.xml_select(u'/nodes/node')
 nodeset([<amara.tree.element at 0x236c2d0: name u'node', 0 namespaces, 0 attributes, 1 children>, 
                <amara.tree.element at  0x236c4d0: name u'node', 0 namespaces, 0 attributes, 1 children>, 
                <amara.tree.element at 0x236c9d0: name u'node', 0 namespaces, 0 attributes, 1 children>])

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.