Stefan Behnel | 1 Oct 09:12 2009
Picon

Re: Question about lxml.html.builder


Joseph Reagle wrote:
> I'm using Python 2.5.2 with lxml 2.1.1-1ubuntu1.
> 
> I'm trying to get some version of the lines involving 'wp_ps' to work:
> 
>         if opts.text:
>             wp_ps = [E.P(p) for p in bio.wp_text.split('\n')]
>             table.append(
>             E.TR(
>                 E.TD(''),
>                 E.TD().extend(wp_ps),
>                 #E.TD(bio.wp_text, colspan='2'),
>                 E.TD(bio.eb_text, colspan='2'), 
>                 valign="top",
>                 ),
>             )
> 
> Simply, I want to take text with LFs and turn them into Ps.

You didn't mention what isn't working here and how it isn't working the way
you expect.

Anyway, without testing, I'd write it this way:

             table.append(
             E.TR(
                 E.TD(''),

                 E.TD(*[E.P(p) for p in bio.wp_text.split('\n')]),
(Continue reading)

Emanuele D'Arrigo | 1 Oct 13:22 2009
Picon

Re: xpath check, selective xslt

2009/9/29 Stefan Behnel <stefan_ml <at> behnel.de>
... not as good as that. I just checked, and it actually decouples the
element from the rest of the document before running the XSLT. So that
won't help in the case that the XSLT needs to refer to the ancestors.

Darn!
 
I wonder if it would make sense to disable the decoupling for plain
Elements. The problem is that this might break code.

Still, in-context sub-tree transformations doesn't seem to be a conceptually far fetched idea. Is the XSLT standard somehow forbidding it?  If not, I think it'd be worth discussing it with the libxml people.
 
OTOH, I expect little XSLT code to really depend on this,

You are probably right -now-, but if the functionality becomes available I suspect it'd be quickly adopted for all sorts of unforeseen purposes.
 
and it's easy to work around by wrapping the element in an ElementTree object.

I didn't get this. The negatively important thing is that the element is not "in-context" when it's transformed. How would wrapping it in an ElementTree object help?

Manu

_______________________________________________
lxml-dev mailing list
lxml-dev <at> codespeak.net
http://codespeak.net/mailman/listinfo/lxml-dev
Stefan Behnel | 1 Oct 13:39 2009
Picon

Re: xpath check, selective xslt


Emanuele D'Arrigo wrote:
>> OTOH, I expect little XSLT code to really depend on this,
> 
> You are probably right -now-, but if the functionality becomes available I
> suspect it'd be quickly adopted for all sorts of unforeseen purposes.
> 
>> and it's easy to work around by wrapping the element in an ElementTree
>> object.
> 
> I didn't get this. The negatively important thing is that the element is not
> "in-context" when it's transformed. How would wrapping it in an ElementTree
> object help?

I meant the opposite: If we switch the way it works, I don't expect much
code to break, and if it does, it'll be easy to fix by wrapping the element
in an ElementTree object before passing it to the transformer.

I'm not sure how hard this will be to implement, though. I didn't find an
obvious function in libxslt that would take a context/start element in
addition to the document to be transformed, so someone needs to investigate
how libxslt works here (we normally call the xsltApplyStylesheetUser()
function), and what it takes to start the transform from a different node
(e.g. if calling xsltProcessOneNode() works out-of-the-box, or if there is
a setup required beforehand).

Could you file a feature request (i.e. bug) on the bug tracker for now?

Stefan
Joseph Reagle | 1 Oct 18:29 2009
Picon

Re: Question about lxml.html.builder

On Thursday 01 October 2009, Stefan Behnel wrote:
> E.TD(*[E.P(p) for p in bio.wp_text.split('\n')]),

Thanks, that does the trick: you're using *args syntax to "delist" the list and make them arguments? Also,
when I want to add a valign, I note it has to be:

                E.TD(colspan='2', *[E.P(p) for p in bio.wp_text.split('\n')]),

not

                E.TD(*[E.P(p) for p in bio.wp_text.split('\n')], colspan='2'),

though I'm not sure why.
Michael Bayer | 3 Oct 20:12 2009

Re: setuptools issues with python2.6 maint


On Aug 10, 2009, at 3:48 PM, Michael Bayer wrote:

> Stefan Behnel wrote:
>>
>>
>> No idea, never seen this before. I use the same setuptools version  
>> under
>> Py2.6.2, and it works perfectly well.
>>
>> Have you tried the bdist_egg target instead of a mere "install"?
>>
>> Also, the way setuptools patches into distutils makes it quite  
>> possible
>> that newer Python releases introduce incompatibilities, so maybe  
>> there's
>> an
>> issue over there.
>>
>
> I was running build_ext in most cases.  Didn't try bdist_egg.    
> Anyway my
> dependency on that version of python is over for now, so if it is in  
> fact
> an issue with py2.6+, we'll all find out soon enough.   thanks for the
> help.

just an FYI, so now that 2.6.3 is out, more eyes have been on the  
problem and the issue is now described here:

http://tarekziade.wordpress.com/2009/10/03/python-2-6-3-and-distribute/
Stefan Behnel | 5 Oct 09:48 2009
Picon

Re: lxml and xmlsec


Roland Hedberg wrote:
> I need xmlsec and I'd like to use lxml instead of libxml, is it  
> possible ?
> libxml is as it's distributed dependent on libxml, but I don't know  
> how hard it would be to put together a lxmlsec where libxml was  
> exchanged for lxml.

Depending on how much of xmlsec you need, it shouldn't be too hard to wrap
the functionality in Cython and put together a new extension module.
lxml.etree exports the main parts in a public API that should allow you to
get to the libxml2 tree.

The Cython tutorial below has a section on wrapping a C library:

http://sage.math.washington.edu/home/dagss/cython-tutorial-preprint.pdf

> Has anyone done it ?

>From the archives, it looks like John Krukoff should have some experience
with it.

Stefan
Clif Swiggett | 7 Oct 19:45 2009

Text attribute is None when element has text

If I run the code:

    test = etree.XML('<root><a/>text</root>')
    for x in test.iter():
        print("%s - %s"%(x.tag, x.text))

I get the output:

    root - None
    a - None

I expected that root.text would have been 'text' rather than none.
However, if I flip the text and <a/> tag, then it works.  E.g.

    test = etree.XML('<root>text<a/></root>')
    for x in test.iter():
        print("%s - %s"%(x.tag, x.text))

Output:

    root - text
    a - None

Anyone know why this is, or how to work around it?
Thanks!
- Clif
Stefan Behnel | 7 Oct 20:09 2009
Picon

Re: Text attribute is None when element has text


Clif Swiggett wrote:
> If I run the code:
> 
>     test = etree.XML('<root><a/>text</root>')
>     for x in test.iter():
>         print("%s - %s"%(x.tag, x.text))
> 
> I get the output:
> 
>     root - None
>     a - None
> 
> I expected that root.text would have been 'text' rather than none.
> However, if I flip the text and <a/> tag, then it works.  E.g.
> 
>     test = etree.XML('<root>text<a/></root>')
>     for x in test.iter():
>         print("%s - %s"%(x.tag, x.text))
> 
> Output:
> 
>     root - text
>     a - None
> 
> Anyone know why this is, or how to work around it?

Sure, read the docs:

http://codespeak.net/lxml/tutorial.html#elements-contain-text

Stefan
John Krukoff | 7 Oct 20:12 2009

Re: Text attribute is None when element has text

On Wed, 2009-10-07 at 10:45 -0700, Clif Swiggett wrote:
> If I run the code:
> 
>     test = etree.XML('<root><a/>text</root>')
>     for x in test.iter():
>         print("%s - %s"%(x.tag, x.text))
> 
> I get the output:
> 
>     root - None
>     a - None
> 
> I expected that root.text would have been 'text' rather than none.
> However, if I flip the text and <a/> tag, then it works.  E.g.
> 
>     test = etree.XML('<root>text<a/></root>')
>     for x in test.iter():
>         print("%s - %s"%(x.tag, x.text))
> 
> Output:
> 
>     root - text
>     a - None
> 
> Anyone know why this is, or how to work around it?
> Thanks!
> - Clif
> 
> _______________________________________________
> lxml-dev mailing list
> lxml-dev <at> codespeak.net
> http://codespeak.net/mailman/listinfo/lxml-dev

Take a look at the tutorial, especially the "Elements contain text"
section near here:
http://codespeak.net/lxml/tutorial.html#the-element-class

Hopefully that will explain how .text and .tail work for accessing
text. 

The short answer is that your text is in test.find( 'a' ).tail, though.
The itertext method may also be useful for you, depending on your use
case.
--

-- 
John Krukoff <jkrukoff <at> ltgc.com>
Land Title Guarantee Company
John Krukoff | 7 Oct 20:23 2009

Re: lxml and xmlsec

On Tue, 2009-09-29 at 15:59 +0200, Roland Hedberg wrote:
> Hi!
> 
> I need xmlsec and I'd like to use lxml instead of libxml, is it  
> possible ?
> libxml is as it's distributed dependent on libxml, but I don't know  
> how hard it would be to put together a lxmlsec where libxml was  
> exchanged for lxml.
> Has anyone done it ?
> 
> --Roland
> 
> _______________________________________________
> lxml-dev mailing list
> lxml-dev <at> codespeak.net
> http://codespeak.net/mailman/listinfo/lxml-dev

I've gotten the two to work together, but I didn't try anything as hard
as that. I used this set of python bindings for xmlsec:
http://xmlsig.sourceforge.net/

And serialized from lxml and had that library reparse. If I had it to do
over again, I'd try this set of python bindings instead, since I had
crash issues with the first library when errors occured:
http://pyxmlsec.labs.libre-entreprise.org/index.php

It turned out that neither was actually suitable for my use case,
however, as libxmlsec didn't seem to be capable of signing a document
that the .NET 1.1 application I was talking to would accept. I ended up
being forced into creating a .NET service (with it's own dedicated
windows box!) just to handle the signing, as it was the only way I could
interop.
--

-- 
John Krukoff <jkrukoff <at> ltgc.com>
Land Title Guarantee Company

Gmane