On Thu, Jul 9, 2009 at 12:22 PM, mdipierro <mdipie...@cs.depaul.edu> wrote:

>
>
> > There's a lot to be said for using re.X when writing expressions like
> > this. Here's a quick hack as the current one.
>
> what does it do?


>From http://docs.python.org/library/re.html#contents-of-module-re
re.X¶ <http://docs.python.org/library/re.html#re.X>
re.VERBOSE¶<http://docs.python.org/library/re.html#re.VERBOSE>

This flag allows you to write regular expressions that look nicer.
Whitespace within the pattern is ignored, except when in a character class
or preceded by an unescaped backslash, and, when a line contains a
'#'neither in a character class or preceded by an unescaped backslash,
all
characters from the leftmost such '#' through the end of the line are
ignored.

That means that the two following regular expression objects that match a
decimal number are functionally equal:

a = re.compile(r"""\d +  # the integral part
                   \.    # the decimal point
                   \d *  # some fractional digits""", re.X)
b = re.compile(r"\d+\.\d*")


Good call, Jonathan -  this may slow things down for the first, uncompiled
run of main (so what) - it will make things much more maintainable....

I like it...


>
> > One thing that jumps out at me (assuming I've done it right) is that
> > the handling of 'sub' and 'ext' doesn't match the documenting comment;
> > they're in reverse order.
>
> you are right. the comment is wrong
>
> > A small point: you don't need to escape dot in character classes, nor
> > minus if you put it first, nor (I think) equals ever. So [\w\-][\=\./]
> > could be [-\w][=./]. I think. (I find that pattern a little puzzling,
> > btw.)
>
> It is designed to avoid .. (which may cause directory traversals) and
> double // (which would result in empty args)
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to