Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Mark Lawrence

On 08/10/2013 23:52, Νίκος Αλεξόπουλος wrote:



Is there something i can try to isolate the problem and make it work?



As you are the problem why not try solitary confinement? :)

--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence

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


Pygame with python 3.3.2

2013-10-09 Thread markotaht
>From pygame tutorials i copied this example:
import pygame
 
class spritesheet(object):
def __init__(self, filename):
try:
self.sheet = pygame.image.load(filename).convert()
except pygame.error, message:
print('Unable to load spritesheet image:', filename)
raise SystemExit, message
# Load a specific image from a specific rectangle
def image_at(self, rectangle, colorkey = None):
"Loads image from x,y,x+offset,y+offset"
rect = pygame.Rect(rectangle)
image = pygame.Surface(rect.size).convert()
image.blit(self.sheet, (0, 0), rect)
if colorkey is not None:
if colorkey is -1:
colorkey = image.get_at((0,0))
image.set_colorkey(colorkey, pygame.RLEACCEL)
return image
# Load a whole bunch of images and return them as a list
def images_at(self, rects, colorkey = None):
"Loads multiple images, supply a list of coordinates" 
return [self.image_at(rect, colorkey) for rect in rects]
# Load a whole strip of images
def load_strip(self, rect, image_count, colorkey = None):
"Loads a strip of images and returns them as a list"
tups = [(rect[0]+rect[2]*x, rect[1], rect[2], rect[3])
for x in range(image_count)]
return self.images_at(tups, colorkey)

When ever i run it i get syntax error on this line except pygame.error, message:
There are no example to show what happens, because, this doesent even work, 
untile the error is fixed. My guess is, that this has something to do with the 
python versions. But im not very familiar with the changes so i dont know how 
to fix it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Ben Finney
Νίκος Αλεξόπουλος  writes:

> When a user hits my link on another website, for exmaple they are on
> ypsilandio.gr and they hit the link of superhost.gr then a new entry
> with a new cookie is appearing into my visitors table!
>
> Where is the old cookie that was saved in my browser so it will get
> retrieved? I use chrome and i notice that when a visitor comes to my
> webpage form a referrer link the cookie's ID is always set to a new
> random value.

None of this has to do with Python. Please do not ask this Python
doscussion forum to educate you on how HTTP operates.

