Passing indented code to compile()

Bengt Richter bokr at oz.net
Wed May 7 17:56:04 EDT 2003


On Wed, 7 May 2003 17:08:34 +0100, "John Wilson" <tug at wilson.co.uk> wrote:

>
>----- Original Message ----- 
>From: "Michael Chermside" <mcherm at mcherm.com>
>To: <tug at wilson.co.uk>; <python-list at python.org>
>Sent: Wednesday, May 07, 2003 4:56 PM
>Subject: Re: Passing indented code to compile()
>
>
>[snip]
>> So it turns out that indenting the code in a human-readable-and-not-
>> left-aligned fashion within the XML source *IS* a requirement for
>> you. In that case, since the problem stems from you requiring extra
>> leading whitespace, the solution is to constrain how it is permitted.
>> 
>> Here is one possible solution:
>>          <execute globals="globals" locals="locals">
>>          <![CDATA[
>>              |text = """this string has five spaces
>>              |     after the newline"""
>>              |if i < 0:
>>              |    content = currentContent + lastContent
>>              |print text + content
>>          ]]>
>>          </execute>
>
>Yes, that would work. I'll think some more about it.
>
>Thanks for taking so much trouble in producing your reply!
>
May be of interest, from the XML 1.0 spec:
__________________________________________________________________
2.10 White Space Handling

In editing XML documents, it is often convenient to use "white space"
(spaces, tabs, and blank lines, denoted by the nonterminal S in this
specification) to set apart the markup for greater readability. Such white
space is typically not intended for inclusion in the delivered version of the
document. On the other hand, "significant" white space that should be
preserved in the delivered version is common, for example in poetry and
source code.

An XML processor must always pass all characters in a document that are
not markup through to the application. A validating XML processor must
also inform the application which of these characters constitute white space
appearing in element content. 

A special attribute named xml:space may be attached to an element to signal
an intention that in that element, white space should be preserved by
applications. In valid documents, this attribute, like any other, must be
declared if it is used. When declared, it must be given as an enumerated type
whose only possible values are "default" and "preserve". For example:

      <!ATTLIST poem   xml:space (default|preserve) 'preserve'>


The value "default" signals that applications' default white-space processing
modes are acceptable for this element; the value "preserve" indicates the
intent that applications preserve all the white space. This declared intent is
considered to apply to all elements within the content of the element where it
is specified, unless overriden with another instance of the xml:space
attribute. 

The root element of any document is considered to have signaled no
intentions as regards application space handling, unless it provides a value
for this attribute or the attribute is declared with a default value. 

2.11 End-of-Line Handling

XML parsed entities are often stored in computer files which, for editing
convenience, are organized into lines. These lines are typically separated by
some combination of the characters carriage-return (#xD) and line-feed
(#xA).

To simplify the tasks of applications, wherever an external parsed entity or
the literal entity value of an internal parsed entity contains either the literal
two-character sequence "#xD#xA" or a standalone literal #xD, an XML
processor must pass to the application the single character #xA. (This
behavior can conveniently be produced by normalizing all line breaks to #xA
on input, before parsing.) 
__________________________________________________________________

Regards,
Bengt Richter




More information about the Python-list mailing list