Mimetools and how to use it

Oleg Broytmann phd at phd.pp.ru
Wed Nov 14 06:06:33 EST 2001


On Wed, Nov 14, 2001 at 11:51:27AM +0100, A wrote:
> >From a web server I receive headers that is an instance of the class 
> MIMETOOLS.MESSAGE.
> How can decode it to  get something like this
> 
> Date: Wed, 14 Nov 2001 10:02:17 GMT
> Server: Apache/1.3.6 (Unix) PHP/3.0.14
> X-Powered-By: PHP/3.0.14
> Set-Cookie: PHPSESSID=000741aaa06ae3645ff0106145f842b5; path=/
> Expires: Thu, 19 Nov 1981 08:52:00 GMT
> Cache-Control: no-store, no-cache, must-revalidate, post-check=0
> Pragma: no-cache
> Set-Cookie: c_id=bla; path=/
> Connection: close
> Content-Type: text/html

msg = mimetools.Message(response) # response must have .read() method
cookie_h = msg["Set-Cookie"]

cookie = Cookie.Cookie("Set-Cookie: %s" % cookie_h)
print cookie["PHPSESSID"].value
print cookie["PHPSESSID"]["path"]

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.




More information about the Python-list mailing list