-- 
 \  “How many people here have telekenetic powers? Raise my hand.” |
  `\  —Emo Philips |
_o__)  |
Ben Finney

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


Re: Pygame with python 3.3.2

2013-10-09 Thread Mark Lawrence

On 09/10/2013 08:03, markot...@gmail.com wrote:

 From pygame tutorials i copied this example:
import pygame

class spritesheet(object):
 def __init__(self, filename):
 try:
 self.sheet = pygame.image.load(filename).convert()
 except pygame.error, message:
 print('Unable to load spritesheet image:', filename)
 raise SystemExit, message
 # Load a specific image from a specific rectangle
 def image_at(self, rectangle, colorkey = None):
 "Loads image from x,y,x+offset,y+offset"
 rect = pygame.Rect(rectangle)
 image = pygame.Surface(rect.size).convert()
 image.blit(self.sheet, (0, 0), rect)
 if colorkey is not None:
 if colorkey is -1:
 colorkey = image.get_at((0,0))
 image.set_colorkey(colorkey, pygame.RLEACCEL)
 return image
 # Load a whole bunch of images and return them as a list
 def images_at(self, rects, colorkey = None):
 "Loads multiple images, supply a list of coordinates"
 return [self.image_at(rect, colorkey) for rect in rects]
 # Load a whole strip of images
 def load_strip(self, rect, image_count, colorkey = None):
 "Loads a strip of images and returns them as a list"
 tups = [(rect[0]+rect[2]*x, rect[1], rect[2], rect[3])
 for x in range(image_count)]
 return self.images_at(tups, colorkey)

When ever i run it i get syntax error on this line except pygame.error, message:
There are no example to show what happens, because, this doesent even work, 
untile the error is fixed. My guess is, that this has something to do with the 
python versions. But im not very familiar with the changes so i dont know how 
to fix it.



From http://docs.python.org/3.0/whatsnew/3.0.html "Change from except 
exc, var to except exc as var. See PEP 3110."  You might also like to 
see this http://docs.python.org/3/howto/pyporting.html


--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence

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


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Νίκος Αλεξόπουλος

Στις 9/10/2013 4:33 πμ, ο/η Steven D'Aprano έγραψε:

On Wed, 09 Oct 2013 01:52:44 +0300, Νίκος Αλεξόπουλος wrote:


Is there something i can try to isolate the problem and make it work?


Of course there is. That is part of the job of the developer: hard work
trying dozens, maybe hundreds of different things until you isolate the
problem. There are no shortcuts, no magic button you can push to
immediately identify the source of the problem.

If you are not willing to spend hours, maybe days or weeks, working on
this problem, then you should hire a programmer who is, and stop fooling
yourself that you are a professional developer. An amateur who programs
for fun can just give up when a problem becomes too difficult and isn't
fun any more. A professional has to keep going.

Start by identifying which browsers this occurs on. You should test using
at least Firefox, Internet Explorer, Safari, Chrome and Opera, for as
many different versions as you can find. You should also test with less
common browsers such as Konqueror, Epiphany, lynx, links and others. See
if there is a pattern in which ones behave as you expect and which ones
don't.

You should also test with and without cookies enabled, ad-blockers, and
similar. Maybe you can replicate the problem if (say) the user accepts
the first cookie, then rejects it when they click Back.

If this only occurs with a single version of a single browser with
cookies enabled and no ad blocker, you should report it as a bug to the
browser developers. Make sure you give them enough detail to replicate
the problem. If it's an old version, they'll probably say Won't Fix, and
you'll just have to accept that your cookie handling code won't work for
some percentage of visitors.

Have you checked that the server is setting the cookie values you expect?
Have you checked the value of the cookie in the browser? If you don't
know how to do these things, this site will teach you everything you need:

https://duckduckgo.com/

Follow the links until you reach enlightenment. There are *thousands* of
pages on debugging programming problems.

If you find it is broken with *all* of the above browsers, then you
should suspect a bug in your Python code. In that case, since other
people have failed to reproduce the reported problem, you are obviously
doing something different than what you are telling us you are doing.
Only in this case should you come back here to ask for help with your
Python code. Before you do, read this, and follow the instructions:

http://www.sscce.org/

If you are not willing to do these things, then stop pretending to be a
professional developer, and admit that you are only programming for fun.
There is no shame in this -- not everyone is cut out to be a professional
programmer, just as not everybody makes a good doctor or taxi driver or
carpenter.



By whole counters project is based on cookie handling now


If you cannot solve the cookie problem, maybe you should reconsider the
decision to rely on cookies.




I managed t overcome it like this:

cur.execute('''UPDATE visitors SET cookieID = %s, host = %s, city = %s, 
useros = %s, browser = %s, ref = %s, hits = hits + 1, lastvisit = %s 
WHERE counterID = %s and host = %s''',

(cookieID, host, city, useros, 
browser, ref, lastvisit, cID, host) )

if not cur.rowcount:
# if first time visitor on this page, create new record, if visitor 
exists then update record
cur.execute('''INSERT INTO visitors (counterID, cookieID, host, city, 
useros, browser, ref, lastvisit) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
ON DUPLICATE KEY UPDATE host = %s, city = %s, useros = %s, browser = %s, 
ref = %s, hits = hits + 1, lastvisit = %s''',
(cID, cookieID, host, city, useros, browser, ref, lastvisit, host, city, 
useros, browser, ref, lastvisit) )



But thats a not clear way to handle the cookie because i involve host to 
help me identify its recorde since when my website hit comes from areferrer.


i also tried adding the domain when i set the cookie but this didnt 
helped me at all:


# initialize cookie and retrieve cookie from clients browser
cookie = cookies.SimpleCookie( os.environ['HTTP_COOKIE'] )

if cookie.get('ID') is not None:
cookieID = cookie['ID'].value
else:
cookieID = random.randrange(0, )
cookie['ID'] = cookieID
cookie['ID']['domain'] = ".superhost.gr"
cookie['ID']['path'] = '/'
cookie["ID"]["expires"] = 60*60*24*365  # this cookie will 
expire in a year

i read some links from duckduckgo but that didnt help me solve this.
Please someone esle try to reproduce the problem by just using cgi and 
not mod_wsgi.


ps. Really why duckduckgo and not google.com ?

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


Re: Encoding of surrogate code points to UTF-8

2013-10-09 Thread wxjmfauth
Le mercredi 9 octobre 2013 08:20:05 UTC+2, Steven D'Aprano a écrit :
> 
> 
> > http://www.unicode.org/versions/Unicode6.2.0/ch02.pdf#G13708 "All three
> 
> > encoding forms can be used to represent the full range of encoded
> 
> > characters in the Unicode Standard; ... Each of the three Unicode
> 
> > encoding forms can be efficiently transformed into eith er of the other
> 
> > two without any loss of data."
> 
> 

Yes, 

and what Unicode.org does not say is that these coding
schemes (like any coding scheme) should be used in an
exclusive way.

Probably, because it is too obvious to understand.

jmf


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


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Mark Lawrence

On 09/10/2013 09:24, Νίκος Αλεξόπουλος wrote:

You have been told repeatedly that your questions have nothing to do 
with Python, e.g. Ben Finney just over an hour ago "None of this has to 
do with Python. Please do not ask this Python doscussion forum to 
educate you on how HTTP operates."


Please be courteous enough to take your questions to an appropriate forum.

--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence

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


Re: Can ay one help me on pysvn , i want to capture the log and status of checkout call .....

2013-10-09 Thread bab mis
On Wednesday, October 9, 2013 11:39:04 AM UTC+5:30, bab mis wrote:
> 

Here  is the code i am trying:



  2 from pysvn import wc_status_kind
  3 import pysvn
  4
import os, os.path
  6 import re
  7
  8 def createSVNClient():
  9 """Create a pysvn client, and setup some callback and options.
 10 """
 11
 12 def login(*args):
 13 return True, 'root', 'pass', False
 16
 17 client = pysvn.Client()
 18 client.set_interactive(True)
 19 client.callback_get_login = login
 20 return client
 21
 22 client = createSVNClient()

 23 link = "http://demo.com/svn/trunk";
 24 path = '/tmp/ux'
 25 client.exception_style = 1
 26
 27 try:
 28 revision = client.checkout(link, path, recurse=True)





primary intention is

revision = client.checkout(link, path, recurse=True)

After this how can i check the exit code and capture the specific log that 
would have generated during this transaction of svn co command internally.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Encoding of surrogate code points to UTF-8

2013-10-09 Thread Ned Batchelder

On 10/9/13 4:22 AM, wxjmfa...@gmail.com wrote:

Le mercredi 9 octobre 2013 08:20:05 UTC+2, Steven D'Aprano a écrit :



http://www.unicode.org/versions/Unicode6.2.0/ch02.pdf#G13708 "All three
encoding forms can be used to represent the full range of encoded
characters in the Unicode Standard; ... Each of the three Unicode
encoding forms can be efficiently transformed into eith er of the other
two without any loss of data."



Yes,

and what Unicode.org does not say is that these coding
schemes (like any coding scheme) should be used in an
exclusive way.


Can you clarify what you mean by "in an exclusive way"?

--Ned.


Probably, because it is too obvious to understand.

jmf




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


ePIPE exception received when other end can't send an RST - how come?

2013-10-09 Thread jkn
Hello there
I am experimenting with a simple python script which establishes a TCP 
connection, over GPRS, to a server. It then periodically sends a small block of 
data (60 bytes or so) to the server.

I then disconnect the GPRS antenna on this client machine (I am actually 
investigating the behaviour of an independant bit of C++ code; the python is 
really being used as a test bench).

What I then see is that the number of bytes in the socket's output buffer 
builds up, and I then get a ePIPE exception (~SIGPIPE signal) in my script.

Now my copy of Richard Steven's 'Unix Network programming' says:

‘when a process writes to a socket that has received an RST, the SIGPIPE signal 
is sent to the process’

My python code is very simple: something like:

{{{
# setup

gSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
gSock.connect((IP_ADDR, IP_PORT))

p = MyPacket()
while 1:
try:
gSock.send(p)
except socket.error, e:
# display exception
except IOError, e
# ePIPE exception encountered here - but why?

time.sleep(15)

}}}

I am trying to understand how the ePIPE exception can occur, given my scenario, 
and whether it is due to my using Python, or might also be applicable to my C++ 
code. Surely, if I have disconnected the antenna, the server will have had no 
opportunity to send an RST? Is there another mechanism that might be causing 
the ePIPE?

I'm running Python 2.7.4 under x86 Kubuntu Linux, and python 2.4 on an embedded 
ARM Linux.

Thanks for any thoughts.

J^n



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


Re: Encoding of surrogate code points to UTF-8

2013-10-09 Thread Neil Cerutti
On 2013-10-09, Ned Batchelder  wrote:
> On 10/9/13 4:22 AM, wxjmfa...@gmail.com wrote:
>> and what Unicode.org does not say is that these coding schemes
>> (like any coding scheme) should be used in an exclusive way.
>
> Can you clarify what you mean by "in an exclusive way"?

Ned, pay no attention to the person whalopping that dead horse.

-- 
Neil Cerutti
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can ay one help me on pysvn , i want to capture the log and status of checkout call .....

2013-10-09 Thread Joel Goldstick
On Wed, Oct 9, 2013 at 5:53 AM, bab mis  wrote:
> On Wednesday, October 9, 2013 11:39:04 AM UTC+5:30, bab mis wrote:
>>
>
> Here  is the code i am trying:
>
>
>
>   2 from pysvn import wc_status_kind
>   3 import pysvn
>   4
> import os, os.path
>   6 import re
>   7
>   8 def createSVNClient():
>   9 """Create a pysvn client, and setup some callback and options.
>  10 """
>  11
>  12 def login(*args):
>  13 return True, 'root', 'pass', False
>  16
>  17 client = pysvn.Client()
>  18 client.set_interactive(True)
>  19 client.callback_get_login = login
>  20 return client
>  21
>  22 client = createSVNClient()
>
>  23 link = "http://demo.com/svn/trunk";
>  24 path = '/tmp/ux'
>  25 client.exception_style = 1
>  26
>  27 try:
>  28 revision = client.checkout(link, path, recurse=True)
>
>
>
>
>
> primary intention is
>
> revision = client.checkout(link, path, recurse=True)
>
> After this how can i check the exit code and capture the specific log that 
> would have generated during this transaction of svn co command internally.
> --
> https://mail.python.org/mailman/listinfo/python-list

have you checked the pysvn mailing list:
http://pysvn.tigris.org/ds/viewForums.do

-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Good Python Book

2013-10-09 Thread Schneider

Hi List,

I'm looking for a good advanced python book. Most books I looked at up 
to now are on beginners level.
I don't need a reference (that's online) or a book explaining how to use 
the interpreter or how to use list comprehensions on the one side and 
skipping topics like decorators, metaclasses on the other side.


any suggestions?

bg,
Johannes

--
GLOBE Development GmbH
Königsberger Strasse 260
48157 MünsterGLOBE Development GmbH
Königsberger Strasse 260
48157 Münster
0251/5205 390

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


öpcaö variable refrenced before assignment

2013-10-09 Thread markotaht
fail4 = "palgad.txt"

f4 = open(fail4, "r")

def koguarv_ridu failis(f):
for i, l in enumerate(f):
pass
return i+1

def palgad(f4):
palgad = 0
while True:
f4r = f4.readline()
if f4r == "":
break
palgad += int(f4r[f4r.find(";")+1:])
return palgad

def kuu_keskmine(palgad, f):
return palgad/koguarv_ridu_failis(f)

print(kuu_keskmine(palgad(f4), f4))


Why does it give me local variable "i" referenced before assignment in 
koguarv_ridu_failis(f) on the return i+1 line
But if i do directly koguarv_ridu_failis(f4) then i get correct antswer.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: öpcaö variable refrenced before assignment

2013-10-09 Thread Chris Angelico
On Thu, Oct 10, 2013 at 1:20 AM,   wrote:
> def koguarv_ridu failis(f):
> for i, l in enumerate(f):
> pass
> return i+1

This will throw the exception you're seeing (by the way, it helps a
LOT to actually copy and paste the full error, including the traceback
- fortunately I can work this one out without) if the enumerate()
doesn't yield any results. The whole loop gets skipped, nothing gets
assigned to i. But the real question is: why are you not getting
anything to enumerate?

> def palgad(f4):
> palgad = 0
> while True:
> f4r = f4.readline()
> if f4r == "":
> break
> palgad += int(f4r[f4r.find(";")+1:])
> return palgad
>
> def kuu_keskmine(palgad, f):
> return palgad/koguarv_ridu_failis(f)

And this would be why. Your first function is consuming the whole file
(up to a blank line, but I'm guessing your file doesn't have any), and
there's nothing left for ridu to read.

But first, a word on naming. You've used the name palgad in four distinct ways:

1) The function introduced in 'def palgad(f4)'
2) A local variable inside #1, which accumulates the returned integer
3) A local variable inside keskmine, which happens to be passed the
value that #1 returned
4) The file name, palgad.txt

This is not a problem to the interpreter, as they're quite separate,
but your first three senses are very confusing to a human.

So. You have a major problem here in that you're calculating a number
and then trying to divide it by the number of lines. There's a much
MUCH simpler, cleaner, _and_ safer way to do that: just count up the
lines at the same time as you calculate palgad. I'll let you do the
specifics, but that's what I would advise you to explore :)

Best of luck!

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Denis McMahon
On Wed, 09 Oct 2013 01:52:44 +0300, Νίκος Αλεξόπουλος wrote:

> Στις 8/10/2013 10:29 μμ, ο/η Denis McMahon έγραψε:

>> Have you checked the cookie jar in the browser to see what value the
>> cookie has? Is that the value you think it should have? Note that
>> checking the cookie jar is a browser topic, not a python topic, so if
>> you don't know how to do that you're going to have to find the right
>> place to ask, WHICH IS NOT HERE!

>> Ideally you need to check what the server thinks it's setting the
>> cooking to, what the browser thinks it received as the cookie, and what
>> the server gets back afterwards to work out where the error is
>> happening.

> Is there something i can try to isolate the problem and make it work?
> By whole counters project is based on cookie handling now

See those last two paragraphs there that you quoted. You should have read 
them.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


UnicodeEncodeError: SOLVED

2013-10-09 Thread Walter Hurry
Many thanks to those prepared to forgive my transgression in the 
'Goodbye' thread. I mentioned there that I was puzzled by a 
UnicodeEncodeError, and said I would rise it as a separate thread.

However, via this link, I was able to resolve the issue myself:

http://stackoverflow.com/questions/3224268/python-unicode-encode-error

Nevertheless, thanks again for the kind words.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Denis McMahon
On Wed, 09 Oct 2013 11:24:35 +0300, Νίκος Αλεξόπουλος wrote:

> Please someone esle try to reproduce the problem by just using cgi and
> not mod_wsgi.

I have no intention of reconfiguring my web server just to prove that 
your code isn't working. We already know that your code isn't working.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: öpcaö variable refrenced before assignment

2013-10-09 Thread Jussi Piitulainen
markot...@gmail.com writes:

> fail4 = "palgad.txt"
> 
> f4 = open(fail4, "r")
> 
> def koguarv_ridu failis(f):
> for i, l in enumerate(f):
> pass
> return i+1
>
> def palgad(f4):
> palgad = 0
> while True:
> f4r = f4.readline()
> if f4r == "":
> break
> palgad += int(f4r[f4r.find(";")+1:])
> return palgad
> 
> def kuu_keskmine(palgad, f):
> return palgad/koguarv_ridu_failis(f)
> 
> print(kuu_keskmine(palgad(f4), f4))
> 
> 
> Why does it give me local variable "i" referenced before assignment
> in koguarv_ridu_failis(f) on the return i+1 line

Because palgad(f4) consumed f, the loop in koguarv_ridu_failis is not
executed even once.

> But if i do directly koguarv_ridu_failis(f4) then i get correct
> antswer.

Try to do just koguarv_ridu_failis(f4) twice. You'll get the same
error on the second attempt.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Νίκος Αλεξόπουλος

Στις 9/10/2013 5:43 μμ, ο/η Denis McMahon έγραψε:

On Wed, 09 Oct 2013 01:52:44 +0300, Νίκος Αλεξόπουλος wrote:


Στις 8/10/2013 10:29 μμ, ο/η Denis McMahon έγραψε:



Have you checked the cookie jar in the browser to see what value the
cookie has? Is that the value you think it should have? Note that
checking the cookie jar is a browser topic, not a python topic, so if
you don't know how to do that you're going to have to find the right
place to ask, WHICH IS NOT HERE!



Ideally you need to check what the server thinks it's setting the
cooking to, what the browser thinks it received as the cookie, and what
the server gets back afterwards to work out where the error is
happening.



Is there something i can try to isolate the problem and make it work?
By whole counters project is based on cookie handling now


See those last two paragraphs there that you quoted. You should have read
them.


ok so then tell me where i should ask this.

--
What is now proved was at first only imagined! & WebHost

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


datetime.timedelta.replace?

2013-10-09 Thread Skip Montanaro
Datetime objects have a replace method, but timedelta objects don't.
If I take the diff of two datetimes and want to zero out the
microseconds field, is there some way to do it more cleanly than this?

delta = dt1 - dt2
zero_delta = datetime.timedelta(days=delta.days, seconds=delta.seconds)

I guess that's not bad, but replace() seems cleaner (or at least more
congruent with datetime objects).

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: öpcaö variable refrenced before assignment

2013-10-09 Thread markotaht
So i got it working, by saving palgad in a variable, before printing it and i 
count the lines into a global variable. Ty
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Joel Goldstick
On Wed, Oct 9, 2013 at 11:00 AM, Νίκος Αλεξόπουλος
 wrote:
> Στις 9/10/2013 5:43 μμ, ο/η Denis McMahon έγραψε:
>
>> On Wed, 09 Oct 2013 01:52:44 +0300, Νίκος Αλεξόπουλος wrote:
>>
>>> Στις 8/10/2013 10:29 μμ, ο/η Denis McMahon έγραψε:
>>
>>
 Have you checked the cookie jar in the browser to see what value the
 cookie has? Is that the value you think it should have? Note that
 checking the cookie jar is a browser topic, not a python topic, so if
 you don't know how to do that you're going to have to find the right
 place to ask, WHICH IS NOT HERE!
>>
>>
 Ideally you need to check what the server thinks it's setting the
 cooking to, what the browser thinks it received as the cookie, and what
 the server gets back afterwards to work out where the error is
 happening.
>>
>>
>>> Is there something i can try to isolate the problem and make it work?
>>> By whole counters project is based on cookie handling now
>>
>>
>> See those last two paragraphs there that you quoted. You should have read
>> them.
>>
> ok so then tell me where i should ask this.
>


I already told you where to learn about cookies.  Try that first.
People will be nicer to your questions if you show you are willing to
come prepared.  As to where to ask -- perhaps there is an http mailing
list.  Your code can't work if you don't know how cookies work.
-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: öpcaö variable refrenced before assignment

2013-10-09 Thread Mark Lawrence

On 09/10/2013 16:15, markot...@gmail.com wrote:

So i got it working, by saving palgad in a variable, before printing it and i 
count the lines into a global variable. Ty



You are hereby placed in detention for one hour this evening.  You will 
spend the whole hour writing repeatedly "I must remember to place things 
in context when replying to the Python main mailing list/news group". 
Do you understand this?


--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence

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


Receive packet using socket

2013-10-09 Thread tspiegelman
Hey all,

I am trying to use socket to send / receive a packet (want to recreate some 
functionality of hping3 and port it to windows and mac as a tcp ping).  I am 
having some problems with the recv functionality of socket.  Below is the 
script I am using.  I get an ack from the server (used wireshark to ensure it 
was working) when I run this, but the script doesn't see the ack for some 
reason and the script exits with this error or a timeout:

  Traceback (most recent call last):
  File "./tcpgcmtesttristedit.py", line 21, in 
s.recv(1024)
socket.error: [Errno 104] Connection reset by peer

Here is the script:

import socket
import time

numberofpackets = int(raw_input("How many packets should be sent?\n> "))
hostname = 'mtalk.google.com'
port = 5228

for i in range(numberofpackets):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(4)
s.connect((hostname, port))
s.send('data')
start_time = time.time()
s.recv(24)
print time.time() - start_time
s.close()


Any help would be much appreciated.  Thanks, Tom.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Mark Lawrence

On 09/10/2013 16:00, Νίκος Αλεξόπουλος wrote:


ok so then tell me where i should ask this.



Google, bing, duckduckgo, ask, yahoo ...

--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence

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


super in Python 3 and variadic arguments

2013-10-09 Thread Marco Buttu

Given this class:

>>> class A:
... def afoo(*args):
... print(args)

in Python 3 we can write the following class:

>>> class B(A):
... def bfoo(*args):
... super(B, args[0]).afoo(*args[1:])
...
>>> B().bfoo(1, 2, 3)
(<__main__.B object at 0x7f5b3bde48d0>, 1, 2, 3)


without giving arguments to super, in this way:

>>> class B(A):
... def bfoo(self, *args):
... super().afoo(*args)
...
>>> B().bfoo(1, 2, 3)
(<__main__.B object at 0x7f5b3bdea0d0>, 1, 2, 3)

But it does not work in this case:

>>> class B(A):
... def bfoo(*args):
... super().afoo(*args[1:])
...
>>> B().bfoo(1, 2, 3)
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 3, in bfoo
RuntimeError: super(): no arguments

How come?
--
Marco Buttu
--
https://mail.python.org/mailman/listinfo/python-list


RE: Code golf challenge: XKCD 936 passwords

2013-10-09 Thread Nick Cash
>> # Python-2, sorry
>> import os
>> print list(set(open('/usr/share/dict/words')))[os.getpid():][:4]

> So that steps by your pid? 

Not really. It seems to rely on list(set(...)) kinda randomizing order... which 
is definitely not safe without hash randomization.  

But this brings up an interesting concept... if we can assume Python 2.7 with 
the -R flag, or Python 3.3+, I think we do get true pseudo-randomization out of 
list(set(...))... which means we can trim some!

print(list(set(open('/usr/share/dict/words')))[:4])

No module imports needed! Although it's not as pretty as the original post, but 
neither was Roy's.

-Nick Cash
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Receive packet using socket

2013-10-09 Thread tspiegelman
BTW what I am trying to accomplish is easily done in hping3 using this command:
hping3 mtalk.google.com -S -p 5228 

I just want those same kind of results using python so I can make an exe out of 
it.  

On Wednesday, October 9, 2013 11:37:39 AM UTC-4, tspie...@amplify.com wrote:
> Hey all,
> 
> 
> 
> I am trying to use socket to send / receive a packet (want to recreate some 
> functionality of hping3 and port it to windows and mac as a tcp ping).  I am 
> having some problems with the recv functionality of socket.  Below is the 
> script I am using.  I get an ack from the server (used wireshark to ensure it 
> was working) when I run this, but the script doesn't see the ack for some 
> reason and the script exits with this error or a timeout:
> 
> 
> 
>   Traceback (most recent call last):
> 
>   File "./tcpgcmtesttristedit.py", line 21, in 
> 
> s.recv(1024)  
> 
> socket.error: [Errno 104] Connection reset by peer
> 
> 
> 
> Here is the script:
> 
> 
> 
> import socket
> 
> import time
> 
> 
> 
> numberofpackets = int(raw_input("How many packets should be sent?\n> "))
> 
> hostname = 'mtalk.google.com'
> 
> port = 5228
> 
> 
> 
> for i in range(numberofpackets):
> 
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> 
> s.settimeout(4)
> 
> s.connect((hostname, port))
> 
> s.send('data')
> 
> start_time = time.time()
> 
> s.recv(24)
> 
> print time.time() - start_time
> 
> s.close()
> 
> 
> 
> 
> 
> Any help would be much appreciated.  Thanks, Tom.

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


Re: Applying 4x4 transformation to 3-element vector with numpy

2013-10-09 Thread Nobody
On Tue, 08 Oct 2013 23:10:16 -0700, John Nagle wrote:

> I only need affine transformations.  This is just moving
> the coordinate system of a point, not perspective rendering. I have to do
> this for a lot of points, and I'm hoping numpy has some way to do this
> without generating extra garbage on the way in and the way out.

In which case, Christian's answer is correct.

For an affine transformation, the bottom row of the 4x4 matrix will be
[0 0 0 1], so you have:

[x']   [a b c d] [x]   [ax+by+cz+d]
[y'] = [e f g h] [y] = [ex+fy+gz+h]
[z']   [i j k l] [z]   [ix+jy+kz+l]
[1 ]   [0 0 0 1] [1]   [1 ]

 => 

[x']   [ax+by+cz+d]   [a b c] [x]   [d]
[y'] = [ex+fy+gz+h] = [e f g] [y] + [h]
[z']   [ix+jy+kz+l]   [i j k] [z]   [l]

IOW:
xyz_ = m[:3,:3] * xyz + m[:3,3:]

(where xyz is a column vector or 3xN array)


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


Re: super in Python 3 and variadic arguments

2013-10-09 Thread Ned Batchelder

On 10/9/13 11:44 AM, Marco Buttu wrote:

Given this class:

>>> class A:
... def afoo(*args):
... print(args)

in Python 3 we can write the following class:

>>> class B(A):
... def bfoo(*args):
... super(B, args[0]).afoo(*args[1:])
...
>>> B().bfoo(1, 2, 3)
(<__main__.B object at 0x7f5b3bde48d0>, 1, 2, 3)


without giving arguments to super, in this way:

>>> class B(A):
... def bfoo(self, *args):
... super().afoo(*args)
...
>>> B().bfoo(1, 2, 3)
(<__main__.B object at 0x7f5b3bdea0d0>, 1, 2, 3)

But it does not work in this case:

>>> class B(A):
... def bfoo(*args):
... super().afoo(*args[1:])
...
>>> B().bfoo(1, 2, 3)
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 3, in bfoo
RuntimeError: super(): no arguments

How come?


The no-args super() call inspects the calling environment to determine 
the class and self.  "self" is the first local name stored in 
frame.f_code.co_localsplus, but *args doesn't put "args" into that entry 
of the code object.  Basically, super() is looking for the first regular 
argument in the function.


--Ned.


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


Re: Receive packet using socket

2013-10-09 Thread Nobody
On Wed, 09 Oct 2013 08:37:39 -0700, tspiegelman wrote:

> I am trying to use socket to send / receive a packet (want to recreate
> some functionality of hping3 and port it to windows and mac as a tcp
> ping).  I am having some problems with the recv functionality of socket. 
> Below is the script I am using.  I get an ack from the server (used
> wireshark to ensure it was working) when I run this, but the script
> doesn't see the ack for some reason and the script exits with this error
> or a timeout:

> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

If you're trying to send/receive individual packets, you need to use
SOCK_RAW (which normally requires root/administrator privilege).

> s.recv(24)

Alternatively, if you use a normal TCP stream socket, the receiver must
consume all data which is sent to it, and only close the socket after the
writer has closed its end. Depending upon the application-layer protocol,
this may involve some form of QUIT command, or a half-close using
the .shutdown() method.

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


Re: Re for Apache log file format

2013-10-09 Thread Piet van Oostrum
Sam Giraffe  writes:

> Hi,
>
> I am trying to split up the re pattern for Apache log file format and seem to 
> be having some
> trouble in getting Python to understand multi-line pattern:
>
> #!/usr/bin/python
>
> import re
>
> #this is a single line
> string = '192.168.122.3 - - [29/Sep/2013:03:52:33 -0700] "GET / HTTP/1.0" 302 
> 276 "-" "check_http/
> v1.4.16 (nagios-plugins 1.4.16)"'
>
> #trying to break up the pattern match for easy to read code
> pattern = re.compile(r'(?P\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+'
>  r'(?P\-)\s+'
>  r'(?P\-)\s+'
>  r'(?P\[(.*?)\])\s+'
>  r'(?P\"(.*?)\")\s+'
>  r'(?P\d{3})\s+'
>  r'(?P\d+)\s+'
>  r'(?P\"\")\s+'
>  r'(?P\((.*?)\))')
>
> match = re.search(pattern, string)
>
> if match:
>     print match.group('ip')
> else:
>     print 'not found'
>
> The python interpreter is skipping to the 'math = re.search' and then the 
> 'if' statement right
> after it looks at the , instead of moving onto  and so on.

Although you have written the regexp as a sequence of lines, in reality it is a 
single string, and therefore pdb will do only a single step, and not go into 
its "parts", which really are not parts.
>
> mybox:~ user$ python -m pdb /Users/user/Documents/Python/apache.py
>> /Users/user/Documents/Python/apache.py(3)()
> -> import re
> (Pdb) n
>> /Users/user/Documents/Python/apache.py(5)()
> -> string = '192.168.122.3 - - [29/Sep/2013:03:52:33 -0700] "GET / HTTP/1.0" 
> 302 276 "-"
> "check_http/v1.4.16 (nagios-plugins 1.4.16)"'
> (Pdb) n
>> /Users/user/Documents/Python/apache.py(7)()
> -> pattern = re.compile(r'(?P\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+'
> (Pdb) n
>> /Users/user/Documents/Python/apache.py(17)()
> -> match = re.search(pattern, string)
> (Pdb)

Also as Andreas has noted the r'(?P\"\")\s+' part is wrong. It should 
probably be 
r'(?P\".*?\")\s+'

And the r'(?P\((.*?)\))') will also not match as there is text outside 
the (). Should probably also be
r'(?P\".*?\")') or something like it.
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Denis McMahon
On Wed, 09 Oct 2013 18:00:28 +0300, Νίκος Αλεξόπουλος wrote:

> Στις 9/10/2013 5:43 μμ, ο/η Denis McMahon έγραψε:
>> On Wed, 09 Oct 2013 01:52:44 +0300, Νίκος Αλεξόπουλος wrote:
>>
>>> Στις 8/10/2013 10:29 μμ, ο/η Denis McMahon έγραψε:
>>
 Have you checked the cookie jar in the browser to see what value the
 cookie has? Is that the value you think it should have? Note that
 checking the cookie jar is a browser topic, not a python topic, so if
 you don't know how to do that you're going to have to find the right
 place to ask, WHICH IS NOT HERE!

 Ideally you need to check what the server thinks it's setting the
 cooking to, what the browser thinks it received as the cookie, and
 what the server gets back afterwards to work out where the error is
 happening.

>>> Is there something i can try to isolate the problem and make it work?
>>> By whole counters project is based on cookie handling now

>> See those last two paragraphs there that you quoted. You should have
>> read them.

> ok so then tell me where i should ask this.

In those two paragraphs I have told you what you need to do to isolate 
where your problem is occurring. If you don't know how to do that, then I 
commend to you the wealth of information that may be discovered using 
search engines. However, as we keep telling you, this group is not the 
right place to ask questions such as:

a) How do I see what's in my web browser's cookie jar?
b) How do I make my web server log the cookies it sends and receives?

For (a) you want information about your browser, not about python.
For (b) you want information about your web server, not about python.

Find the relevant forums and ask in them.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Denis McMahon
On Wed, 09 Oct 2013 18:00:28 +0300, Νίκος Αλεξόπουλος wrote:

> Στις 9/10/2013 5:43 μμ, ο/η Denis McMahon έγραψε:
>> On Wed, 09 Oct 2013 01:52:44 +0300, Νίκος Αλεξόπουλος wrote:
>>
>>> Στις 8/10/2013 10:29 μμ, ο/η Denis McMahon έγραψε:
>>
 Have you checked the cookie jar in the browser to see what value the
 cookie has? Is that the value you think it should have? Note that
 checking the cookie jar is a browser topic, not a python topic, so if
 you don't know how to do that you're going to have to find the right
 place to ask, WHICH IS NOT HERE!

 Ideally you need to check what the server thinks it's setting the
 cooking to, what the browser thinks it received as the cookie, and
 what the server gets back afterwards to work out where the error is
 happening.

>>> Is there something i can try to isolate the problem and make it work?
>>> By whole counters project is based on cookie handling now

>> See those last two paragraphs there that you quoted. You should have
>> read them.

> ok so then tell me where i should ask this.

In those two paragraphs I have told you what you need to do to isolate 
where your problem is occurring. If you don't know how to do that, then I 
commend to you the wealth of information that may be discovered using 
search engines. However, as we keep telling you, this group is not the 
right place to ask questions such as:

a) How do I see what's in my web browser's cookie jar?
b) How do I make my web server log the cookies it sends and receives?

For (a) you want information about your browser, not about python.
For (b) you want information about your web server, not about python.

Find the relevant forums and ask in them.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Mark Lawrence

On 09/10/2013 19:06, Denis McMahon wrote:


Find the relevant forums and ask in them.



Why am I thinking of this 
http://en.wikipedia.org/wiki/There%27s_a_Hole_in_My_Bucket ?


--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence

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


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Piet van Oostrum
Νίκος Αλεξόπουλος  writes:

>
> # initialize cookie and retrieve cookie from clients browser
> cookie = cookies.SimpleCookie( os.environ['HTTP_COOKIE'] )
>
> if cookie.get('ID') is not None:
>   cookieID = cookie['ID'].value
> else:
>   cookieID = random.randrange(0, )
>   cookie['ID'] = cookieID
>   cookie['ID']['domain'] = ".superhost.gr"
>   cookie['ID']['path'] = '/'
>   cookie["ID"]["expires"] = 60*60*24*365  # this cookie will 
> expire in a year
>
As Ian already has told you (but apparently you didn't pay attention to), your 
expires is wrong. So if your cookies disappear you should get this right first.

from datetime import datetime, timedelta
expiretime = datetime.utcnow() + timedelta(days=365)

cookie["ID"]["expires"] = expiretime.strftime("%a, %d %b %Y %H:%M:%S GMT")
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Tim Chase
On 2013-10-09 19:28, Mark Lawrence wrote:
> On 09/10/2013 19:06, Denis McMahon wrote:
>> Find the relevant forums and ask in them.
> 
> Why am I thinking of this 
> http://en.wikipedia.org/wiki/There%27s_a_Hole_in_My_Bucket ?

There's a bug in my program, dear newsgroup, dear newsgroup,
There's a bug in my program, dear newsgroup a bug.

Then fix it, dear Nikos, dear Nikos, dear Nikos,
Then fix it, dear Nikos, dear Nikos, fix it.

With what shall I fix it, dear newsgroup, dear newsgroup,
With what shall I fix it, dear newsgroup, with what?

The traceback, dear Nikos, dear Nikos, dear Nikos,
The traceback, dear Nikos, dear Nikos, traceback.

The problem's not Python, dear newsgroup, dear newsgroup,
The problem's not Python, dear newsgroup, what now?

Try Google, dear Nikos, dear Nikos, dear Nikos,
Try Google, dear Nikos, dear Nikos, Google.

But what shall I query, dear newsgroup, dear newsgroup,
But what shall I query, dear newsgroup, but what?

Some keywords, dear Nikos, dear Nikos, dear Nikos,
Some keywords, dear Nikos, dear Nikos, keywords.

I know it's off-topic, dear newsgroup, dear newsgroup,
I know it's off-topic, dear newsgroup, but help...


I can see the similarity ;-)

-tkc






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


PROPOSAL: PyCons in Africa

2013-10-09 Thread D.M. Procida
[reposted; the previous one didn't seem to make it out!]

I have a written a first draft outlining a proposal for a PyCon in a
sub-Saharan African nation where there has never been one.



There's an email list for people interested in becoming involved in the
idea: .

I'm seeking support for the proposal, from all parties who'd need to be
involved, from Python user groups in African cities where a PyCon might
be viable, to people who'd want to take part and the wider Python
community.

If anyone would like to add themselves to the list of potential
collaborators on this, please do so using GitHub:
. If you can't do that, just ask me to add the information.

There's a wiki on GitHub too:
.

I'm also seeking critical opinions on this, so if you think it's a poor
idea, or poorly conceived, or that there would be better ways to achieve
the aims in the proposal, or something key that's missing from it, I
would like to hear why you think that, so I can address any problems.

Thanks,

Daniele
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: class-private names and the Zen of Python

2013-10-09 Thread Charles Hixson

On 10/08/2013 06:24 AM, Steven D'Aprano wrote:

On Tue, 08 Oct 2013 12:13:48 +0200, Marco Buttu wrote:


In the following case:

  >>> class Foo:
... _Foo__a = 100
... __a = 33
...
  >>> Foo._Foo__a
33

I think this behavior, for a user who does not know the convention,
could be a surprise.

Yes, you are correct. It surprised me, and I've been using Python for
more than 15 years, and I know the convention of double-underscore name-
mangling.



Should be raising an exception (in order to inform
the user the transformation of the name __a have been replaced an
existing name) a possible --explicit-- alternative?

No, I don't think so. That would slow down class creation, for no real
benefit. Except for the name-mangling part, this is no different from:

class Spam:
 x = 23
 x = 42

If anything, something like PyLint or PyChecker could warn about it. But
the language itself is fine like it is.



Another question is: where is the place in which this transformation
occurs? Is it at the parser level, before the dictionary attribute is
gave as argument to the metaclass?

Good question!

I don't have a full answer, but I have a part answer: it occurs before
the metaclass sees the namespace:

py> class Meta(type):
... def __new__(meta, name, bases, namespace):
... print(namespace)
... return super().__new__(meta, name, bases, namespace)
...
py>
py> class Test(metaclass=Meta):
... __test = 'foo'
...
{'__module__': '__main__', '_Test__test': 'foo', '__qualname__': 'Test'}


so I think it is done by the parser.
Unless one wanted to add an error checking mode to the interpreter, not 
a totally bad idea, I agree that this is a job for external tools.  But 
perhaps that same external tool should be referenced in the 
documentation.  As it is I'm not clear that PyLint and/or PyChecker are 
kept current with the compiler/interpreter version, and I rather suspect 
that they aren't.  (This won't normally show up, as changes that they 
would catch happen quite rarely, but...)


OTOH, neither one really fits in as, say, an included module...they're 
more like idle, which now that I look does have a "check module" run 
option.  Perhaps that invokes one of them.  I note that Idle, itself, is 
barely mentioned in the documentation. Perhaps there needs to be a 
"tools" section.



--
Charles Hixson

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


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Mark Lawrence

On 09/10/2013 20:26, Tim Chase wrote:

On 2013-10-09 19:28, Mark Lawrence wrote:

On 09/10/2013 19:06, Denis McMahon wrote:

Find the relevant forums and ask in them.


Why am I thinking of this
http://en.wikipedia.org/wiki/There%27s_a_Hole_in_My_Bucket ?


There's a bug in my program, dear newsgroup, dear newsgroup,
There's a bug in my program, dear newsgroup a bug.

Then fix it, dear Nikos, dear Nikos, dear Nikos,
Then fix it, dear Nikos, dear Nikos, fix it.

With what shall I fix it, dear newsgroup, dear newsgroup,
With what shall I fix it, dear newsgroup, with what?

The traceback, dear Nikos, dear Nikos, dear Nikos,
The traceback, dear Nikos, dear Nikos, traceback.

The problem's not Python, dear newsgroup, dear newsgroup,
The problem's not Python, dear newsgroup, what now?

Try Google, dear Nikos, dear Nikos, dear Nikos,
Try Google, dear Nikos, dear Nikos, Google.

But what shall I query, dear newsgroup, dear newsgroup,
But what shall I query, dear newsgroup, but what?

Some keywords, dear Nikos, dear Nikos, dear Nikos,
Some keywords, dear Nikos, dear Nikos, keywords.

I know it's off-topic, dear newsgroup, dear newsgroup,
I know it's off-topic, dear newsgroup, but help...


I can see the similarity ;-)

-tkc



Great minds think alike? :)

--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence

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


Re: Code golf challenge: XKCD 936 passwords

2013-10-09 Thread random832
On Tue, Oct 8, 2013, at 18:27, Rob Day wrote:
> On 08/10/13 07:17, Chris Angelico wrote:
> > Who's up for some fun? Implement an XKCD-936-compliant password
> > generator in Python 3, in less code than this:
> >
> > print(*__import__("random").sample(open("/usr/share/dict/words").read().split("\n"),4))
> >
> >
> print("imploring epsilon decamp graveyard's")
> # Chosen by fair random sampling, guaranteed to be random

Of course, the choice of dictionary makes all the difference in the
world.

print('kayo wide sitz keen')
# Chosen by fair random sampling among SOWPODS words of four or fewer
letters.
# This is a set of 6870 words, XKCD Std. #936 requires a set of at least
2048.
# This password's 50.98 bits of entropy exceed the standard's
recommendations by 6.98.

This can be further improved to the standard's recommended entropy level
(but not strictly the same method) by selecting only the first one from
this set, and selecting the remaining four words from the set of 1416
words of 3 letters or less, for 44.14 bits of entropy:
print('axis ar cha tam')

Or, keeping with the spirit of the standard, mix the set of 1416 words 3
letters or less with 632 randomly selected words from the four-letter
set:
print('pal alp govs deb')
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Νίκος Αλεξόπουλος

Στις 9/10/2013 9:36 μμ, ο/η Piet van Oostrum έγραψε:

Νίκος Αλεξόπουλος  writes:



# initialize cookie and retrieve cookie from clients browser
cookie = cookies.SimpleCookie( os.environ['HTTP_COOKIE'] )

if cookie.get('ID') is not None:
cookieID = cookie['ID'].value
else:
cookieID = random.randrange(0, )
cookie['ID'] = cookieID
cookie['ID']['domain'] = ".superhost.gr"
cookie['ID']['path'] = '/'
cookie["ID"]["expires"] = 60*60*24*365  # this cookie will 
expire in a year


As Ian already has told you (but apparently you didn't pay attention to), your 
expires is wrong. So if your cookies disappear you should get this right first.

from datetime import datetime, timedelta
expiretime = datetime.utcnow() + timedelta(days=365)

cookie["ID"]["expires"] = expiretime.strftime("%a, %d %b %Y %H:%M:%S GMT")



Expire is not the issue here, as i have it is working with no problem.
when i print the cookie expiration time is calculated properly.
Something else is going worng.

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


Can anyone help on conflicts between Python 2.5 and 2.7

2013-10-09 Thread Errol Anderson
I maintain a Delphi program, AAA, that runs Python 2.5 scripts using the 
PythonForDelphi (P4D)interface.  I can install both Python 2.5 and Python 2.7 
on my computer and AAA is unaffected.   However one user of AAA uses another 
program, BBB, that requires Python 2.7.  When they run AAA, an error is 
generated that suggests that AAA has been directed to the Python 2.7 libraries.

The specific error is identified in Python27\lib\linecache.py line 127
with open(fullname, 'rU') as fp:

as compared with Python25\lib\linecache.py line 128
fp = open(fullname, 'rU')

It appears that the BBB program installs Python 2.7 to be the "default" Python 
version, although I do not know how this is done.  Assuming BBB cannot be 
changed, I would like to know how I can modify AAA so that it ignores any 
"default" settings and simply runs Python 2.5.

Regards

Errol Anderson



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


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Joel Goldstick
>
> Expire is not the issue here, as i have it is working with no problem.
> when i print the cookie expiration time is calculated properly.


> Something else is going worng.
>
Indeed!



> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Mark Lawrence

On 09/10/2013 23:03, Joel Goldstick wrote:


Expire is not the issue here, as i have it is working with no problem.
when i print the cookie expiration time is calculated properly.




Something else is going worng.


Indeed!



Well explained here http://en.wikipedia.org/wiki/User_error

--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence

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


Re: Tail recursion to while iteration in 2 easy steps

2013-10-09 Thread Charles Hixson

On 10/08/2013 02:22 AM, Steven D'Aprano wrote:

On Mon, 07 Oct 2013 20:27:13 -0700, Mark Janssen wrote:


But even putting that aside, even if somebody wrote such a
description, it would be reductionism gone mad. What possible light
on the problem would be shined by a long, long list of machine code
operations, even if written using assembly mnemonics?

Only that you've got a consistent, stable (and therefore,
formalizable) translation from your language to the machine.

You are mistaken to think that there is a single, one-to-one, mapping
between high-level code and machine code.

It's not mistaken.

I'm afraid it is. Reality trumps your theory. gcc, clang, Microsoft
Visual Studio, and all the many, many other C compilers do not generate
identical machine code even when targeting the same hardware. This is a
fact. It's not even the case that there is One True Way to implement a
particular program on a given hardware device and compilers merely are
buggy for doing something else. There are often different ways to
implement it which are equally good, the only difference being personal
preference.



Given a stable and formalized language definition,
there should only be continued optimization of the lexical and
procedural constructs into better machine code.

Better than what? "Continued" optimization? When you say "lexical and
procedural constructs", do you mean "source code"?



In the case of an
"interpreted" language like Python (which I'll define as a language
which includes a layer of indirection between the user and the machine,

Irrelevant. In the case of Python, there is a machine. The fact that it
is a VM rather than a physical machine is irrelevant. A machine is a
machine -- we could be talking about a Lisp Machine, a Forth Machine, a
x86 processor, an Motorola 68000, an Atom processor, one of those old
Russian mainframes that used three-state trits instead of two-state bits,
or even Babbage's Analytical Engine.

Besides, most modern CPUs don't execute machine code directly, they run
the machine code in a virtual machine implemented in hardware. So the
difference between Python and x86 machine code is just a matter of degree.




encouraging the nice benefits of interactivity), such optimization isn't
really apropos, because it's not the purpose of python to be optimal to
the machine as much as "optimal to the programmer".  In any case, while
such optimization can continue over time, they generally create new
compiler releases to indicate such changes.  The one-to-one mapping is
held by the compiler.

Such determinism *defines* the machine, otherwise you might as well get
rid of the notion of computer *science*.  All else is error, akin to
cosmic rays or magic.  Unless the source code changes, all else
remaining equal, the machine code is supposed to be the same, no matter
how many times it is compiled.

That is akin to saying that there is *only one* way to measure the speed
of light (say), standing in exactly the same place, using exactly the
same equipment, using precisely the same measurement techniques, and that
if we allow alternative methods for measuring the speed of light, physics
is no longer a science.



[Only if you use the exact source, compiler, switches, etc]] will the
output be the same.
And even that is not guaranteed.

Oh, and what would cause such non-determinism?

The compiler-writer, of course. A compiler is software, and is written by
a person, who can program it to do anything the writer wants. If the
writer wants the compiler to be non-deterministic, it can be.

Some viruses use a similar technique to try to avoid virus scanners. They
encrypt the payload, which is functionally equivalent to randomizing it
(except it can be reversed if you have the key) so as to defeat virus
scanners.

A more whimsical example: perhaps a mischievous compiler writer included
something like this in her compiler:


when compiling integer multiplication, INT * INT:
   if today is Tuesday:
 emit machine code that does multiplication using repeated addition
   otherwise:
 emit machine code that does multiplication using ADD and SHIFT


Both implementations of multiplication are perfectly valid. There may be
a performance difference, or there may not be. Since no sensible
programming language is going to specify the *detailed* machine code
implementation of its high-level operations, such a mischievous compiler
would still be valid.



Take, for example, the single high-level operation:

sort(alist)

What machine code will be executed? Obviously that will depend on the
sort algorithm used. There are *dozens*. Here are just a few:

Well, since you didn't specify your programming language, you're then
merely stating an English construct.

What difference does it make? But if it will make you feel better, I'm
specifying Hypertalk. You've probably never heard of it, but regardless,
it exists, and it has a sort command, and the high-level language does
not specify which of many sort algorithm

Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Steven D'Aprano
On Wed, 09 Oct 2013 18:06:05 +, Denis McMahon wrote:

> Find the relevant forums and ask in them.

In fairness to Nikos, that may not be an easy thing to do. I for one have 
*no idea* where to find an appropriate forum to learn about these sorts 
of web basics. comp.protocol.http doesn't exist :-)

I'm pretty sure that everyone here has been in this situation. We've 
pretty much all asked for recommendations "where is a good place to learn 
about X?", for some definition of X. That is a reasonable question, and 
"just google it" is *not* a reasonable answer, because search engines are 
not good at that sort of value judgement. Human beings are. And even the 
best of us have had days were we simply cannot come up with good search 
terms that find us what we need.

So, for the benefit of anyone, not just Nikos, who wants to learn about 
how browsers connect to web sites and how to run a web server, does 
anyone have any recommendation for tutorials, mailing lists, web forums 
or books which are suitable? Preferably things you have used yourself, 
and can personally vouch for being useful.

I'm pretty sure that *somebody* here has been in the position of needing 
to learn about running a website, and can point Nikos in the right 
direction (away from here). How did you learn? 

And if nobody is able, or willing, to answer? I've been in that position 
too, asking for help that nobody was able to give. It sucks, and you move 
on and do your best.


-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Python's and and Pythons or

2013-10-09 Thread Peter Cacioppi
I really like the logic that Pythons "or" is not only short-circuit but 
non-typed.

So I can say

y = override or default

and y won't necc be True or False. If override boolean evaluates to True 
(which, for most classes, means not None) than y will be equal to override. 
Otherwise it will be equal to default.

I have two questions
--> Is there a handy name for this type of conditional (something as catchy as 
"short circuit or")

and 

--> Is there a common idiom for taking advantage of the similar behavior of 
"and". The "override or default" just makes me grin every time I use it.

Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Chris Angelico
On Thu, Oct 10, 2013 at 10:48 AM, Steven D'Aprano
 wrote:
> So, for the benefit of anyone, not just Nikos, who wants to learn about
> how browsers connect to web sites and how to run a web server, does
> anyone have any recommendation for tutorials, mailing lists, web forums
> or books which are suitable? Preferably things you have used yourself,
> and can personally vouch for being useful.

Personally, what I find most useful is network-level tracing - if I
want to know what my web server's doing, I'll telnet to it (or, more
likely, use my MUD client) and look at exactly what it's sending; and
if I want to know what a browser's doing, I'll do the same (since my
MUD clients allow me to run them "backwards", listening rather than
connecting).

But that isn't for everyone, I'm aware of that.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Code golf challenge: XKCD 936 passwords

2013-10-09 Thread Roy Smith
In article ,
 Nick Cash  wrote:

> >> # Python-2, sorry
> >> import os
> >> print list(set(open('/usr/share/dict/words')))[os.getpid():][:4]
> 
> > So that steps by your pid? 
> 
> Not really. It seems to rely on list(set(...)) kinda randomizing order... 
> which is definitely not safe without hash randomization.

Exactly.  I *did* preface this with:

>>> If you're willing to accept a sub-optimal random number generator:

[Nick, again]
> But this brings up an interesting concept... if we can assume Python 2.7 with 
> the -R flag, or Python 3.3+, I think we do get true pseudo-randomization out 
> of list(set(...))... which means we can trim some!
> 
> print(list(set(open('/usr/share/dict/words')))[:4])

Excellent!  I didn't know about -R before this, so not only has this 
been fun, it's been educational too!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Denis McMahon
On Wed, 09 Oct 2013 23:48:12 +, Steven D'Aprano wrote:

> On Wed, 09 Oct 2013 18:06:05 +, Denis McMahon wrote:
> 
>> Find the relevant forums and ask in them.
> 
> In fairness to Nikos, that may not be an easy thing to do. I for one
> have *no idea* where to find an appropriate forum to learn about these
> sorts of web basics. comp.protocol.http doesn't exist :-)

If Nikos wants to write programs that communicate using internet 
protocols, Nikos really needs to learn where internet protocols are 
defined, how to read and interpret those protocol definitions, and how to 
check that the data he's sending or receiving is the data that he thinks 
he's sending or receiving.

Just as, if Nikos wants to generate web pages using HTML markup, Nikos 
needs to learn where HTML markup is defined.

There's no easy path to this knowledge. For some of us, it's been a 30 or 
more year journey so far and we're still learning (I'm into year 36, 
having started at the age of 14 and turning 51 in seven weeks).

If Nikos can't even figure out the right queries to feed into a search 
engine to get started on such matters as looking at the cookie jar in a 
browser or enabling cookie logging on a server, then he probably 
shouldn't be trying to code at this level.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python's and and Pythons or

2013-10-09 Thread Steven D'Aprano
On Wed, 09 Oct 2013 16:54:03 -0700, Peter Cacioppi wrote:

> I really like the logic that Pythons "or" is not only short-circuit but
> non-typed.
> 
> So I can say
> 
> y = override or default
> 
> and y won't necc be True or False. If override boolean evaluates to True
> (which, for most classes, means not None) than y will be equal to
> override. Otherwise it will be equal to default.
> 
> I have two questions
> --> Is there a handy name for this type of conditional (something as
> catchy as "short circuit or")

I don't know about catchy. I think of it as just a special case of duck-
typing -- all objects can be duck-typed as if they were bools.

Some terms that are often used:

"boolean context"
"truth context"
"truthiness"

The values themselves are described as "truthy" and "falsey", or "true-
like" and "false-like", or even just "true and false" (as opposed to True 
and False). Other languages (Ruby, PHP, Javascript, etc.) also have 
truthy and falsey values, but in my opinion none of them have got it 
right. Python has a unifying model of truthiness: objects which represent 
"something" ought to be truthy, those which represent "nothing" ought to 
be falsey:


# Nothing
empty strings '', u''
empty list, tuple, dict [] () {}
empty set, frozenset
None
zero 0, 0.0, 0j, Decimal("0.0"), Fraction(0)
any empty collection or mapping


# Something
all other strings
all non-empty lists, tuples, dicts
all non-empty sets, frozensets
object()
all non-zero numbers
any non-empty collection or mapping
anything else (by default)


while other languages appear to just have a grab-bag of whatever 
arbitrary values the language designer thought ought to be truthy/falsey.



> and
> 
> --> Is there a common idiom for taking advantage of the similar behavior
> of "and". The "override or default" just makes me grin every time I use
> it.


Not that I can think of.



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Ben Finney
Steven D'Aprano  writes:

> So, for the benefit of anyone, not just Nikos, who wants to learn
> about how browsers connect to web sites and how to run a web server,
> does anyone have any recommendation for tutorials, mailing lists, web
> forums or books which are suitable? Preferably things you have used
> yourself, and can personally vouch for being useful.

I learned a lot from reading the documents at the W3C, since they
defined the standards we all use http://www.w3.org/standards/>.
They are very well written and explain a lot about the architecture of
the Web.

> I'm pretty sure that *somebody* here has been in the position of
> needing to learn about running a website, and can point Nikos in the
> right direction (away from here). How did you learn?

Experiment, observation, and reference to standards.

> And if nobody is able, or willing, to answer? I've been in that
> position too, asking for help that nobody was able to give. It sucks,
> and you move on and do your best.

Right. What you don't do is disrupt a discussion forum by bombarding it
with off-topic requests; that's a quick way to get a community turn
against you.

-- 
 \ “I have yet to see any problem, however complicated, which, |
  `\  when you looked at it in the right way, did not become still |
