Skip to Content
Perl To Python Migration
book

Perl To Python Migration

by Martin C. Brown
November 2001
Beginner
320 pages
5h 53m
English
Pearson Business
Content preview from Perl To Python Migration

HANDLING COOKIES

In Perl the CGI::Cookie module will create a cookie HTTP header for you by supplying the cookie data, domain, and expiry date to a new cookie object. For example

my $query = new CGI;
my $cookietext = $query->cookie(-name => 'sample',
                               -value => { login =>
                                           $login,
                                           other =>
                                          'Other'
                               -path => '/',
                               -domain =>
                                   'mcwords.mchome.com',
                               -expires => '+1y');
print "Set-Cookie: $cookietext\n";

In Python there is a third party module called Cookie which will build a new cookie for you. For example, we could rewrite the above using the Cookie module like this:

 import Cookie cookie = Cookie.SmartCookie() cookie['sample'] = 'login=%s; other=Other' % (login) cookie['sample']['path'] = '/' cookie['sample']['domain'] = 'mcwords.mchome.com' cookie['sample']['expires'] ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl in a Nutshell

Perl in a Nutshell

Nathan Patwardhan, Ellen Siever, Stephen Spainhour
Perl by Example

Perl by Example

Ellie Quigley
Perl Hacks

Perl Hacks

Chromatic, Damian Conway, Curtis Ovid Poe, Curtis (Ovid) Poe

Publisher Resources

ISBN: 0201734885Purchase book