Passing indented code to compile()

John Wilson tug at wilson.co.uk
Thu May 8 02:16:26 EDT 2003


----- Original Message ----- 
From: "Bengt Richter" <bokr at oz.net>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Wednesday, May 07, 2003 10:56 PM
Subject: Re: Passing indented code to compile()


[snip]
> >
> 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.
>

This says that all whitespace *must* be passed to the application. The
xml:space attibute is intended to allow the author of the document to tell
the consumer application that whitespace is not significant - the XML parser
just passes it through to the consumer. If a DTD is present then it is
possible to tell a validating parser that some whitespace (i.e. whitespace
between two start elements) is not significant. In this case the parser must
still pass the whitespace to the consumer application but it is marked as
not significant (SAX uses the ignorableWhitespace callback for this
purpose).
In the <execute> example above the whitespace is always passed through
inchanged (aside from end of line normalisation) no matter what the DTD
says.

> 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.)

This is the end of line normalisation process - If the document author wants
to insert CR LF into the document then the appropriate numeric character
entities need to be used instead of the literal characters.

John Wilson
The Wilson Partnership
http://www.wilson.co.uk






More information about the Python-list mailing list