_o__)more complicated.” —Paul Anderson |
Ben Finney

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


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Roy Smith
In article <5255eb3c$0$29984$c3e8da3$54964...@news.astraweb.com>,
 Steven D'Aprano  wrote:

> So, for the benefit of anyone, not just Nikos, who wants to learn about 
> how browsers connect to web sites and how to run a web server, does 
> anyone have any recommendation for tutorials, mailing lists, web forums 
> or books which are suitable? Preferably things you have used yourself, 
> and can personally vouch for being useful.

In the way of tools, tcpdump (or wireshark, or whatever packet sniffer 
you have handy) is invaluable for seeing what's really going on.  Also, 
curl is an amazing tool for sending arbitrary requests to a HTTP server.  
It's got a zillion options.  You'll want to learn what most of them do.  
The combination of curl and tcpdump is a pretty potent weapon for poking 
at servers.

An interesting alternative to tcpdump/curl is Google Chrome.  Open up 
the developer tools (Command-Option-I on the Mac), click the network 
tab, and type a request into the address bar.  It will capture the 
outgoing request and the response you get back, and let you dig into 
them in as much detail as you want.  Very handy, at least for GET 
requests.  I imagine any decent browser has similar functionality.


For general background, I would start with 
https://en.wikipedia.org/wiki/Http and keep following links from there 
until you have read the whole wiki or gotten tired, whichever comes 
first.

