urlib.quote gives KeyError in Python 2.4.4 but workin 2.3.5

2007-01-07 Thread nyenyec
urllib.quote chokes on unicode in 2.4.4.

>>> print sys.version
2.4.4 (#1, Oct 18 2006, 10:34:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)]
>>> urllib.quote(u"\xe9")
Traceback (most recent call last):
  File "", line 1, in ?
  File
"/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/urllib.py",
line 1117, in quote
res = map(safe_map.__getitem__, s)
KeyError: u'\xe9'

but it seems to work in Python 2.3.5

Python 2.3.5 (#1, Aug 19 2006, 21:31:42)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, urllib
>>> print sys.version
2.3.5 (#1, Aug 19 2006, 21:31:42)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)]
>>> urllib.quote(u'\xe9')
'%E9'

Is this a known bug?

What's the workaround?

Thanks,
nyenyec

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urlib.quote gives KeyError in Python 2.4.4 but workin 2.3.5

2007-01-07 Thread nyenyec
encode seems to solve my problem:

>>> urllib.quote(u'\xe9'.encode('utf-8'))
'%C3%A9'

Cheers,
nyenyec

nyenyec wrote:
> urllib.quote chokes on unicode in 2.4.4.
>
> >>> print sys.version
> 2.4.4 (#1, Oct 18 2006, 10:34:39)
> [GCC 4.0.1 (Apple Computer, Inc. build 5341)]
> >>> urllib.quote(u"\xe9")
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File
> "/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/urllib.py",
> line 1117, in quote
> res = map(safe_map.__getitem__, s)
> KeyError: u'\xe9'
>
> but it seems to work in Python 2.3.5
>
> Python 2.3.5 (#1, Aug 19 2006, 21:31:42)
> [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import sys, urllib
> >>> print sys.version
> 2.3.5 (#1, Aug 19 2006, 21:31:42)
> [GCC 4.0.1 (Apple Computer, Inc. build 5363)]
> >>> urllib.quote(u'\xe9')
> '%E9'
>
> Is this a known bug?
> 
> What's the workaround?
> 
> Thanks,
> nyenyec

-- 
http://mail.python.org/mailman/listinfo/python-list


re.sub and re.MULTILINE

2007-01-08 Thread nyenyec
I feel like a complete idiot but I can't figure out why re.sub won't
match multiline strings:

This works:
>>> re.search("^foo", "\nfoo", re.MULTILINE)
<_sre.SRE_Match object at 0x6c448>

This doesn't. No replacement:
>>> re.sub("^foo", "bar", "\nfoo", re.MULTILINE)
'\nfoo'

Why?

Thanks,
nyenyec

-- 
http://mail.python.org/mailman/listinfo/python-list


re.sub and re.MULTILINE

2007-01-08 Thread nyenyec
I feel like a complete idiot but I can't figure out why re.sub won't
match multiline strings:

This works:
>>> re.search("^foo", "\nfoo", re.MULTILINE)
<_sre.SRE_Match object at 0x6c448>

This doesn't. No replacement:
>>> re.sub("^foo", "bar", "\nfoo", re.MULTILINE)
'\nfoo'

Why?

Thanks,
nyenyec

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: re.sub and re.MULTILINE

2007-01-09 Thread nyenyec

Paddy wrote:
> Check the arguments to re.sub.
>
> >>> re.sub('(?m)^foo', 'bar', '\nfoo', count=0)
> '\nbar'
> 
> - Paddy.

Duh! :) I appreciate it, thanks.

-- nyenyec

-- 
http://mail.python.org/mailman/listinfo/python-list