Trouble with regexes

2005-05-25 Thread Fernando Rodriguez
Hi,

I'm trying to write a regex that matches a \r char if and only if it
is not followed by a \n (I want to translate text files from unix
newlines to windows\dos).

I tried this, but it doesn't work:
p = re.compile(r'(\r)[^\n]', re.IGNORECASE)

it still matches a string such as r'\r\n'

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


Avoiding redirects with urllib

2008-06-14 Thread Fernando Rodriguez


Hi,

I'musing urllib to download pages from a site. How can I detect if a given 
url is being redirected somewhere else? I want to avoid this, is it possible?


Thanks in advance!


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


Re: Avoiding redirects with urllib

2008-06-15 Thread Fernando Rodriguez

Hello [EMAIL PROTECTED],


import urllib
url_opener = urllib.URLopener() # create URLopener
#You could also work with urllib.FancyURLopener
try:
data = url_opener.open("http://www.somedomain.com/index.html";)   #
open index.html
except IOError, error_code:
if error_code[0] == "http error":
if error_code[1] == 301:
#do something here
if error_code[2] == 302:
#do something here
I hope that's of some help!  I think you may want to delve deeper into
FancyURLopener...



The problem is that I'm using a subclass of FancyOpener and it doesn't raise 
those exceptions.



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


Re: Avoiding redirects with urllib

2008-06-15 Thread Fernando Rodriguez

Hello Fernando,


I hope that's of some help!  I think you may want to delve deeper
into
FancyURLopener...

The problem is that I'm using a subclass of FancyOpener and it doesn't
raise those exceptions.



Ok, forget it, I should have read the "fine" manual. O:-)


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