stackoverflow has become a really good forum for asking all sorts of 
programming-related questions (although, its sister site, serverfault, 
is more appropriate for networking questions).  I find the U/I 
confusing, and often find the rules (i.e. what's allowed and what's not) 
kind of silly, but a lot of really smart people hang out there.  If you 
want a question answered, go where the smart people are.

> I'm pretty sure that *somebody* here has been in the position of needing 
> to learn about running a website, and can point Nikos in the right 
> direction (away from here).

I guarantee the folks on either stackoverflow or serverfault won't put 
up with the kind of bullcrap that has been pervading this group as of 
late.

If I was using a program, foo, and had a problem, the first thing I 
would do is google for "foo mailing list" and see if I can find one.  
You don't always find one, and sometimes the list is dead, but it's a 
good place to start.

> How did you learn? 

Run.  Fall down.  Get up.  Start running again.  Repeat as needed.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python's and and Pythons or

2013-10-09 Thread Chris Angelico
On Thu, Oct 10, 2013 at 11:36 AM, Steven D'Aprano
 wrote:
> Other languages (Ruby, PHP, Javascript, etc.) also have
> truthy and falsey values, but in my opinion none of them have got it
> right. Python has a unifying model of truthiness: objects which represent
> "something" ought to be truthy, those which represent "nothing" ought to
> be falsey

