pyparsing with nested table
using pyparsing to deal with nested tables , wanna keep table's
structure and propertys .
but program was chunked with the tag of inner table.
have any ideas?
here's the program
from pyparsing import *
mytable = """
system
art
art
"""
startTag = Literal("<")
endTag = Literal(">")
idPattern = CaselessLiteral("id").suppress() + Literal("=").suppress()
+ ( quotedString.copy().setParseAction( removeQuotes ) |
Word(srange("[a-zA-Z0-9_~]")))
attrPattern = Combine(Word(alphanums + "_") + Literal("=") + (
quotedString | Word(srange("[a-zA-Z0-9_~:&@#;?/\.]"
tablePattern = Forward()
def getItemCloseTag(x):
itemCloseTag = Combine(startTag + Literal("/") + CaselessLiteral(x)
+ endTag).suppress()
return itemCloseTag
def getItemStartTag(x):
itemStartTag = startTag.suppress() +
Keyword(x,caseless=True).suppress() + Group(ZeroOrMore(idPattern)) +
Group(ZeroOrMore(attrPattern)) + endTag.suppress()
return itemStartTag
def getItemPattern(x):
tCloseTag = getItemCloseTag(x)
itemPattern = getItemStartTag(x) + Group(ZeroOrMore(tablePattern))
+ Group(SkipTo(tCloseTag)) + tCloseTag
return itemPattern
def getMultiLevelPattern(x,y):
tCloseTag = getItemCloseTag(x)
itemPattern = getItemStartTag(x) + Group(OneOrMore(y)) + tCloseTag
return itemPattern
tdPattern = getItemPattern(x='td')
trPattern = getMultiLevelPattern('tr',tdPattern)
tablePattern = getMultiLevelPattern('table',trPattern)
t = tablePattern
for toks,strt,end in t.scanString(mytable):
print toks.asList()
OutPut:
[['leftpage_table'], ['width="156"', 'border="0"', 'cellspacing="0"',
'cellpadding="0"'], [['trtd'], ['height="24"'], [[], ['width="153"',
'background="images/bt_kind.gif"', 'align="center"',
'class="left_menu"'], [], ['system']], ['trtd_down'], ['height="20"'],
[['trtd_down'], [], [], ['\n\n art']], [], [], [[],
['background="images/bt_class.gif"', 'align="center"'], [], ['art'
--
http://mail.python.org/mailman/listinfo/python-list
Re: pyparsing with nested table
Paul McGuire wrote:
>
> Load Forward's with '<<' instead of '='. Change:
> tablePattern = getMultiLevelPattern('table',trPattern)
> to:
> tablePattern << getMultiLevelPattern('table',trPattern)
>
> I think that is all you needed.
>
> Awesome job! (Also check out the pyparsing built-ins for making HTML
> and XML tags.)
>
> -- Paul
thank you , i was wonding why my iteraiton not functional . so it's my
fault .
later , i checked other parsers like Clientable & BeautifulSoap ,
i think with beautifulsoap doing this job is a better idea.
--
http://mail.python.org/mailman/listinfo/python-list
strange result with json-server & zope
i'm using maildrophost to sendmail and wrote a script for it
when the script is called directly from web request , a letter
geneated with right things
but when the script is called from json-rpc, the letter generated
include a mess.
see the file with this letter
[the script]
body_html = container.mime_mail(body_html=body_html)
container.MailHost.send(messageText=body_html, mto=to_email,
mfrom=from_email, subject=subject, encode=None)
[mime_mail is a dtml-method]
[enviroment]
Zope Version
(Zope 2.9.4-final, python 2.4.3, linux2)
Python Version
2.4.3 (#1, Sep 11 2006, 19:52:33) [GCC 3.4.6 20060404 (Red Hat
3.4.6-3)]
System Platform
linux2
strangely at another server, everythin runs smoothly
[enviroment]
Zope Version
(Zope 2.9.2-, python 2.4.3, linux2)
Python Version
2.4.3 (#1, Mar 31 2006, 17:42:57) [GCC 3.4.4 20050721 (Red Hat
3.4.4-2)]
[called directly from web request ]
##To:[EMAIL PROTECTED]
##From:[EMAIL PROTECTED]
Message-Id: <[EMAIL PROTECTED]>
Mime-Version: 1.0
Content-Type: multipart/mixed;
boundary="127.0.0.1.500.5494.1158303670.500.4"
Subject: You probably forgot your password for Ztooo.com
To: [EMAIL PROTECTED]
From: [EMAIL PROTECTED]
Date: Fri, 15 Sep 2006 15:01:10 -0500
--127.0.0.1.500.5494.1158303670.500.4
Content-Type: text/html;
charset="utf8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
http://www.w3.org/TR/html4/loose.dtd";>
You probably forgot your password for
Ztooo.com!=E6=82=A8=E5=8F=AF=
=E8=83=BD=E9=81=97=E5=BF=98=E4=BA=86=E6=91=98=E7=BD=91=E7=9A=84=E5=AF=86=E7=
=A0=81!
=E6=82=A8=E5=8F=AF=E8=83=BD=E9=81=97=E5=BF=98=E4=BA=86=E6=91=98=E7=BD=
=91=E7=9A=84=E5=AF=86=E7=A0=81
=E6=82=A8=E7=9A=84=E5=AF=86=E7=A0=81=E6=98=AF
=EF=BC=8C=E4=BD=BF=E7=94=A8=E6=AD=A4=E9=82=AE=E7=
=AE=B1=E5=90=8D=E4=BD=9C=E4=B8=BA=E7=94=A8=E6=88=B7=E5=90=8D=E5=92=8C=E6=AD=
=A4=E5=AF=86=E7=A0=81=E7=99=BB=E5=BD=95=EF=BC=8C=E6=88=96=E8=80=85=E7=82=B9=
=E5=87=BB=E4=B8=8B=E9=9D=A2=E7=9A=84=E6=8C=89=E9=92=AE=E7=99=BB=E5=BD=95=EF=
=BC=9A
http://web3.com/index.htm";
target=3D"_blank" enctype=3D"multipart/form-data">
=20
=20
=E7=99=BB=E5=BD=95=E5=90=8E=E6=82=A8=E5=8F=AF=E4=
=BB=A5=E4=BF=AE=E6=94=B9=E6=82=A8=E7=9A=84=E5=AF=86=E7=A0=81=E5=92=8C=E8=AE=
=BE=E7=BD=AE=E6=82=A8=E5=96=9C=E6=AC=A2=E7=9A=84=E7=AC=94=E5=90=8D=E3=80=82=
You probably forgot your password for Ztooo.com!
Your password is , Use the mailboxname as username and this
passw=
ord to login , or click the button below:
http://web3.com/index.htm";
target=3D"_blank" enctype=3D"multipart/form-data">
=20
You could change your password and set your
favo=
rite pseudonym after that.
--127.0.0.1.500.5494.1158303670.500.4--
[called from json-rpc]
##To:[EMAIL PROTECTED]
##From:[EMAIL PROTECTED]
Message-Id: <[EMAIL PROTECTED]>
Mime-Version: 1.0
Content-Type: multipart/mixed;
boundary="127.0.0.1.500.5494.1158303673.002.5"
Subject: You probably forgot your password for Ztooo.com
To: [EMAIL PROTECTED]
From: [EMAIL PROTECTED]
Date: Fri, 15 Sep 2006 15:01:13 -0500
--127.0.0.1.500.5494.1158303673.002.5
Content-Type: text/html;
charset="utf8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
< ! D O C T Y P E H T M L P U B L I C " - / / W 3 C / / D T D H
T M=
L 4 . 0 1 T r a n s i t i o n a l / / E N "
" h t t p : / / w w w . w 3 . o r g / T R / h t m l 4 / l o o s e . d
t d =
" >
< h t m l >
< h e a d >
< m e t a h t t p - e q u i v =3D " C o n t e n t - T y p e " c o
n t =
e n t =3D " t e x t / h t m l ; c h a r s e t =3D u t f - 8 " >
< t i t l e > Y o u p r o b a b l y f o r g o t y o u r p a s
s w =
o r d f o r Z t o o o . c o m !
=A8`=EFS=FD=80W=90=D8_=86NXdQ=7F=84v=C6=
[x! < / t i t l e >
< / h e a d >
< b o d y >
< h 3 > =A8`=EFS=FD=80W=90=D8_=86NXdQ=7F=84v=C6[x< / h 3 >
< h r / >
< p > & n b s p ; & n b s p ; & n b s p ; & n b s p ; =A8`=84v=C6[x/f
< =
f o n t
c o l o r =3D " b l u e " > < / f o n t >
=FF=7FO(udk=AE=90=B1{=
T\O:N(u7b
T=8CTdk=C6[x{vU_=FFb=80=B9p=FBQNb=97=84v c=AE=94{vU_=FF< /=
p >
< d i v >
< f o r m m e t h o d =3D " p o s t " a c t i o n =3D " h t t
p : =
/ / w e b 3 . c o m / i n d e x . h t m "
t a r g e t =3D " _ b l a n k " e n c t y p e =3D "
m u =
l t i p a r t / f o r m - d a t a " >
< i n p u t t y p e =3D " h i d d e n " n a m e =3D " _ _
a c =
_ n a m e " i d =3D " _ _ a c _ n a m e "
s i z e =3D " 1 2 " v a l u e =3D " a s t e r
o c =
e a n @ g m a i l . c o m " >
< i n p u t t y p e =3D " h i d d e n " n a m e =3D " _ _
a c =
_ p a s s w o r d " s i z e =3D " 1 2 "
v a l u e =3D " " >
& n b s p ; & n b s p ; & n b s p ; & n b s p ; < i n p u t t y p e
=3D =
" s u b m i t " v a l u e =3D " =B9p=FBQdkY{vU_" >
< / f o r m >
< / d i v >
< p > & n b s p ; & n b s p ; & n b s p ; & n
Re: strange result with json-server & zop
error finnaly been eliminated. after install placelesstranslationservice product, everything back to normal. but i don't know why. the program runs well under a server with zope2.9.1 , for i got another server and i wanna do a global update ,so a new zope version 2.9.4 and all other new version were installed and the program was exported from old server and imported in new server . but i didn't install placelesstranslationservice product, it seems nofair with this program.that's why this error happen. really strange turn out , i guess there's something wrong with zexp mechanic , for it seemed program exported and imported are binary code not source code with objects like scripts, so some stein code remains. thank you, Gabrial. Gabriel Genellina wrote: > At Saturday 16/9/2006 08:40, asterocean wrote: > > >>But this is not UTF-8; looks like UTF-16 with 0x00 converted to 0x20 > >>(space). I'd look at where the body comes from, or ask on the Zope > >>list for the right way to use dtml-mime. > > > >i've try with UTF-8 , error remains . when the script is called > >directly from http request , it went well. so this should not be the > >problem. the real problem is when it is called from a json-rpc, the > >error happened > > Try to look at what you *get* as the body from xmlrpc, if it comes > wrong, will go wrong to the email. > > >>Anyway, why are you using dtml-mime and such? Using the email package > >>is easier and a lot more powerful. > >i'm using zope & jsonserver & maildrop to develop this part , so the > >main problem how to send mail with json-rpc structure. > > You can use the email package from inside Zope; an external method will do. > > > > Gabriel Genellina > Softlab SRL > > > > > > __ > Preguntá. Respondé. Descubrí. > Todo lo que querías saber, y lo que ni imaginabas, > está en Yahoo! Respuestas (Beta). > ¡Probalo ya! > http://www.yahoo.com.ar/respuestas -- http://mail.python.org/mailman/listinfo/python-list
i just made a website(ztooo.com) using zope & jsonserver
ztooo.com come up on 2006-09-19, made with zope & jsonserver, have a look? you may need zh_CN.utf8 charsets installed for view normaly thanks reebalazs for his brilliant idea thanks zope -- http://mail.python.org/mailman/listinfo/python-list
how to remember login in zope?
how to remember login in zope? so when user came back , they needn't input username and password again. i'm using zope,extensiveuserfolder and cookiecrumbler, exuserfolder is set to cookie-based authentication. i'm not using cmf or plone , how could i handle this? thanks a lot. i'm working around this for two days and surfing a lot of pages but still felt confused, any suggestion would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list
