Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81126

Re: Working with HTML5 documents

Path csiph.com!usenet.pasdenom.info!gegeweb.org!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'skip:e 50': 0.05; 'attribute': 0.07; 'detect': 0.07; 'nicely': 0.07; 'ugly': 0.07; 'predefined': 0.09; 'url:github': 0.09; 'way:': 0.09; 'python': 0.11; 'elements,': 0.16; 'factory': 0.16; 'notably': 0.16; 'side.': 0.16; 'typos': 0.16; 'url:py': 0.16; 'wrote:': 0.18; 'module': 0.19; 'stefan': 0.19; 'thu,': 0.19; 'seems': 0.21; '>>>': 0.22; 'import': 0.22; 'creating': 0.23; 'builder': 0.24; 'looks': 0.24; 'source': 0.25; 'header:In-Reply-To:1': 0.27; 'testing': 0.29; 'message-id:@mail.gmail.com': 0.30; '"",': 0.31; 'trivial': 0.31; 'file': 0.32; '(most': 0.33; 'subject:with': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'easily': 0.37; 'nov': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'blank': 0.60; 'ian': 0.60; 'lower': 0.61; 'tag': 0.61; 'simply': 0.61; 'more': 0.64; 'mar': 0.68; '20,': 0.68; 'capital': 0.73; 'saw': 0.77; '2014,': 0.84; 'url:master': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=zzmZBP8fsjr0STwap96kqqNSVLLL991+a6GXyDqDU18=; b=BekaGBb2csxQD11kHAlkdzt/RTgjZZ62D4lIeO3BpIbEiRwDc+yUNSGuOglNI13/lx p3Wnq83gOkgAi49dnkHACPr0SGl+nY3gOnqxhddaXmQDvSNqbs2Sca6Uj1I2XDQRd7ZW bNyGlIyHs9hQ82LrQb0gVf/OXKBfJf4IxlUJ59CFlyTg3LntrvVpz2mELaMjAztc9/CJ OI6uyLVN+QYHeLUK3KSV+tmf5R7AR2YO0tbozDYnEKK7QCLlAvgnVrovpOhpsTyZ82s6 QU8YvW8HRGhftPA2CBG2o3Dckgt5fQKRQ5U0sZav62jh582ZzXqMCTfKHrYl721ooJPc oYNQ==
X-Received by 10.68.175.196 with SMTP id cc4mr403334pbc.147.1416518199530; Thu, 20 Nov 2014 13:16:39 -0800 (PST)
MIME-Version 1.0
In-Reply-To <m4lhr4$odg$1@ger.gmane.org>
References <m4j0rj$vis$1@dont-email.me> <ab8be359-503f-4e0b-b157-66815687923b@googlegroups.com> <m4l6te$vvt$1@dont-email.me> <69c8db11-5928-4978-a0ca-0cd042f0febb@googlegroups.com> <m4ldrg$s1l$1@ger.gmane.org> <CALwzidmFbykm9BPAB-o_4k31_=AKf7qPsVjfw5fCaiB9CR4fFQ@mail.gmail.com> <m4lhr4$odg$1@ger.gmane.org>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Thu, 20 Nov 2014 14:15:59 -0700
Subject Re: Working with HTML5 documents
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16056.1416518201.18130.python-list@python.org> (permalink)
Lines 43
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416518201 news.xs4all.nl 2954 [2001:888:2000:d::a6]:44780
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81126

Show key headers only | View raw


On Thu, Nov 20, 2014 at 1:10 PM, Stefan Behnel <stefan_ml@behnel.de> wrote:
> Ian Kelly schrieb am 20.11.2014 um 20:44:
>> On Thu, Nov 20, 2014 at 12:02 PM, Stefan Behnel wrote:
>>> There's also the E-factory for creating (sub-)trees and a nicely objectish way:
>>>
>>> http://lxml.de/lxmlhtml.html#creating-html-with-the-e-factory
>>
>> That looks ugly with all those caps and also hard to extend. Notably
>> it seems to be missing any functions to build HTML5 elements, unless
>> those have been added in lxml 3.4.
>
> It's actually trivial to extend, and it's designed for it. The factory
> simply uses "__getattr__()", so you can ask it for any tag name. The
> predefined names in the builder.py module are mainly there to easily detect
> typos on user side.

This is not the case from what I saw in my testing based on the documentation.

Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml.html import builder as E
>>> html = E.HTML(E.HEAD(), E.BODY())
>>> html = E.HTML(E.HEAD(), E.BODY(E.ARTICLE()))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'ARTICLE'

> https://github.com/lxml/lxml/blob/master/src/lxml/html/builder.py
>
> If you don't like capital names for constants, just copy the module and
> change the tag names to lower case, or use the blank E-factory if you feel
> like it.

Based on the source file that you linked, I can see that this would
work but is undocumented:

>>> from lxml.builder import ElementMaker
>>> import lxml.html
>>> E = ElementMaker(makeelement=lxml.html.html_parser.makeelement)
>>> html = E.html(E.head(), E.body(E.article()))
>>> lxml.html.tostring(html)
'<html><head></head><body><article></article></body></html>'

Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Working with HTML5 documents Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-19 21:08 +0000
  Re: Working with HTML5 documents Novocastrian_Nomad <gregory.j.baker@gmail.com> - 2014-11-19 13:43 -0800
    Re: Working with HTML5 documents Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-20 17:03 +0000
      Re: Working with HTML5 documents Tim <jtim.arnold@gmail.com> - 2014-11-20 09:31 -0800
        Re: Working with HTML5 documents Stefan Behnel <stefan_ml@behnel.de> - 2014-11-20 20:02 +0100
        Re: Working with HTML5 documents Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-20 12:44 -0700
        Re: Working with HTML5 documents Stefan Behnel <stefan_ml@behnel.de> - 2014-11-20 21:10 +0100
        Re: Working with HTML5 documents Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-20 14:15 -0700

csiph-web