Python's model makes a lot of sense. The only other system that I've
seen that makes as much sense is Pike's, which can be summarized as:

Falsey:
0 (the integer; does the job of None in many contexts)

Truthy:
Everything else.

Python lets you distinguish easily between an empty list and a list
with something in it; Pike lets you distinguish between a list and the
absence of a list.

The use of 'and' and 'or' in returning their arguments is an extremely
useful one, but I'm not sure it has a name. Pike and Lua have the same
behaviour; neither offers a good term for it. Recommendation: Invent a
term if you can't find one, and start using it. :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Steven D'Aprano
On Thu, 10 Oct 2013 00:31:06 +, Denis McMahon wrote:

> On Wed, 09 Oct 2013 23:48:12 +, Steven D'Aprano wrote:
> 
>> On Wed, 09 Oct 2013 18:06:05 +, Denis McMahon wrote:
>> 
>>> Find the relevant forums and ask in them.
>> 
>> In fairness to Nikos, that may not be an easy thing to do. I for one
>> have *no idea* where to find an appropriate forum to learn about these
>> sorts of web basics. comp.protocol.http doesn't exist :-)
> 
> If Nikos wants to write programs that communicate using internet
> protocols, Nikos really needs to learn where internet protocols are
> defined, how to read and interpret those protocol definitions, and how
> to check that the data he's sending or receiving is the data that he
> thinks he's sending or receiving.

