List Info

Thread: Re: Using regular expressions within a python script?




Re: Using regular expressions within a python script?
country flaguser name
Australia
2007-04-17 02:02:21
I ran into this same problem and discovered that some fields
have a
.replace method.  E.g.
something.Description().replace('<p>',''). That
was good enough for what I wanted.  Not sure if it works for
the body
text.

Peter Shute 

plone-users-bounceslists.sourceforge.net wrote on :

> I'm attempting to use the following script to remove a
> specific pagination code from a Document's body text:
> 
> ----------
> 
> ## Script (Python) "removePagination"
> ##bind container=container
> ##bind context=context
> ##bind namespace=
> ##bind script=script
> ##bind subpath=traverse_subpath
> ##parameters=text=None
> ##title=Remove pagination code from a Page
> 
> import re
> 
> pagination =
re.compile('<p>++++*.</p>',
> re.IGNORECASE|re.DOTALL|re.LOCALE)
> pages = re.sub(pagination, '', text)
> ----------
> 
> However, when I attempt to call this from my page
template I get the
> following error: 
> 
> Unauthorized:  You are not allowed to access 'compile'
in
> this context.
> 
> I'm assuming that this is due a security restriction. 
How do
> I go about allowing a python script to use regular
> expressions from within Zope?  Specifically I need to
somehow
> declare w/in my product that it's OK to use
re.compile,
> re.sub, etc in the manner that I'm using above.  Or is
there
> a better way to do this?
> 
> Any help would be appreciated.  Thanks!
> 
> Shane
> 
>
------------------------------------------------------------
--
> -----------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get
the
> chance to share your opinions on IT & business
topics through brief
> surveys-and earn cash
> http://www.techsay.com/default.php?page=join.p
hp&p=sourceforge 
&CID=DEVDEV
_______________________________________________
Plone-Users mailing list
Plone-Userslists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plone-users
 

------------------------------------------------------------
-------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and
take
control of your XML. No limits. Just data. Click to get it
now.
http://sourcefor
ge.net/powerbar/db2/
_______________________________________________
Plone-Users mailing list
Plone-Userslists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plone-users


Re: Using regular expressions within a python script?
country flaguser name
Germany
2007-04-17 03:42:01
Peter Shute <pshutenuw.org.au> wrote:

> I ran into this same problem and discovered that some
fields have a
> .replace method.  E.g.
something.Description().replace('<p>',''). That
> was good enough for what I wanted.  Not sure if it
works for the body
> text.

To speak from one's own experience: If you want to parse
HTML, use a
HTML parser  (e.g.
HTMLParser)

Look here: http://docs.py
thon.org/lib/markup.html

Best
Kai
-- 
Kai Diefenbach - http://diefenba.ch
iqplusplus - http://iqpp.de


------------------------------------------------------------
-------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and
take
control of your XML. No limits. Just data. Click to get it
now.
http://sourcefor
ge.net/powerbar/db2/
_______________________________________________
Plone-Users mailing list
Plone-Userslists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plone-users


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )