HTTPConncetion - HEAD request

2011-06-16 Thread gervaz
Hi all, can someone tell me why the read() function in the following py3 code returns b''? >>> h = http.client.HTTPConnection("www.twitter.com") >>> h.connect() >>> h.request("HEAD", "/", "HTTP 1.0") >>> r = h.getresponse() >>> r.read() b'' Thanks, Mattia -- http://mail.python.org/mailman/listi

Re: HTTPConncetion - HEAD request

2011-06-17 Thread gervaz
On 17 Giu, 01:00, Ian Kelly wrote: > On Thu, Jun 16, 2011 at 4:43 PM, gervaz wrote: > > Hi all, can someone tell me why the read() function in the following > > py3 code returns b''? > > >>>> h = http.client.HTTPConnection("www.twitter.com") &

Re: HTTPConncetion - HEAD request

2011-06-17 Thread gervaz
On 17 Giu, 12:14, Adam Tauno Williams wrote: > On Thu, 2011-06-16 at 15:43 -0700, gervaz wrote: > > Hi all, can someone tell me why the read() function in the following > > py3 code returns b'' > > >>> h = http.client.HTTPConnection("www.twitter.com&

Python scoping

2011-06-20 Thread gervaz
Hi all, can you explain me why this simple function works well (i.e. I can call the print function using txt) in py >>> def test(value): ... if value%5: txt = "hello" ... else: txt = "test" ... print(txt) while in other languages like C the txt identifier would be undefined? Is there

Re: Python scoping

2011-06-21 Thread gervaz
On 21 Giu, 06:06, Ben Finney wrote: > Chris Angelico writes: > > On Tue, Jun 21, 2011 at 12:38 PM, Ben Finney > > wrote: > > > The *binding* is scoped. > > > And the binding follows the exact same rules as anything else would. > > It has scope and visibility. In terms of the OP, the binding IS

Get the name of a function

2011-08-05 Thread gervaz
Hi all, is there a way to retrive the function name like with self.__class__.__name__? Using self.__dict__.__name__ I've got >>> def test(): ... print(self.__dict__.__name__) ... >>> test But I really just want the function name, so 'test' Any help? Thanks, Mattia -- http://mail.python.

Use cookies from a script in a browser

2011-03-18 Thread gervaz
Hi all, I use a scraper to retrieve data from a web page. In order to do that I need to enable cookies. The data that I'm looking for is contained in a bunch of web pages. Is there a way to show this web pages in a browser using the cookies used in the script (otherwise it doesn't work). Thanks,

Re: Use cookies from a script in a browser

2011-03-18 Thread gervaz
On 18 Mar, 22:52, Miki Tebeka wrote: > You can use mechanize, which holds a cookie jar and can user the browser > cookies as well. I use: opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor()) urllib.request.install_opener(opener) I start scraping from http://page.com/home.ht

Proxy authentication required

2011-03-21 Thread gervaz
Hi all, I've got to download some web pages but I'm behind a proxy. So far this is what I've used without any successful result receiving the error: "urllib.error.HTTPError: HTTP Error 407: Proxy Authentication Required ( The ISA Server requires auth orization to fulfill the request. Access to the

Re: Proxy authentication required

2011-03-22 Thread gervaz
On 22 Mar, 00:02, Chris Rebert wrote: > On Mon, Mar 21, 2011 at 2:38 AM, gervaz wrote: > > Hi all, > > I've got to download some web pages but I'm behind a proxy. So far > > this is what I've used without any successful result receiving the > > erro

Re: Proxy authentication required

2011-03-22 Thread gervaz
On 22 Mar, 09:34, gervaz wrote: > On 22 Mar, 00:02, Chris Rebert wrote: > > > > > > > On Mon, Mar 21, 2011 at 2:38 AM, gervaz wrote: > > > Hi all, > > > I've got to download some web pages but I'm behind a proxy. So far > > > this

Regexp

2009-01-19 Thread gervaz
Hi all, I need to find all the address in a html source page, I'm using: 'href="(?Phttp://mysite.com/[^"]+)">()?(?P[^]+)()?' but the [^]+ pattern retrieve all the strings not containing < or / or a etc, although I just not want the word "". How can I specify: 'do not search the string "blabla"?' T

Re: Regexp

2009-01-19 Thread gervaz
On Jan 19, 4:01 pm, Ant wrote: > A 0-width positive lookahead is probably what you want here: > > >>> s = """ > > ... hdhd http://mysite.com/blah.html";>Test String OK a> > ... > ... """>>> p = r'href="(http://mysite.com/[^"]+)">(.*)(?=)' > >>> m = re.search(p, s) > >>> m.group(1) > > 'http://mysi

Re: Correct URL encoding

2009-03-15 Thread gervaz
On Mar 16, 12:38 am, Graham Breed wrote: > mattia wrote: > > I'm using urlopen in order to download some web pages. I've always to > > replace some characters that are in the url, so I've come up with: > > url.replace("|", "%7C").replace("/", "%2F").replace(" ", "+").replace > > (":", "%3A") > > T

py3.x urllib.request - HTTPCookieProcessor and header adding

2009-12-16 Thread gervaz
Hi all, I need to fetch some html pages and it is required to have cookies enabled. So, I'm using opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor ()) urllib.request.install_opener(opener) as a global instance. Is there a way to always use a default header like: {"User-Age

putchar(8)

2009-10-16 Thread gervaz
Hi all, is there a pythonic way to have the -- http://mail.python.org/mailman/listinfo/python-list

putchar(8)

2009-10-16 Thread gervaz
Hi all, is there in python the equivalent of the C function int putchar (int c)? I need to print putchar(8). Thanks, Mattia -- http://mail.python.org/mailman/listinfo/python-list

Signal handler & cygwin

2010-12-25 Thread gervaz
Hi all, given the followin code snippet: import signal import time import sys import os print("{0}\n".format(os.getpid())) ContinueProcessing = True def stop(signal, frame): print("\nSignal received!\n") time.sleep(1) global ContinueProcessing ContinueProcessing = False signal.

Interrput a thread

2010-12-29 Thread gervaz
Hi all, I need to stop a threaded (using CTR+C or kill) application if it runs too much or if I decide to resume the work later. I come up with the following test implementation but I wanted some suggestion from you on how I can implement what I need in a better or more pythonic way. Here the code:

String building using join

2010-12-31 Thread gervaz
Hi all, I would like to ask you how I can use the more efficient join operation in a code like this: >>> class Test: ... def __init__(self, v1, v2): ... self.v1 = v1 ... self.v2 = v2 ... >>> def prg(l): ... txt = "" ... for x in l: ... if x.v1 is not None: ...

Re: String building using join

2011-01-02 Thread gervaz
On 31 Dic 2010, 16:43, Emile van Sebille wrote: > On 12/31/2010 7:22 AM gervaz said... > > > > > > > Hi all, I would like to ask you how I can use the more efficient join > > operation in a code like this: > > >>>> class Test: > > ...     de

Re: Interrput a thread

2011-01-02 Thread gervaz
On 31 Dic 2010, 23:25, Alice Bevan–McGregor wrote: > On 2010-12-31 10:28:26 -0800, John Nagle said: > > > Even worse, sending control-C to a multi-thread program > > is unreliable in CPython.  See "http://blip.tv/file/2232410"; > > for why.  It's painful. > > AFIK, that has been resolved in Python

Re: String building using join

2011-01-02 Thread gervaz
On 2 Gen, 19:14, Emile van Sebille wrote: > On 1/2/2011 9:43 AM gervaz said... > > > > > > > On 31 Dic 2010, 16:43, Emile van Sebille  wrote: > >> On 12/31/2010 7:22 AM gervaz said... > > >>> Hi all, I would like to ask you how I can use the more ef

Re: String building using join

2011-01-02 Thread gervaz
On 2 Gen, 22:37, gervaz wrote: > On 2 Gen, 19:14, Emile van Sebille wrote: > > > > > > > On 1/2/2011 9:43 AM gervaz said... > > > > On 31 Dic 2010, 16:43, Emile van Sebille  wrote: > > >> On 12/31/2010 7:22 AM gervaz said... > > > &

Re: Interrput a thread

2011-01-03 Thread gervaz
On 3 Gen, 17:47, de...@web.de (Diez B. Roggisch) wrote: > gervaz writes: > > On 31 Dic 2010, 23:25, Alice Bevan–McGregor > > wrote: > >> On 2010-12-31 10:28:26 -0800, John Nagle said: > > >> > Even worse, sending control-C to a multi-thread program >

Re: Interrput a thread

2011-01-03 Thread gervaz
On 3 Gen, 22:17, Adam Skutt wrote: > On Jan 3, 4:06 pm, Jean-Paul Calderone > wrote: > > > > > > Multiple processes, ok, but then regarding processes' interruption > > > there will be the same problems pointed out by using threads? > > > No.  Processes can be terminated easily on all major platfo

Re: Interrput a thread

2011-01-04 Thread gervaz
On 4 Gen, 07:13, Jean-Paul Calderone wrote: > On Jan 3, 6:17 pm, Adam Skutt wrote: > > > On Jan 3, 5:24 pm, Jean-Paul Calderone > > wrote: > > > > Of course.  The whole point here is not about threads vs processes. > > > It's about shared memory concurrency vs non-shared memory > > > concurrency