You can't seriously mean that everyone who runs a website has to become 
skilled at reading and interpreting the RFCs for "internet protocols". 
Which protocols? All the way down to TCP/IP?


> Just as, if Nikos wants to generate web pages using HTML markup, Nikos
> needs to learn where HTML markup is defined.
> 
> There's no easy path to this knowledge. For some of us, it's been a 30
> or more year journey so far and we're still learning (I'm into year 36,
> having started at the age of 14 and turning 51 in seven weeks).
> 
> If Nikos can't even figure out the right queries to feed into a search
> engine to get started on such matters as looking at the cookie jar in a
> browser or enabling cookie logging on a server, then he probably
> shouldn't be trying to code at this level.

Nikos Nikos Nikos... and what about me? If I asked you for a few pointers 
about a good place to learn about running a web site, would you tell me 
to fuck off too? I wonder what you are doing here, if you are so 
unwilling to share your hard-earned knowledge with others as you seem in 
this post. This attitude is not the Denis McMahon I'm used to.

Honestly, your response seems to me to be just a more verbose way of 
saying "RTFM n00b", and about as helpful. Speaking for myself, I don't 
want this forum to be the sort of place where that is considered an 
appropriate response, no matter how politely the dismissal is dressed up.

I'm here to help people, and yes, that even means Nikos. To give back to 
the community that helped me (and continues to help me). In my opinion, 
if we're going to tell people to RTFM the least we can do is point them 
at the right manual, and not just dismiss them by telling them to google 
it. I don't think that's too much to ask.

