This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 256 - Making TS work in Python
Summary: Making TS work in Python
Status: RESOLVED FIXED
Alias: None
Product: DOM TS
Classification: Unclassified
Component: ECMAScript Binding (show other bugs)
Version: unspecified
Hardware: Other other
: P2 normal
Target Milestone: ---
Assignee: Curt Arnold
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-06-29 18:18 UTC by Curt Arnold
Modified: 2003-12-18 11:13 UTC (History)
0 users

See Also:


Attachments
Python domts package (0.2) (16.85 KB, application/zip)
2003-12-18 06:13 UTC, Andrew Clover
Details

Description Curt Arnold 2003-06-29 18:18:28 UTC
In http://lists.w3.org/Archives/Public/www-dom-ts/2003Jun/0005.html

Date: Wed, 18 Jun 2003 12:50:33 +0000
From: Andrew Clover <and-w3@doxdesk.com>
To: www-dom-ts@w3.org
Cc: carnold@houston.rr.com
Message-ID: <20030618125033.GA18541@doxdesk.com>
Subject: Making TS work in Python (and an L2 suite bug)


Curt Arnold <carnold@houston.rr.com> wrote in www-dom list <www-dom@w3.org>:

> If you'd like to take a shot at manually coverting some of the generated 
> Java or Javascript tests, I'd be willing to create a variant of the 
> existing stylesheets to produce Python tests.

OK, here's what you'll need to know to produce a Python transformation.

Variables do not have to be declared. Unless a <var> specifies an initial
value it can be completely ignored.

String and integer literals are the same as ECMAScript. List literals can
be written as '['...value...','...value...']'.

null literals are 'None'. Boolean literals are 'True' and 'False', but if you
want to be compatible with Python 2.1 you'll want to use '1' and '0' instead.
If may be easiest just to add something like:

  null= None
  true= None is None
  false= None is not None

at the start of each test, then you can use null/true/false in expressions
as normal.

method calls are the same as Java and ECMA:

  document.createElementNS(None, "foo")

property access is direct, not through getters/setters:

  root= document.documentElement
  textNode.data= "foo"

Equality comparison uses the usual '=='/'!=' operator. Same-object comparison
uses the 'is'/'is not' operator. Checking whether an instance implements an
interface can't really be done; you can check whether something is a subclass
instance using isinstance but that's all.

Addition is the usual '+' operator. Logical negation is the 'not' unary
operator. Appending to a list can be done with the append method:

  comments.append(commentNode)

and getting the length of a list is done using the len() function:

  ncomments= len(comments)

There's no standard for loading documents (until L3 L/S), some sort of
factory stuff will be needed for <load>, eg.

  from xml.dom import minidom
  factory= minidom.parse
  ...
  import os.path
  document= factory(os.path.join("files", "staff.xml"))

<for-each> comes out as:

  for membervar in collection:
    ...indented loop body...

<if><else/></if> comes out as:

  if condition:
    ...indented body...
  else:
    ...

The indent level must be consistent. Don't know if that might be a problem
with XSLT.

Exceptions are caught using:

  try:
     ...
  except:
     ...

You can't really tell whether the exception that was thrown was a
DOMException or something else as DOMException is not bound to anything
in particular. You could try:

  exception= None
  try:
    ...
  except Exception, e:
    if hasattr(e, code):
      exception= e.code
    else:
      raise

to pass non-DOM errors through.

I think that covers everthing TSML needs.

I've knocked up a quick and (very) dirty Python TSML interpreter which can
run most L1 and L2 Core tests, to check my own imp; you're welcome to a copy
if it'd help.

----   Rest of message logged as separate bugs   ----
Comment 1 Andrew Clover 2003-07-18 05:50:50 UTC
Just one other thing: strings with characters >=128 should be encoded as Unicode 
strings, as including top-bit-set characters directly in Python scripts is a 
recipe for incompatibility.

The \u character escape sequence is the same as in Java, however strings that 
include Unicode characters have to be marked as Unicode strings by putting a 'u' 
before the opening quote.

eg.: u'foo', u"f\u00FC".
Comment 2 Andrew Clover 2003-12-18 06:10:52 UTC
Okay, I've implementated DOMTS for Python. But as an interpreter-based package,
not the XSLT code-generation approach used by the Java and ECMAScript tests.
(For Python it's much easier to do this way.)

This covers all TSML in use at the time of writing, I'll try to keep it up to
date with any new language constructs or new DOM interfaces.
Comment 3 Andrew Clover 2003-12-18 06:13:32 UTC
Created attachment 123 [details]
Python domts package (0.2)