Changeset 3144:e69dbe6b271b in livinglogic.python.xist

Show
Ignore:
Timestamp:
01/17/08 00:50:18 (12 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Fix parser bug. Fix .h file problem. Handle xmlns attribute in pool. Simplify URLAttr/PI interaction.

When parsing attributes that had an empty value, where drop. This is fixed
now.

distutils has dropped helpers.h from the source distributions. Fix this by
renaming the file to helpers_include.c.

Registerung module in a Pool object, now copies the xmlns attribute too (if it
exists and is a string).

"Fancy" URL attributes will now no longer be transformed in any way when
publishing.

Files:
12 modified
1 moved

Legend:

Unmodified
Added
Removed
  • MIGRATION.rst

    r3129 r3144  
     1Migrating to version 3.1 
     2======================== 
     3 
     4Changes to URL handling 
     5----------------------- 
     6 
     7URLs containing processing instructions will no longer be transformed in 
     8any way. If you need the old behaviour you can wrap the initial part of 
     9the attribute value into an :class:`specials.url` PI. 
     10 
     11 
    112Migrating to version 3.0 
    213======================== 
  • MIGRATION.xml

    r3131 r3144  
    11<?xml version='1.0' encoding='iso-8859-1'?> 
     2<section><h>Migrating to version 3.1</h> 
     3 
     4<section><h>Changes to &url; handling</h> 
     5<p>&url;s containing processing instructions will no longer 
     6be transformed in any way. If you need the old behaviour 
     7you can wrap the initial part of the attribute value into 
     8an <class>specials.url</class> PI.</p> 
     9</section> 
     10 
     11</section> 
     12 
     13 
    214<section><h>Migrating to version 3.0</h> 
    315 
  • NEWS.rst

    r3142 r3144  
    11History 
    22======= 
     3 
     4 
     5Changes in 3.1 (released 01/18/2008) 
     6------------------------------------ 
     7 
     8*   Added missing source file ``helpers_include.c`` to the source distributions. 
     9 
     10*   If an :class:`URLAttr` attribute contains a processing instruction XIST will 
     11    no longer transform the URL in any way. 
     12 
     13*   Fixed a parser bug, where attributes where dropped when the attribute value 
     14    was empty. 
     15 
     16*   Putting a module into a :class:`Pool` object now copies the ``xmlns`` attribute 
     17    too. This makes it possible to use :class:`Pool` objects as conversion targets. 
    318 
    419 
  • NEWS.xml

    r3143 r3144  
    11<?xml version='1.0' encoding='utf-8'?> 
     2<section><h>Changes in 3.1 (released 01/18/2008)</h> 
     3<ul> 
     4<li>Added missing source file <filename>helpers_include.c</filename> to 
     5the source distributions.</li> 
     6<li>If an <class>URLAttr</class> attribute contains a processing instruction 
     7&xist; will no longer transform the &url; in any way.</li> 
     8<li>Fixed a parser bug, where attributes where dropped when the attribute 
     9value was empty.</li> 
     10<li>Putting a module into a <class>Pool</class> object now copies the 
     11<lit>xmlns</lit> attribute too. This makes it possible to use <class>Pool</class> 
     12objects as conversion targets.</li> 
     13</ul> 
     14</section> 
     15 
     16 
    217<section><h>Changes in 3.0 (released 01/07/2008)</h> 
    318<ul> 
  • setup.py

    r3136 r3144  
    6060args = dict( 
    6161    name="ll-xist", 
    62     version="3.0", 
     62    version="3.1", 
    6363    description="An extensible HTML/XML generator", 
    6464    long_description=description, 
     
    7373    packages=["ll", "ll.xist", "ll.xist.ns", "ll.xist.scripts"], 
    7474    ext_modules=[ 
    75         tools.Extension("ll.xist.helpers", ["src/ll/xist/helpers.c"]), 
     75        tools.Extension("ll.xist.helpers", ["src/ll/xist/helpers.c", "src/ll/xist/helpers_include.c"]), 
    7676        tools.Extension("ll.xist.sgmlop", ["src/ll/xist/sgmlop.c"], define_macros=[("SGMLOP_UNICODE_SUPPORT", None)]), 
    7777    ], 
  • src/ll/xist/helpers.c

    r3080 r3144  
    2727#define STRINGLIB_STR  PyUnicode_AS_UNICODE 
    2828 
    29 #include "helpers.h" 
     29#include "helpers_include.c" 
    3030 
    3131#undef STRINGLIB_NAME 
     
    4343#define STRINGLIB_STR PyString_AS_STRING 
    4444 
    45 #include "helpers.h" 
     45#include "helpers_include.c" 
    4646 
    4747#undef STRINGLIB_NAME 
  • src/ll/xist/helpers_include.c

    r3080 r3144  
    99 
    1010 
     11#ifdef STRINGLIB_NAME 
    1112static PyObject *STRINGLIB_NAME(PyObject *str, Py_ssize_t inattr) 
    1213{ 
     
    113114    } 
    114115} 
     116#endif 
  • src/ll/xist/ns/doc.py

    r3128 r3144  
    5454    roles.register_generic_role("const", nodes.literal) 
    5555    en.roles["const"] = "const" 
     56 
     57    roles.register_generic_role("file", nodes.literal) 
     58    en.roles["file"] = "file" 
     59 
     60    roles.register_generic_role("dir", nodes.literal) 
     61    en.roles["dir"] = "dir" 
     62 
     63    roles.register_generic_role("data", nodes.literal) 
     64    en.roles["data"] = "data" 
    5665 
    5766import ll 
     
    16721681    defaults["tab_width"] = 3 
    16731682    defaults["pep_references"] = 1 
     1683    defaults["pep_base_url"] = "http://www.python.org/dev/peps/" 
    16741684    defaults["rfc_references"] = 1 
     1685    defaults["rfc_base_url"] = "http://www.faqs.org/rfcs/" 
    16751686 
    16761687    doc = utils.new_document("?", optparse.Values(defaults)) 
  • src/ll/xist/parsers.py

    r3131 r3144  
    547547 
    548548    def handle_leaveattr(self, name, line, col): 
    549         self._nesting.pop() 
     549        (node, prefixes) = self._nesting.pop() 
     550        # if the attribute was empty, ``handle_data`` is newer called, so we have to add an empty text node, to prevent the attribute from disappearing 
     551        if not node: 
     552            node.append("") 
    550553 
    551554    def handle_leavestarttag(self, name, line, col): 
  • src/ll/xist/utils.py

    r3128 r3144  
    3838            return content[startpos:endpos] 
    3939    return None 
    40  
    41  
    42 def replaceInitialURL(frag, callback): 
    43     """ 
    44     This function replaces to the text nodes of a fragment, 
    45     which will be interpreted as an URL with another URL. All 
    46     text nodes up to the first non text node are converted to a 
    47     URL. This URL will be passed to the callback and the result 
    48     will be put in into the frag instead of the old text nodes. 
    49     """ 
    50     newfrag = xsc.Frag() 
    51     if len(frag): 
    52         for i in xrange(len(frag)): 
    53             v = frag[i] 
    54             if isinstance(v, xsc.Text): 
    55                 newfrag.append(v) 
    56             else: 
    57                 break 
    58         else: 
    59             i += 1 
    60         if len(newfrag): # do the replacement only if we have something static 
    61             u = url_.URL(unicode(newfrag).lstrip()) 
    62             u = callback(u) 
    63             newfrag = xsc.Frag(u.url) 
    64         while i < len(frag): 
    65             newfrag.append(frag[i]) 
    66             i += 1 
    67     return newfrag 
  • src/ll/xist/xsc.py

    r3131 r3144  
    21812181 
    21822182    def parsed(self, parser, start=None): 
    2183         return self.__class__(utils.replaceInitialURL(self, lambda u: parser.base/u)) 
     2183        return self.__class__(url_.URL(parser.base/unicode(self))) 
    21842184 
    21852185    def _publishattrvalue(self, publisher): 
    2186         new = utils.replaceInitialURL(self, lambda u: u.relative(publisher.base)) 
    2187         for part in new.publish(publisher): 
    2188             yield part 
     2186        if self.isfancy(): 
     2187            return Attr._publishattrvalue(self, publisher) 
     2188        else: 
     2189            new = Attr(url_.URL(unicode(self)).relative(publisher.base)) 
     2190            return new._publishattrvalue(publisher) 
    21892191 
    21902192    def asURL(self): 
     
    21942196        """ 
    21952197        return url_.URL(Attr.__unicode__(self)) 
    2196  
    2197     def __unicode__(self): 
    2198         return self.asURL().url 
    21992198 
    22002199    def forInput(self, root=None): 
     
    34333432        values will be registered, this makes it possible to e.g. register all 
    34343433        local variables by passing <lit>vars()</lit>);</li> 
    3435         <li>A module (all <class>Node</class> classes in the 
    3436         module will be registered);</li> 
     3434        <li>A module (all <class>Node</class> classes and the <lit>xmlns</lit> attribute 
     3435        if it's a string) in the module will be registered);</li> 
    34373436        </ul> 
    34383437        """ 
     
    34663465                if isinstance(value, type): # This avoids recursive module registration 
    34673466                    self.register(value) 
     3467                elif key == "xmlns" and type(value) is str: 
     3468                    self.xmlns = value 
    34683469        elif isinstance(object, dict): 
    34693470            super(Pool, self).register(object) 
  • test/test_parse.py

    r3080 r3144  
    271271    assert isinstance(e[0], specials.z) 
    272272    py.test.raises(xsc.IllegalElementError, parsers.parsestring, s, pool=xsc.Pool()) 
     273 
     274def test_parseemptyattribute(): 
     275    e = parsers.parsestring("<a target=''/>", pool=xsc.Pool(html)) 
     276    assert "target" in e[0].attrs 
  • test/test_url.py

    r3080 r3144  
    1313 
    1414from ll.xist import xsc, parsers 
    15 from ll.xist.ns import specials 
     15from ll.xist.ns import specials, html, jsp 
    1616 
    1717 
     
    1919    node = parsers.parsestring("<?url root:images/gurk.gif?>") 
    2020    assert node.bytes(base="root:about/us.html") == "../images/gurk.gif" 
     21 
     22    node = parsers.parsestring('<img src="root:images/gurk.gif"/>') 
     23    assert node.bytes(base="root:about/us.html") == '<img src="../images/gurk.gif" />' 
     24 
     25 
     26def test_fancyurl():     
     27    node = html.a("gurk", href=("http://", jsp.expression("server"))) 
     28    assert node.bytes(base="root:about/us.html") == '<a href="http://<%= server %>">gurk</a>'