(On the other hand, it's okay to say "I don't know of any good forums for 
learning this stuff. Sorry mate, I can't help.")

I have no objection to encouraging people to read the fine manual, and I 
don't intend to be Nikos' (or anyone else's) unpaid full-time help desk 
and troubleshooter. But I do think it is simply unfair to treat him more 
harshly than we would others in the same position. If *anyone else* asked 
for help on these sorts of network and browser questions, we'd give them 
more constructive pointers than just "google it".

Nikos, are you reading this? This is what happens when you behave like a 
royal pain in the arse and annoy people. They stop wanting to help you. 
Be told. Learn from this. Don't repeat this mistake in the next forum. If 
you learn nothing else, learn that lesson.


-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Chris Angelico
On Thu, Oct 10, 2013 at 12:10 PM, Steven D'Aprano
 wrote:
> On Thu, 10 Oct 2013 00:31:06 +, Denis McMahon wrote:
>
>> On Wed, 09 Oct 2013 23:48:12 +, Steven D'Aprano wrote:
>>
>>> On Wed, 09 Oct 2013 18:06:05 +, Denis McMahon wrote:
>>>
 Find the relevant forums and ask in them.
>>>
>>> In fairness to Nikos, that may not be an easy thing to do. I for one
>>> have *no idea* where to find an appropriate forum to learn about these
>>> sorts of web basics. comp.protocol.http doesn't exist :-)
>>
>> If Nikos wants to write programs that communicate using internet
>> protocols, Nikos really needs to learn where internet protocols are
>> defined, how to read and interpret those protocol definitions, and how
>> to check that the data he's sending or receiving is the data that he
>> thinks he's sending or receiving.
>
> You can't seriously mean that everyone who runs a website has to become
> skilled at reading and interpreting the RFCs for "internet protocols".
> Which protocols? All the way down to TCP/IP?

Certainly not; but if he's run into trouble with cookies, I think it's
not too much to ask him to read:
http://en.wikipedia.org/wiki/HTTP_cookie
It has a lot of text, but quite a bit of it is likely to be of use.
Then there's links down the bottom to an RFC, to Mozilla, and so on,
which could also be of use. Half an hour spent reading there will pay
good dividends.

> ... I do think it is simply unfair to treat him more
> harshly than we would others in the same position. If *anyone else* asked
> for help on these sorts of network and browser questions, we'd give them
> more constructive pointers than just "google it".
>
> Nikos, are you reading this? This is what happens when you behave like a
> royal pain in the arse and annoy people. They stop wanting to help you.
> Be told. Learn from this. Don't repeat this mistake in the next forum. If
> you learn nothing else, learn that lesson.

Actually no, it's not unfair to treat him more harshly. What's unfair
is that he hasn't been banned, killfiled by everyone, or in some other
way completely cut off from assistance. It's just as unfair as the
mercy God shows to us. We're being extremely unjust in helping him...
he hasn't earned anything, he hasn't merited help, he's not paying us.
It's a gift, it's free service, and it's a privilege. Nikos, rejoice
in the unfair and inconceivably merciful state of this forum, and as
Steven says, learn from it and don't make the same mistake elsewhere.

(I've made that mistake myself, too. I've made myself a stench in the
nostrils of certain communities. It's not something you can't come
back from; it's part of life, part of learning.)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can anyone help on conflicts between Python 2.5 and 2.7

2013-10-09 Thread Steven D'Aprano
Hi Errol,

Happy to help, but first I have a brief note about house-keeping... this 
group is both a mailing list and a newsgroup on Usenet. A text newsgroup, 
so I'm afraid that HTML posts are frowned upon, because a large number of 
people reading this will see your message something like this:

>  xmlns:o="urn:schemas-microsoft-com:office:office"
> xmlns:w="urn:schemas-microsoft-com:office:word"
> xmlns:m="http://schemas.microsoft.com/office/2004/12/omml";
> xmlns="http://www.w3.org/TR/REC-html40";> 
> 
> 
> 

Re: UnicodeEncodeError: SOLVED

2013-10-09 Thread Steven D'Aprano
On Wed, 09 Oct 2013 14:41:53 +, Walter Hurry wrote:

> Many thanks to those prepared to forgive my transgression in the
> 'Goodbye' thread. I mentioned there that I was puzzled by a
> UnicodeEncodeError, and said I would rise it as a separate thread.
> 
> However, via this link, I was able to resolve the issue myself:
> 
> http://stackoverflow.com/questions/3224268/python-unicode-encode-error

I don't know what problem you had, and what your solution was, but the 
above link doesn't solve the problem, it just throws away data until the 
problem no longer appears, and never mind if it changes the semantics of 
the XML data.

Instead of throwing away data, the right solution is likely to be, stop 
trying to deal with XML yourself, and use a proper UTF-8 compliant XML 
library.

Or if you can't do that, at least open and read the XML file using UTF-8 
in the first place. In Python 3, you can pass a codec to open. In Python 
2, you can use codecs.open instead of the built-in open.


-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can anyone help on conflicts between Python 2.5 and 2.7

2013-10-09 Thread Terry Reedy

On 10/9/2013 9:31 PM, Steven D'Aprano wrote:


I'm not a Windows guru, so I might be off-mark here (I'm sure somebody
will correct me) but as I understand it, the "default Python" under
Windows is the one that was installed most recently.


It is an option in the installer.


So, assuming you have Python2.5 installed in Python25 and Python 2.7 in
Python27, I would expect that you also have the actual executables in:

C:\Program Files\python25.exe
C:\Program Files\python27.exe


The installers actually tried to put them in C:/python25/python.exe, 
etc, but lets you choose an install directory other than /.


Beyond that, I don't know what going on either.

--
Terry Jan Reedy

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


I am never going to complain about Python again

2013-10-09 Thread Steven D'Aprano
Just came across this little Javascript gem:

",,," == Array((null,'cool',false,NaN,4));

=> evaluates as true

http://wtfjs.com/2011/02/11/all-your-commas-are-belong-to-Array

I swear, I am never going to complain about Python again.




-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am never going to complain about Python again

2013-10-09 Thread Chris Angelico
On Thu, Oct 10, 2013 at 3:36 PM, Steven D'Aprano  wrote:
> Just came across this little Javascript gem:
>
> ",,," == Array((null,'cool',false,NaN,4));
>
> => evaluates as true
>
> http://wtfjs.com/2011/02/11/all-your-commas-are-belong-to-Array
>
> I swear, I am never going to complain about Python again.

*blank look*

Wow.

Now, is there a situation in which this problem can actually crop up
in production code? And is it as serious as PHP's treatment of
hexadecimal hashes (eg that "100"== "1E2")?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can anyone help on conflicts between Python 2.5 and 2.7

2013-10-09 Thread Mark Lawrence

On 10/10/2013 04:32, Terry Reedy wrote:

On 10/9/2013 9:31 PM, Steven D'Aprano wrote:


I'm not a Windows guru, so I might be off-mark here (I'm sure somebody
will correct me) but as I understand it, the "default Python" under
Windows is the one that was installed most recently.


It is an option in the installer.


So, assuming you have Python2.5 installed in Python25 and Python 2.7 in
Python27, I would expect that you also have the actual executables in:

C:\Program Files\python25.exe
C:\Program Files\python27.exe


The installers actually tried to put them in C:/python25/python.exe,
etc, but lets you choose an install directory other than /.

Beyond that, I don't know what going on either.



Do the Windows gurus know if the launcher described here 
http://www.python.org/dev/peps/pep-0397/ would help in this instance?


--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence

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


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Mark Lawrence

On 10/10/2013 02:28, Chris Angelico wrote:


Half an hour spent reading there will pay
good dividends.



That's been sadly lacking in all of these threads.  With responses 
coming back faster than a ball on the centre court at Wimbledon, it's 
hardly surprising that progress has been conspicious by its absence.


--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence

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


Re: I am never going to complain about Python again

2013-10-09 Thread Chris Rebert
On Wed, Oct 9, 2013 at 9:36 PM, Steven D'Aprano  wrote:
> Just came across this little Javascript gem:
>
> ",,," == Array((null,'cool',false,NaN,4));
>
> => evaluates as true
>
> http://wtfjs.com/2011/02/11/all-your-commas-are-belong-to-Array
>
> I swear, I am never going to complain about Python again.

Oh, indeed, you have no idea.
Since we're talking about JavaScript suckage, I'm obliged to link to
this wonderful video on the subject:
https://www.destroyallsoftware.com/talks/wat

Cheers,
Chris R.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread rusi
On Thursday, October 10, 2013 6:40:19 AM UTC+5:30, Steven D'Aprano wrote:
> 
> I have no objection to encouraging people to read the fine manual, and I 
> don't intend to be Nikos' (or anyone else's) unpaid full-time help desk 
> and troubleshooter. But I do think it is simply unfair to treat him more 
> harshly than we would others in the same position. If *anyone else* asked 
> for help on these sorts of network and browser questions, we'd give them 
> more constructive pointers than just "google it".

https://mail.python.org/pipermail/python-list/2013-October/657221.html

https://mail.python.org/pipermail/python-list/2013-October/657034.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am never going to complain about Python again

2013-10-09 Thread Mark Lawrence

On 10/10/2013 05:36, Steven D'Aprano wrote:

Just came across this little Javascript gem:

",,," == Array((null,'cool',false,NaN,4));

=> evaluates as true

http://wtfjs.com/2011/02/11/all-your-commas-are-belong-to-Array

I swear, I am never going to complain about Python again.



Isn't that what the CS gurus call a type safe array?  What's the 
problem, *I* don't see anything wrong with it :)


--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence

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


Re: I am never going to complain about Python again

2013-10-09 Thread Cameron Simpson
On 10Oct2013 15:50, Chris Angelico  wrote:
> On Thu, Oct 10, 2013 at 3:36 PM, Steven D'Aprano  wrote:
> > Just came across this little Javascript gem:
> >
> > ",,," == Array((null,'cool',false,NaN,4));
> >
> > => evaluates as true
> >
> > http://wtfjs.com/2011/02/11/all-your-commas-are-belong-to-Array
> >
> > I swear, I am never going to complain about Python again.
> 
> *blank look*
> Wow.
> 
> Now, is there a situation in which this problem can actually crop up
> in production code?

Only, I think, the usual one: accidentally comparing two variables
which should never have been compared, either by brain fade or typo.

> And is it as serious as PHP's treatment of
> hexadecimal hashes (eg that "100"== "1E2")?

Charming. I don't even want to know :-(

A friend forwarded me a link a few months ago; PHP apparently got
some subclassing support that basicly seemed to support "mixins";
it looked ghastly.

Cheers,
-- 
Cameron Simpson 

Strong typing isn't for weak minds; the argument 'strong typing is for weak
minds' is for weak minds. - Guy Harris
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Mark Lawrence

On 10/10/2013 06:36, rusi wrote:

On Thursday, October 10, 2013 6:40:19 AM UTC+5:30, Steven D'Aprano wrote:


I have no objection to encouraging people to read the fine manual, and I
don't intend to be Nikos' (or anyone else's) unpaid full-time help desk
and troubleshooter. But I do think it is simply unfair to treat him more
harshly than we would others in the same position. If *anyone else* asked
for help on these sorts of network and browser questions, we'd give them
more constructive pointers than just "google it".


https://mail.python.org/pipermail/python-list/2013-October/657221.html

https://mail.python.org/pipermail/python-list/2013-October/657034.html



I don't understand you point, please explain.

--
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence

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


Re: Cookie gets changed when hit comes from a referrer

2013-10-09 Thread Ben Finney
rusi  writes:

> On Thursday, October 10, 2013 6:40:19 AM UTC+5:30, Steven D'Aprano wrote:
> > If *anyone else* asked for help on these sorts of network and
> > browser questions, we'd give them more constructive pointers than
> > just "google it".

Someone who has so consistently demonstrated their unwillingness to
learn, and their persistent arrogance in flooding this forum with
demands for assistance, is quite deserving of curt “go and find out for
yourself, leave this forum alone” responses.

We are a, and should remain, an open and tolerant community. But the
persistently disrespectful actions of Nikos threaten the forum's value
and usefulness for everyone else. There are limits to how much
disruption and obstinacy this community should tolerate from a given
individual.

> https://mail.python.org/pipermail/python-list/2013-October/657221.html
> https://mail.python.org/pipermail/python-list/2013-October/657034.html

Both of which got quite helpful responses: a brief, polite referral to
seek a specific discussion forum where their requests would be on topic.

-- 
 \ “If nature has made any one thing less susceptible than all |
  `\others of exclusive property, it is the action of the thinking |
_o__)  power called an idea” —Thomas Jefferson |
Ben Finney

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


Re: Python's and and Pythons or

2013-10-09 Thread Peter Cacioppi
On Wednesday, October 9, 2013 4:54:03 PM UTC-7, Peter Cacioppi wrote:
> I really like the logic that Pythons "or" is not only short-circuit but 
> non-typed.
> 
> 
> 
> So I can say
> 
> 
> 
> y = override or default
> 
> 
> 
> and y won't necc be True or False. If override boolean evaluates to True 
> (which, for most classes, means not None) than y will be equal to override. 
> Otherwise it will be equal to default.
> 
> 
> 
> I have two questions
> 
> --> Is there a handy name for this type of conditional (something as catchy 
> as "short circuit or")
> 
> 
> 
> and 
> 
> 
> 
> --> Is there a common idiom for taking advantage of the similar behavior of 
> "and". The "override or default" just makes me grin every time I use it.
> 
> 
> 
> Thanks

ok, since someone asked, I suggest we call the "return it's arguments" behavior 
"echo-argument".

That is to say, the reason we can write 

y = override or default 

is because Python implements echo-argument or. That is to say, "or" doesn't 
necc return True or False, "or" returns the first "truthy" argument it 
encounters. 

"and" behaves similarly, in that it returns the first "falsey" argument it 
encounters.

I'm trying to think of a good example usage of echo-argument and. Maybe 
something like

possible = foo and foo.allowsit()
if (possible is None) :
   print "foo not provided"
if (possible is False) :
   print "foo doesn't allow it"

A bit awkward, echo-argument or is more naturally useful to me then 
echo-argument and.



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


Re: I am never going to complain about Python again

2013-10-09 Thread Christian Gollwitzer

Am 10.10.13 06:36, schrieb Steven D'Aprano:

Just came across this little Javascript gem:

",,," == Array((null,'cool',false,NaN,4));

=> evaluates as true

http://wtfjs.com/2011/02/11/all-your-commas-are-belong-to-Array

I swear, I am never going to complain about Python again.


More of this fun for polyglott programmers:
https://www.destroyallsoftware.com/talks/wat

Christian

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


Re: Python's and and Pythons or

2013-10-09 Thread Chris Angelico
On Thu, Oct 10, 2013 at 5:12 PM, Peter Cacioppi
 wrote:
> I'm trying to think of a good example usage of echo-argument and. Maybe 
> something like
>
> possible = foo and foo.allowsit()
> if (possible is None) :
>print "foo not provided"
> if (possible is False) :
>print "foo doesn't allow it"
>
> A bit awkward, echo-argument or is more naturally useful to me then 
> echo-argument and.

first_element = some_list[0]# Oops, may crash

try:
first_element = some_list[0]
except IndexError:
firstelement = None   # A bit verbose

first_element = some_list and some_list[0]

# or if you want a zero instead of an empty list:
first_element = len(some_list) and some_list[0]


Also, consider the case where you have a function, or None:

result = func(*args,**kwargs)   # NoneType is not callable

result = func and func(*args,**kwargs)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list