[Biopython-dev] Something wrong with Martel?

Greg Tyrelle greg at tyrelle.net
Sat Jul 26 02:32:44 EDT 2003


*** Yair Benita wrote: 
  |Second, trying to run the same script as Andrew wrote in the Readme
  |(attached), I only get:
  |<?xml version="1.0" encoding="iso-8859-1"?>
  |
  |Basically nothing is executed after the command: parser.parse(open(File))
  |
  |Is something wrong on my system or something wrong with the Martel code?

Something in your /etc/passwd file is causing the Martel expression to
fail. The script fails on my system (OSX) because of comments in the
passwd file. I have attached a slight modification of the demo script
that deals with comments.

Was that the problem ?

_greg

-- 
Greg Tyrelle
-------------- next part --------------
import Martel
from xml.sax import saxutils,handler

def ToColon(name):
    return Martel.ToSep(name, ":")

comment = Martel.Rep(Martel.Re("^#") +Martel.ToEol())

passwd =  Martel.Rep(
              Martel.Group("record",
              ToColon("account") + ToColon("password") + ToColon("UID") + \
              ToColon("GID") + ToColon("GECOS") + ToColon("directory") + \
              Martel.ToEol("shell")))

format = Martel.Group("passwd", comment + passwd)

parser = format.make_parser()
parser.setContentHandler(saxutils.XMLGenerator())
parser.parseFile(open("/etc/passwd"))

from xml.dom import pulldom
sax2dom = pulldom.SAX2DOM()
parser.setContentHandler(sax2dom)
parser.parseFile(open("/etc/passwd"))
doc = sax2dom.document
doc.normalize()
for record in doc.getElementsByTagName("record"):
    account = record.getElementsByTagName("account")[0].firstChild.nodeValue
    shell = record.getElementsByTagName("shell")[0].firstChild.nodeValue
    print account, "uses", shell


More information about the Biopython-dev mailing list