HighDots Forums  

regexp help

Python Python programming language mailing list


Discuss regexp help in the Python forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Savoy, Jim
 
Posts: n/a

Default Re: regexp help - 11-02-2009 , 06:29 PM






Mark Sapiro wrote:

Quote:
You used some kind of word processor to create foo.py that concatenated
lines 2 and 3 into a single line. Your Foo.py file must be just like
my original example with lines 1, 2 and 3 at the left margin, lines 4
and 6 indented 4 spaces and lines 5, 7, 8 and 9 indented 8 spaces.

These words you are saying are all true. I just "cut" your code in
Outlook and "pasted" it in vi. I will try it again with the indenting
you suggested (reminds me of Fortran!). Thanks.

- jim -

------------------------------------------------------
Mailman-Users mailing list Mailman-Users (AT) python (DOT) org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: http://mail.python.org/mailman/options/mailman-users/python%40highdots.com

Reply With Quote
  #12  
Old   
Savoy, Jim
 
Posts: n/a

Default Re: regexp help - 11-02-2009 , 07:05 PM






Quote:
Depending on the options set in vi, it can do horrible things to
indentation when you paste things in

I just looked at your original posting (using Outlook) and line 3 is
not indented, but rather continuous from line 2, and the other indents
are in columns 5 and 9 (not 4 and 8). I shall try viewing it with other
mail clients, just for kicks.

But now that I know that whitespace is critical in Python, I will be
more
careful.


Quote:
Python is not at all like Fortran, In Fortran (at least through Fortran
IV - I never did much with Fortran 77 and nothing beyond that) white
space except for line endings is totally insignificant. True, you have
some formatting restrictions like positions 1 - 5 for statement numbers,
6 for continuation and 7 - 72 for statements (although some compilers
relaxed these), but consider that the compiler's parser/tokenizer
doesn't know whether

I was loosely referring to Fortran reserving certain columns for certain
things. I barely remember it at all (that was back in my pre-Commodore64
(PEEKin' and POKEin' anyone?), punched-hole card days).

- jim -



------------------------------------------------------
Mailman-Users mailing list Mailman-Users (AT) python (DOT) org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: http://mail.python.org/mailman/options/mailman-users/python%40highdots.com

Reply With Quote
  #13  
Old   
Chr. von Stuckrad
 
Posts: n/a

Default Re: regexp help (OT: Edit and Mail) - 11-03-2009 , 07:03 AM



On Mon, 02 Nov 2009, Savoy, Jim wrote:

Quote:
Depending on the options set in vi, it can do horrible things to
indentation when you paste things in
:-) seen that! Therefore modern vims have :set paste<enter>
and as long as you not 'set nopaste' *no* munging of pastes will be
done! I'm needing/using that all the time, I might even put it
into my '.vimrc' and make it default ...

Quote:
I just looked at your original posting (using Outlook) and line 3 is
not indented, but rather continuous from line 2, and the other indents
are in columns 5 and 9 (not 4 and 8). I shall try viewing it with other
mail clients, just for kicks.
'outlook' is a <insert favorite expletive here> for programmers.
By Default it *reformats* everything to 'Paragraphs' of the form:
- everything NOT split by an empty line is 'supposed to be a useless
linebreak for mailtransfer', then it collects all those lines and
reformats the resulting words with single whitespaces to window-size.
- an empty line means 'paragraph end', so itself may vanish anyway
only the linebreak in a paragraph stays.

It's like Microsoft(office)Word's view of Text and you are supposed
to write html or rtf anyway :-)

If hints(warnings, whatever) are on, you'll see a line above your
munged mail, saying it removed useless newlines, and by clicking
it you can get them back.

Stucki
------------------------------------------------------
Mailman-Users mailing list Mailman-Users (AT) python (DOT) org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: http://mail.python.org/mailman/options/mailman-users/python%40highdots.com

Reply With Quote
  #14  
Old   
Savoy, Jim
 
Posts: n/a

Default Re: regexp help - 11-03-2009 , 05:05 PM



Hi Mark,

I got it to compile properly, but it is still not working.
I made the following changes in Foo.py:

