Trying to set a cookie within a python script

Νίκος nikos.the.gr33k at gmail.com
Tue Aug 3 19:17:28 CEST 2010


>On 3 Αύγ, 18:41, Dave Angel <da... at ieee.org> wrote:
> > Different encodings equal different ways of storing the data to the
> > media, correct?
>
> Exactly. The file is a stream of bytes, and Unicode has more than 256
> possible characters. Further, even the subset of characters that *do*
> take one byte are different for different encodings. So you need to tell
> the editor what encoding you want to use.

For example an 'a' char in iso-8859-1 is stored different than an 'a'
char in iso-8859-7 and an 'a' char of utf-8 ?


> > What is a "String Literal" ?
>
> In python, a string literal is enclosed by single quotes, double quotes,
> or triples.
> myvar = u"tell me more"
> myvar = u'hello world'
> The u prefix is used in python 2.x to convert to Unicode; it's not
> needed in 3.x and I forget which one you're using.

I use Python 2.4 and never used the u prefix.

i Still don't understand the difference between a 'string' and a
'string literal'

If i save a file as iso-8859-1 but in some of my variabels i use greek
characters instead of telling the browser to change encoding and save
the file as utf-8 i can just use the u prefix like your examples to
save the variables as iso-8859-1 ?

> I don't understand your wording. Certainly the server launches the
> python script, and captures stdout. It then sends that stream of bytes
> out over tcp/ip to the waiting browser. You ask when does it become html
> ? I don't think the question has meaning.

http cliens send request to http server(apache) , apache call python
interpreter python call mysql to handle SQL queries right?

My question is what is the difference of the python's script output
and the web server's output to the http client?

Who is producing the html code? the python output or the apache web
server after it receive the python's output?


> The more I think about it, the more I suspect your confusion comes
> because maybe you're not using the u-prefix on your literals. That can
> lead to some very subtle bugs, and code that works for a while, then
> fails in inexplicable ways.

I'm not sure whatr exaclty the do just yet.

For example if i say mymessage = "καλημέρα" and the i say mymessage =
u"καλημέρα" then the 1st one is a greek encoding variable while the
2nd its a utf-8 one?

So one script can be in some encoding and some parts of the script
like th2 2nd varible can be in another?

==============================
Also can you please help me in my cookie problem as to why only the
else block executed each time and never the if?

here is the code:

[code]
if os.environ.get('HTTP_COOKIE') and cookie.has_key('visitor') ==
'nikos':		#if visitor cookie exist
	print "ΑΠΟ ΤΗΝ ΕΠΟΜΕΝΗ ΕΠΙΣΚΕΨΗ ΣΟΥ ΘΑ ΣΕ ΥΠΟΛΟΓΙΖΩ ΩΣ ΕΠΙΣΚΕΠΤΗ
ΑΥΞΑΝΟΝΤΑΣ ΤΟΝ ΜΕΤΡΗΤΗ!"
	cookie['visitor'] = ( 'nikos', time() - 1 )		#this cookie will expire
now
else:
	print "ΑΠΟ ΔΩ ΚΑΙ ΣΤΟ ΕΞΗΣ ΔΕΝ ΣΕ ΕΙΔΑ, ΔΕΝ ΣΕ ΞΕΡΩ, ΔΕΝ ΣΕ ΑΚΟΥΣΑ!
ΘΑ ΕΙΣΑΙ ΠΛΕΟΝ Ο ΑΟΡΑΤΟΣ ΕΠΙΣΚΕΠΤΗΣ!!"
	cookie['visitor'] = ( 'nikos', time() + 60*60*24*365 )		#this cookie
will expire in an year
[/code]

How do i check if the cookie is set and why if set never gets unset?!



More information about the Python-list mailing list