import re
cre = re.compile('test.account', re.IGNORECASE)
def process(mlist, msg, msgdata):
if mlist.internal_name <> 'abc-l':
return
if cre.search(msg.get('to', '')):
msgdata['approved'] = 1
# Used by the Emergency module
msgdata['adminapproved'] = 1


Goal: The account test.account (AT) uleth (DOT) ca is set to forward mail to the
mailing
list abc-l (AT) uleth (DOT) ca, which should accept it, regardless of who sent it
to
test.account (AT) uleth (DOT) ca (all other mail to this list from non-members will
be
rejected).


You also wrote:

Quote:
if the contents of the To: header of the message matches the regexp in
re.compile() case insensitively, then the approved and adminapproved
flags will be set in the message metadata and the message won't be
subject to any holds.
So when you say "matches the regexp" do you mean "exactly" matches? And
if so,
would your regexp work? Or do I need a more specific or accompanying
regexp in
the re.compile statement? eg

cre = re.compile('test.account (AT) uleth (DOT) ca', re.IGNORECASE)

Thanks.

- jim -

------------------------------------------------------
Mailman-Users mailing list Mailman-Users (AT) python (DOT) org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: http://mail.python.org/mailman/options/mailman-users/python%40highdots.com

Reply With Quote
  #15  
Old   
Savoy, Jim
 
Posts: n/a

Default Re: regexp help - 11-03-2009 , 06:24 PM



Mark Sapiro wrote:

Quote:
Did you put 'Foo' back in the GLOBAL_PIPELINE prior to 'Moderate' and
restart Mailman?

I did.

Quote:
What happens when you mail to test.account? Is the mail rejected by
Mailman? Does the To: header in the mail in the reject notice contain
'test.account'?

Yes, it is rejected. And the To: header does not come from test.account
but rather from the actual sender. Inside of what looks like an Exchange
attachment, I can see the full original message, with the To: header
displaying test.account. So it looks like the Exchange server may be
wrapping up the original message and obscuring the headers.


Quote:
Since that regexp 'test.account' is not anchored and is searched for by
the re.search() method, it means if the string 'test' in any
combination of upper/lower case followed by any single character (the
.. matches any character) followed by the string 'account' in any
combination of upper/lower case is in the To: header, it will match.

OK - that's close enough for me. I don't really need to be that specific
anyway because my test.account (not the real name of the account) is
quite
a unique and unusual name.

I have just received word from the owners of this list that they no
longer
care about me doing this (they have just opened the list up to anyone)
so I probably won't spend too much more time on it now, especially if
the Exchange server (which I don't have access to) is obscuring the
original
headers from Mailman. Since we have exim as a front-end to Mailman, I
can
probably just do some sort of a re-write in there instead.

But thanks anyway. It was an interesting foray into Python for me!

- jim -


------------------------------------------------------
Mailman-Users mailing list Mailman-Users (AT) python (DOT) org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: http://mail.python.org/mailman/options/mailman-users/python%40highdots.com

Reply With Quote
  #16  
Old   
Savoy, Jim
 
Posts: n/a

Default Re: regexp help - 11-04-2009 , 12:19 PM



Quote:
Mark Sapiro wrote:

That would be the To: header of the reject notice.
Yes. That is the message I am analyzing.

Quote:
Mailman sends a multipart/mixed message with two parts - a text/plain
part containing the reject reason and a message/rfc822 part containing
the post as received by Mailman. It is the message in this
message/rfc822 part that is what Mailman saw. If that is not the
original post, but somehow got wrapped by Exchange in the forwarding
process, you'll have to take that into account.
Got it. Under the message/rfc822 part, the To: header says
test.account (AT) uleth (DOT) ca.

So in theory, it should accept this message. I will re-analyze
everything to
make sure there are no typos. Thanks.

- jim -



------------------------------------------------------
Mailman-Users mailing list Mailman-Users (AT) python (DOT) org
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://wiki.list.org/x/AgA3
Security Policy: http://wiki.list.org/x/QIA9
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: http://mail.python.org/mailman/options/mailman-users/python%40highdots.com

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.