Sybase module 0.40pre2 released

2011-12-09 Thread Robert Boehne

 WHAT IS IT:
The Sybase module provides a Python interface to the Sybase relational
database system.  It supports all of the Python Database API, version
2.0 with extensions.  Please downolad, test and report any problems with 
the pre-release.


** This version is a pre-release not intended for production use **

The module is available here:

http://downloads.sourceforge.net/python-sybase/python-sybase-0.40pre2.tar.gz

The module home page is here:

http://python-sybase.sourceforge.net/

MAJOR CHANGES SINCE 0.40pre1:

Better support for building against Sybase 15 on Windows, UNIX/Linux and 
64-bit platforms.


MAJOR CHANGES SINCE 0.39:

Modify the DateTimeAsPython output conversion to return None when NULL 
is output

support for Python without threads
Ignore additional non-error codes from Sybase (1918 and 11932)
Use outputmap in bulkcopy mode (thanks to patch by Cyrille Froehlich)
Raise exception when opening a cursor on a closed connection
Added unit tests
Added new exception DeadLockError when Sybase is in a deadlock situation
Add command properties CS_STICKY_BINDS and CS_HAVE_BINDS
Added support for inputmap in bulkcopy
reuse command and cursor when calling cursor.execute with same request
Use ct_setparam to define ct_cursor parameters types instead of ct_param
implicit conversion for CS_DATE_TYPE in CS_DATETIME_TYPE DataBuf
Adding ct_cmd_props wrapper
Increase DataBuf maxlength for params of a request when using 
CS_CHAR_TYPE params so that the buf can be reused


BUGS CORRECTED SINCE 0.39:

Corrected money type when using CS_MONEY4 (close bug 2615821)
Corrected thread locking in ct_cmd_props (thanks to patch by Cyrille 
Froehlich)
Corrected bug in type mapping in callproc (thanks to report by Skip 
Montanaro)

Correct passing None in a DataBuf (thanks to patch by Bram Kuijvenhoven)

The full ChangeLog is here:

https://python-sybase.svn.sourceforge.net/svnroot/python-sybase/tags/r0_40pre2/ChangeLog

--
http://mail.python.org/mailman/listinfo/python-announce-list

   Support the Python Software Foundation:
   http://www.python.org/psf/donations/


Re: subprocess.Popen under windows 7

2011-12-09 Thread Frank van den Boom


I didn't have Windows 7 right now, but that shouldn't happen with the
code you've given; when trimming code for posting, you should check that
the trimmed code still have the exact same problem.



Here is the hole code:


#!/usr/bin/env python
# little script to backup recursive a folder with 7zip


SOURCE_DIR = C:/Users/yoicks/Desktop/source
DEST_DIR = C:/Users/yoicks/Desktop/dest
BACKUP_NAME_PREFIX = BACKUP
BACKUP_NAME_DELIMITER = _
METHOD = '7zip'
PATH_TO_7ZIP = C:/Program Files/7-Zip/7z.exe
PASSWORD = 1234

import os, time, shutil, sys, tarfile, subprocess, traceback

try:
# win32
from msvcrt import getch
except ImportError:
# unix
def getch():
import sys, tty, termios
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
try:
tty.setraw(fd)
return sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old)

def press_any_key():
print Press any key to continue.
getch()

def exit_with_string(exit_string):
print exit_string
press_any_key()
sys.exit(exit_string)

def backup_directory_7zip(srcdir,archive_name):
if os.path.exists(archive_name):
exit_stop(backup path %s already exists! % arcpath)
try:
# see 7zip help
arglist = [PATH_TO_7ZIP,a, -sfx, archive_name, *, -r, 
-p,PASSWORD]
print (try running cmd:\n %s\nin directory\n %s % (' 
'.join(arglist),srcdir)) # join because i don't want [ ]
sp = subprocess.Popen(args=arglist, stdout=subprocess.PIPE, 
stderr=subprocess.PIPE, cwd=srcdir)


#output, error = subprocess.Popen(args=arglist, 
stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=srcdir).communicate()


except:
print Error while running 7zip subprocess.\n
print Traceback:\n%s%traceback.format_exc()
return False

output, error = sp.communicate()
#something 
i tried output =  sp.stdout.read()
#somtehing 
i tried error = sp.stderr.read()

if output:
print output

if error:
print error

return False
return archive_name


# build backup name
print start backup with python-script...\n

timestr = time.strftime(%Y%m%d_%H%M%S,time.localtime())

if METHOD not in [7zip]:
exit_stop(METHOD not '7zip')

if not os.path.exists(SOURCE_DIR):
exit_stop(SOURCE_DIR: %s doesn't exists % 
os.path.abspath(SOURCE_DIR))


if not os.path.exists(DEST_DIR):
exit_stop(DEST_DIR: %s doesn't exists % os.path.abspath(DEST_DIR))

else:
print(write backup from %s to %s \n using the %s method...\n %
  (os.path.abspath(SOURCE_DIR), os.path.abspath(DEST_DIR), METHOD))
if METHOD == 7zip:
try:
if not os.path.exists(PATH_TO_7ZIP):
exit_stop(Path to 7ZIP %s doesn't exist. % PATH_TO_7ZIP)
except NameError:
exit_stop(variable PATH_TO_7ZIP not defined)
return_value = 
backup_directory_7zip(srcdir=os.path.abspath(SOURCE_DIR),


archive_name=os.path.abspath(os.path.join(
   DEST_DIR, BACKUP_NAME_PREFIX + 
BACKUP_NAME_DELIMITER + timestr + .exe)))


if return_value:
print(Backup successfully written.)
else:
print(FAILURE during the backup)

press_any_key()















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


Re: Multiprocessing bug, is my editor (SciTE) impeding my progress?

2011-12-09 Thread John Ladasky
Thanks once again to everyone for their recommendations, here's a
follow-up.  In summary, I'm still baffled.

I tried ipython, as Marco Nawijn suggested.  If there is some special
setting which returns control to the interpreter when a subprocess
crashes, I haven't found it yet.  Yes, I'm RTFM.  As with SciTE,
everything just hangs.  So I went back to SciTE for now.

And I'm doing what Terry Reedy suggested -- I am editing
multiprocess.Pool in place.  I made a backup, of course.  I am using
sudo to run SciTE so that I can edit the system files, and not have to
worry about chasing path and import statement problems.

What I have found, so far, is no evidence that a string is needed in
any of the code.  What's the task variable?  It's a deeply-nested
tuple, containing no strings, not even in the WORKING code.  This
makes me wonder whether that traceback is truly complete.

I wrote a routine to display the contents of task, immediately before
the offending put().  Here's a breakdown.


In the WORKING version:

task:  type 'tuple'
   type 'int' 0
   type 'int' 0
   type 'function'function mapstar at 0xa7ec5a4
   type 'tuple'   (see below)
   type 'dict'{}

task[3]:  type 'tuple'
   type 'tuple'   (see below)

task[3][0]:  type 'tuple'
   type 'function'function mean_square_error at 0xa7454fc
   type 'tuple'   (see below)

task[3][0][1]:  type 'tuple'
   class 'neural.SplitData'   (see below)

task[3][0][1][0]:  class 'neural.SplitData'
   net  class 'neural.CascadeArray'   shape=(2, 3)
   inp  type 'numpy.ndarray'  shape=(307, 2)
   tgt  type 'numpy.ndarray'  shape=(307, 2)


By watching this run, I've learned that task[0] and task[1] are
counters for groups of subprocesses and individual subprocesses,
respectively.  Suppose we have four subprocesses.  When everything is
working, task[:2] = [0,0] for the first call, then [0,1], [0,2],
[0,3]; then, [1,0], [1,1], [1,2], etc.

task[2] points to multiprocessing.Pool.mapstar, a one-line function
that I never modify.  task[4] is an empty dictionary.  So it looks
like everything that I provide appears in task[3].

task[3] is just a tuple inside a tuple (which is weird).  task[3][0]
contains the function to be called (in this case, my function,
mean_square_error), and then a tuple containing all of the arguments
to be passed to that function.  The docs say that the function in
question must be defined at the top level of the code so that it's
importable (it is), and that all the arguments to be sent to that
function will be wrapped up in a single tuple -- that is presumably
task[3][0][1].

But that presumption is wrong.  I wrote a function which creates a
collections.namedtuple object of the type SplitData, which contains
the function's arguments.  It's not task[3][0][1] itself, but the
tuple INSIDE it, namely task[3][0][1][0].  More weirdness.  You don't
need to worry about task[3][0][1][0], other than to note that these
are my neural network objects, they are intact, they are the classes I
expect, and they are named as I expect -- and that there are NO STRING
objects.


Now, are there any differences between the working version of my code
and the buggy version?  Other than a few trivial name changes that I
made deliberately, the structure of task looks the SAME...


task:  type 'tuple'
   type 'int' 0
   type 'int' 0
   type 'function'function mapstar at 0x88e0a04
   type 'tuple'   (see below)
   type 'dict'{}

task[3]:  type 'tuple'
   type 'tuple'   (see below)

task[3][0]:  type 'tuple'
   type 'function'function error at 0x88a5fb4
   type 'tuple'   (see below)

task[3][0][1]:  type 'tuple'
   class '__main__.SplitData' (see below)

task[3][0][1][0]:  class '__main__.SplitData'
   func class 'cascade.Cascade'   shape=(2, 3)
   inp  type 'numpy.ndarray'  shape=(307, 2)
   tgt  type 'numpy.ndarray'  shape=(307, 2)

Again, all the action is in task[3].  I was worried about the empty
dictionary in task[4] at first, but I've seen this {} in the working
program, too.  I'm not sure what it does.

For completeness, here's mean_square_error() from the working program:

def mean_square_error(b):
out = array([b.net(i) for i in b.inp])
return sum((out-b.tgt)**2)

And, here's error() from the buggy program.

def error(b):
out = array([b.func(i) for i in b.inp])
return sum((out-b.tgt)**2)

I renamed mean_square_error(), because I realized that the mean-square
error is the only kind of error I'll ever be computing.  I also
renamed net to func, in SplitData, reflecting the more general
nature of the Cascade class I'm developing.  So I mirror that name
change here.  Other than that, I trust you can see that error() and
mean_square_error() are identical.

I can call mean_square_error directly with a SplitData tuple and it
works.  I can call error directly with a SplitData tuple in the 

Re: subprocess.Popen under windows 7

2011-12-09 Thread Ulrich Eckhardt

Am 08.12.2011 23:41, schrieb Frank van den Boom:

arglist = [PATH_TO_7ZIP,a, -sfx, archive_name, *, -r,
-p,PASSWORD]


The * is resolved by the shell, this is not a wildcard that gets 
passed to the program. At least not normally, your case might be different.



if output:
print output

print (Eyerthing is good)


Is that Python 2 or 3?

That said, if you reduced it to something that doesn't e.g. require 7zip 
I'd happily run it on an XP system with Python 2.7 to tell you if it 
works there or not. Doing so would also rule out any influence by 7zip, 
just in case.


Uli
--
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess.Popen under windows 7

2011-12-09 Thread Tim Golden

On 09/12/2011 08:32, Ulrich Eckhardt wrote:

Am 08.12.2011 23:41, schrieb Frank van den Boom:

arglist = [PATH_TO_7ZIP,a, -sfx, archive_name, *, -r,
-p,PASSWORD]


The * is resolved by the shell, this is not a wildcard that gets
passed to the program. At least not normally, your case might be different.


... not normally == ... not on Unix. On Windows, the shell
doesn't do any wildcard expansion. The OP is asking about behaviour
on Windows 7.

TJG
--
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess.Popen under windows 7

2011-12-09 Thread Frank van den Boom

Thank you very much.

Now I have written a little c++ programm which produces some ouput.

And now it works fine.
There is something wrong with 7zip.exe and the arglist with *.
Tonight I will go on and hunt the error.


It should be Python 2.7


#!/usr/bin/env python

PATH_TO_EXE  = C:/Users/yoicks/Desktop/ausgabe.exe

import os, shutil, sys, subprocess, traceback

try:
# win32
from msvcrt import getch
except ImportError:
# unix
def getch():
import sys, tty, termios
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
try:
tty.setraw(fd)
return sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old)

def press_any_key():
print Press any key to continue.
getch()

def exit_with_string(exit_string):
print exit_string
press_any_key()
sys.exit(exit_string)

def start_exe (PATH_TO_EXE):
try:
arglist = [PATH_TO_EXE]
print (try running cmd:\n %s\n % (' '.join(arglist)))
sp = subprocess.Popen(args=arglist, stdout=subprocess.PIPE,
  stderr=subprocess.PIPE, shell=True)

except:
print Error while running subprocess.\n
print Traceback:\n%s%traceback.format_exc()
return False

output, error = sp.communicate()

if output:
print output

if error:
print error
return False

return True

return_value = start_exe(PATH_TO_EXE)

if return_value:
print(Backup successfully written.)
else:
print(FAILURE during the backup)

press_any_key()


 * Englisch - erkannt
 * Englisch
 * Deutsch

 * Englisch
 * Deutsch

 javascript:void(0);
--
http://mail.python.org/mailman/listinfo/python-list


Re: Misleading error message of the day

2011-12-09 Thread Jean-Michel Pichavant

Ethan Furman wrote:

Jean-Michel Pichavant wrote:
You have to opportunity to not use unpacking anymore :o) There is a 
recent thread were the dark side of unpacking was exposed. Unpacking 
is a cool feautre for very small applications but should be avoided 
whenever possible otherwise.


Which thread was that?


~Ethan~

A tuple in order to pass returned values ? was the thread.

JM

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


Re: I love the decorator in Python!!!

2011-12-09 Thread Robert Kern

On 12/9/11 5:02 AM, alex23 wrote:

On Dec 9, 2:38 am, Chris Angelicoros...@gmail.com  wrote:

One piece of sophistication that I would rather like to see, but don't
know how to do. Instead of *args,**kwargs, is it possible to somehow
copy in the function's actual signature? I was testing this out in
IDLE, and the fly help for the function no longer gave useful info
about its argument list.


The 3rd party 'decorator' module takes care of issues like docstrings
  function signatures. I'd really like to see some of that
functionality in the stdlib though.


Much of it is:

  http://docs.python.org/library/functools#functools.update_wrapper

--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: I love the decorator in Python!!!

2011-12-09 Thread Thomas Rachel

Am 08.12.2011 12:43 schrieb Chris Angelico:

On Thu, Dec 8, 2011 at 10:22 PM, K.-Michael Ayekmichael@gmail.com  wrote:

I am still perplexed about decorators though, am happily using Python for
many years without them, but maybe i am missing something?
For example in the above case, if I want the names attached to each other
with a comma, why wouldn't I just create a function doing exactly this? Why
would I first write a single name generator and then decorate it so that I
never can get single names anymore (this is the case, isn't it? Once
decorated, I can not get the original behaviour of the function anymore.


The example given is a toy. It's hardly useful.


Right. It was supposed to be an example.

In my case, I work with a script used to build a XML file. I change this 
script from time to time in order to match the requirements.
Here I find it useful just to add some more yield statements for adding 
entries.


But now that I think again about it, it's more an example for 
generators, not so much for decorators - which I like as well.


*

But some useful examples for decorators include

1. Threadifying a function, i.e. turning it into a Thread object, or 
into a callable which in turn starts a thread according to the given 
parameters.


2. Automatically calling a function if the given module is executed as a 
script, a kind of replacement for the if __name__ == '__main__': stuff.


3. Meta decorators:

I find it annoying to have to wrap the function given to the decorator 
into another one, modifying its properties and returning that in turn.


def wrapfunction(decorated):
Wrap a function taking (f, *a, **k) and replace it with a
function taking (f) and returning a function taking (*a, **k) which
calls our decorated function.

from functools import wraps
@wraps(decorated)
def wrapped_outer(f):
@wraps(f)
def wrapped_inner(*a, **k):
return decorated(f, *a, **k)
return wrapped_inner
return wrapped_outer

makes it much easier to create decorators which just wrap a function 
into another, extending its funtionality:


@wrapfunction
def return_list(f, *a, **k)
return list(f(*a, **k))

is much easier and IMHO much better to read than

def return_list(f):
Wrap a function taking (f, *a, **k) and replace it with a
function taking (f) and returning a function taking (*a, **k) which
calls our decorated function.

from functools import wraps
@wraps(f)
def wrapped(*a, **k):
return list(f, *a, **k)
return wrapped

- especially if used multiple times.

3a. This is a modified case of my first example: If you want a function 
to assemble and return a list instead of a generator object, but prefer 
yield over ret=[]; ret.append();..., you can do that with this 
@return_list.


4. So-called indirect decorators:

@spam(eggs)
def foo(bar):
pass

are as well quite tricky to build when taking

def indirdeco(ind):
from functools import update_wrapper, wraps
upd=wraps(ind)
# outer wrapper: replaces a call with *a, **k with an updated
# lambda, getting the function to be wrapped and applying it and
# *a, **k to ind.
outerwrapper=lambda *a, **k: upd(lambda f: ind(f, *a, **k))
# We update this as well:
return upd(outerwrapper)
# We don't update f nor the result of ind() - it is the callee's
# business.

It is kind of reverse to 3.

@indirdeco
def addingdeco(f, offset):
return lambda *a, **k: f(*a, **k) + offset
# Here should maybe be wrapped - it is just supposed to be an
# example.

5. Creating a __all__ for a module. Instead of maintaining it somewhere 
centrally, you can take a


class AllList(list):
list which can be called in order to be used as a __all__-adding
decorator
def __call__(self, obj):
for decorators
self.append(obj.__name__)
return obj

, do a __all__ = AllList()

and subsequently decorate each function with

@__all__

6. Re-use a generator:

A generator object is creted upon calling the generator function with 
parameters and can be used only once. A object wrapping this generator 
might be useful.


# Turn a generator into a iterable object calling the generator.
class GeneratorIterable(object):
Take a parameterless generator function and call it on every
iteration.
def __init__(self, gen):
# Set object attribute.
self.gen = gen
def __iter__(self):
# Class attribute calls object attribute in order to keep
# namespace variety small.
return self.gen()


@GeneratorIterable
def mygen():
yield 1
yield 2

list(mygen) - [1, 2]
list(mygen) - [1, 2] # again, without the ()

Might be useful if the object is to be transferred to somewhere else.

*

Some of these decorators are more useful, some less if seen standalone, 
but very handy if creating other decorators.


HTH nevertheless,


Thomas
--

Re: Dynamic variable creation from string

2011-12-09 Thread Massi
Thank you all for your replies, first of all my Sum function was an
example simplifying what I have to do in my real funciton. In general
the D dictionary is complex, with a lot of keys, so I was searching
for a quick method to access all the variables in it without doing the
explicit creation:

a, b, c = D['a'], D['b'], D['c']

and without using directly the D dictionary (boring...).
When I talked about nested function I meant both cases Chris, but this
is not a really tighten bound.
I tried to follow the hints of Chris together with some help by google
and used the following code:

for k in D : exec %s = D[k] %k

That seems to do the trick, but someone speaks about dirty code, can
anyone point me out which problems this can generate?
Again, thank you for your help!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic variable creation from string

2011-12-09 Thread Peter Otten
Massi wrote:

 for k in D : exec %s = D[k] %k
 
 That seems to do the trick, but someone speaks about dirty code, can
 anyone point me out which problems this can generate?

exec can run arbitrary code, so everybody reading the above has to go back 
to the definition of D to verify that it can only contain safe keys. 
Filling D with user-input is right out because a malicious user could do 
anything he likes. Here's a harmless demo that creates a file:

 d = {x = 42\nwith open('tmp.txt', 'w') as f:\n f.write('whatever')\nx: 
123}
 for k in d: exec %s = d[k] % k
...
 x
123
 open(tmp.txt).read()
'whatever'


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


Re: order independent hash?

2011-12-09 Thread Steven D'Aprano
On Thu, 08 Dec 2011 10:30:01 +0100, Hrvoje Niksic wrote:

 In a language like Python, the difference between O(1) and O(log n) is
 not the primary reason why programmers use dict; they use it because
 it's built-in, efficient compared to alternatives, and convenient to
 use.  If Python dict had been originally implemented as a tree, I'm sure
 it would be just as popular.

Except for people who needed dicts with tens of millions of items.

Remember also that dicts are used for looking up names in Python. Nearly 
all method calls, attribute accesses, global name lookups, function 
calls, etc. go through at least one and potentially multiple dict 
lookups. The simple statement:

n = len(x.y) + len(z)

likely requires nine dict lookups, and potentially more. In even a small 
application, there could be tens of millions of dict lookups; changing 
each of them from O(1) to O(log N) could result in a measurable slowdown 
to Python code in real applications. That is why dicts are highly 
optimized for speed.

As fast as dicts are, sometimes they aren't fast enough. One common micro-
optimization for tight loops and time-critical code is to create local 
variables from globals or builtins, because local variable access 
bypasses dict lookup. So people would notice if dicts were slower.


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


Re: Dynamic variable creation from string

2011-12-09 Thread Steven D'Aprano
On Fri, 09 Dec 2011 01:55:28 -0800, Massi wrote:

 for k in D : exec %s = D[k] %k
 
 That seems to do the trick, but someone speaks about dirty code, can
 anyone point me out which problems this can generate? Again, thank you
 for your help!

Just the second-most common source of viruses, malware and security 
vulnerabilities (behind buffer overflows): code injection attacks.

Code injection attacks make up at least three of the top 25 security 
vulnerabilities on the CWE/SANS list:

http://cwe.mitre.org/top25/index.html

including the top 2 most dangerous threats (beating even our old friend, 
the buffer overflow): SQL injection and OS command injection. Your use of 
exec is vulnerable to attack if a hostile user can fool you into using a 
dict like this one:

D = {'a': '42', 
 'import os;'\
 ' os.system(echo ha ha i ownz ur system rm-rf/ ); b': '23',
}
for k in D : exec %s = D[k] % k


You might think you're safe from such attacks, but (1) it is MUCH harder 
to protect against them than you might think; and (2) code has a habit of 
being re-used. Today your application might only be used by you; next 
week your code might find itself embedded in a web-application where 
hostile script kiddies can destroy your server with a single upload.

My advice is:

(1) If you need to ask why exec is dangerous, you shouldn't touch it.
(2) If you're sure you can protect against code injection, you can't.
(3) If you think you need exec, you probably don't.
(4) If you think you can make exec safe with a prohibited list of 
dangerous strings, you probably can't.


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


Re: Dynamic variable creation from string

2011-12-09 Thread Steven D'Aprano
On Fri, 09 Dec 2011 11:59:16 +, Steven D'Aprano wrote:

 Just the second-most common source of viruses, malware and security
 vulnerabilities (behind buffer overflows): code injection attacks.

Oops, I forgot to go back and revise this sentence. Code injection 
attacks are now the most common, not second-most common, source of 
security vulnerabilities.

http://cwe.mitre.org/top25/index.html



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


Re: Dynamic variable creation from string

2011-12-09 Thread Chris Angelico
On Fri, Dec 9, 2011 at 10:59 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 (4) If you think you can make exec safe with a prohibited list of
 dangerous strings, you probably can't.

If you think that it's even _possible_ to make exec safe with a
blacklist, I have a nice padded cell for you over here.

Security is NEVER achieved with blacklists, ONLY whitelists.

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


Re: I love the decorator in Python!!!

2011-12-09 Thread Francesco Bochicchio
On 8 Dic, 12:22, K.-Michael Aye kmichael@gmail.com wrote:
 On 2011-12-08 08:59:26 +, Thomas Rachel said:



  Am 08.12.2011 08:18 schrieb 8 Dihedral:
  I use the @ decorator to behave exactly like a c macro that
  does have fewer side effects.

  I am wondering is there other interesting methods to do the
  jobs in Python?

  In combination with a generator, you can do many funny things.

  For example, you can build up a string:

  def mkstring(f):
       Turns a string generator into a string,
       joining with , .
       
       return , .join(f())

  def create_answer():
       @mkstring
       def people():
           yield Anna
           yield John
           yield Theo

       return The following people were here:  + people

  Many other things are thinkable...

  Thomas

 I am still perplexed about decorators though, am happily using Python
 for many years without them, but maybe i am missing something?
 For example in the above case, if I want the names attached to each
 other with a comma, why wouldn't I just create a function doing exactly
 this? Why would I first write a single name generator and then decorate
 it so that I never can get single names anymore (this is the case,
 isn't it? Once decorated, I can not get the original behaviour of the
 function anymore.
 So, above, why not
 def mkstring(mylist):
 with the same function declaration and then just call it with a list of
 names that I generate elsewhere in my program?
 I just can't identify the use-case for decorators, but as I said, maybe
 I am missing something.

 Michael

I had/have similar feelings. For instance,  this is something that I
tought useful, but then I never used in real code.
The idea was to find a way to automate this code pattern, which I do a
lot:

class SomeClass:
   def __init__(self, some, attribute, here ):
   self.some, self.attribute, self.here = some, attribute, here


In other words, I often define classes in which the constructor list
of arguments corresponds one-to-one to class attributes.
So I thought of this (it uses class decorators so it only works with
Python 3.x ) :


class FieldsDecorator:
def __init__(self, *names):
self.names = names

def __call__(self, cls):
def constructor(instance, **kwds):
for n,v in kwds.items():
if n in self.names:
setattr(instance, n, v)
else: raise TypeError(%s is not a valid field % s )
setattr(cls, '__init__', constructor )
return cls


@FieldsDecorator(uno, due)
class Prova:
pass

p = Prova(uno=12, due=9)
print (p.uno, p.due )


It works and it is nice, but I don't find it compelling enough to use
it. I keep assigning directly the attributes, which is more readable.

Decorators are really useful when you have lot of repetitive
boilercode that you _want_ to hide,  since it has little to do with
the problem logic and more to to with the technicalities of the
programming language or of some framework that you are using. It is
called separating of concerns I think, and is one of the principles
of Aspect-Oriented Programming (and  with decorators you can do some
nice AOP exercises ... ).

Ciao
---
FB

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


Re: tracking variable value changes

2011-12-09 Thread Andrea Crotti

On 12/08/2011 08:17 PM, Catherine Moroney wrote:

Hello,

Is there a way to create a C-style pointer in (pure) Python so the 
following code will reflect the changes to the variable a in the

dictionary x?

For example:

 a = 1.0
 b = 2.0
 x = {a:a, b:b}
 x
{'a': 1.0, 'b': 2.0}
 a = 100.0
 x
{'a': 1.0, 'b': 2.0}   ## at this point, I would like the value
   ## associated with the a key to be 100.0
   ## rather than 1.0

If I make a and b numpy arrays, then changes that I make to the 
values of a and b show up in the dictionary x.


My understanding is that when I redefine the value of a, that Python
is creating a brand-new float with the value of 100.0, whereas when I 
use numpy arrays I am merely assigning a new value to the same object.


Is there some way to rewrite the code above so the change of a from
1.0 to 100.0 is reflected in the dictionary.  I would like to use
simple datatypes such as floats, rather than numpy arrays or classes.
I tried using weakref's, but got the error that a weak reference cannot
be created to a float.

Catherine


Not sure if it's exactly pure python but Traits can actually do this
https://github.com/enthought/traits
--
http://mail.python.org/mailman/listinfo/python-list


Re: Misleading error message of the day

2011-12-09 Thread Roy Smith
In article mailman.3466.1323425036.27778.python-l...@python.org,
 Jean-Michel Pichavant jeanmic...@sequans.com wrote:

 Ethan Furman wrote:
  Jean-Michel Pichavant wrote:
  You have to opportunity to not use unpacking anymore :o) There is a 
  recent thread were the dark side of unpacking was exposed. Unpacking 
  is a cool feautre for very small applications but should be avoided 
  whenever possible otherwise.
 
  Which thread was that?
 
 
  ~Ethan~
 A tuple in order to pass returned values ? was the thread.
 
 JM

To save everybody the effort of finding it, I think he's talking about 
https://groups.google.com/d/topic/comp.lang.python/2vcwYfIQSOM/discussion
-- 
http://mail.python.org/mailman/listinfo/python-list


Contacts/Addressbook application - any good Python ones out there?

2011-12-09 Thread tinnews
I'm after an application for managing Contacts (i.e. an Address Book)
and as I suspect I will want to 'tune' it a bit Python would be my
preferred language.

So far I have found :-

pycocuma - reasonable but rather old and a bit clunky (uses TCL/Tk)
pyaddressbook - newer but very minimal

Does anyone have any other suggestions?  I'd prefer an application
which uses vCards as its native data storage format but that's not
vital and I'd also like to have a GUI but again that's not vital, a
well designed curses/terminal application would be OK too.

-- 
Chris Green
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Contacts/Addressbook application - any good Python ones out there?

2011-12-09 Thread Alec Taylor
Wammu?

On Sat, Dec 10, 2011 at 1:41 AM,  tinn...@isbd.co.uk wrote:
 I'm after an application for managing Contacts (i.e. an Address Book)
 and as I suspect I will want to 'tune' it a bit Python would be my
 preferred language.

 So far I have found :-

    pycocuma - reasonable but rather old and a bit clunky (uses TCL/Tk)
    pyaddressbook - newer but very minimal

 Does anyone have any other suggestions?  I'd prefer an application
 which uses vCards as its native data storage format but that's not
 vital and I'd also like to have a GUI but again that's not vital, a
 well designed curses/terminal application would be OK too.

 --
 Chris Green
 --
 http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] Book authoring

2011-12-09 Thread Grant Edwards
On 2011-12-09, Miki Tebeka miki.teb...@gmail.com wrote:
 Greetings,

 Any recommendations for a book authoring system that supports the following:
 1. Code examples (with syntax highlighting and line numbers)
 2. Output HTML, PDF, ePub ...
 3. Automatic TOC and index
 4. Search (in HTML) - this is a nice to have

http://en.wikipedia.org/wiki/Lightweight_markup_language

I've used asciidoc extensively and reStructuredText a little. Asciidoc
will produce all the formats you mentioned (though I've only refularly
used HTML and PDF). reStructuredText is what's used for Python docs
isn't it?

 Can I somehow use Sphinx?

Don't know what Sphinx is.

And there's always the old stand-by LaTeX, but it's a bit more
heavyweight with more of a learning curve.  OTOH, it does produce
text-book quality output.

-- 
Grant Edwards   grant.b.edwardsYow! BELA LUGOSI is my
  at   co-pilot ...
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] Book authoring

2011-12-09 Thread Nick Dokos
Grant Edwards invalid@invalid.invalid wrote:

 On 2011-12-09, Miki Tebeka miki.teb...@gmail.com wrote:
  Greetings,
 
  Any recommendations for a book authoring system that supports the following:
  1. Code examples (with syntax highlighting and line numbers)
  2. Output HTML, PDF, ePub ...
  3. Automatic TOC and index
  4. Search (in HTML) - this is a nice to have
 
 http://en.wikipedia.org/wiki/Lightweight_markup_language
 
 I've used asciidoc extensively and reStructuredText a little. Asciidoc
 will produce all the formats you mentioned (though I've only refularly
 used HTML and PDF). reStructuredText is what's used for Python docs
 isn't it?
 
  Can I somehow use Sphinx?
 
 Don't know what Sphinx is.
 

I think Sphinx is used for the python docs: it sits atop rST and does
all the transformations/processing to produce the desired output
( http://sphinx.pocoo.org )

 And there's always the old stand-by LaTeX, but it's a bit more
 heavyweight with more of a learning curve.  OTOH, it does produce
 text-book quality output.
 

There is also orgmode, which has been used for a few books
(http://orgmode.org ). I know it does HTML and PDF (the latter through
latex), but I'm not sure about ePub: ISTR somebody actually did ePub for
his book but I don't remember details. The indexing is manual:
add #+index: foo entries as required.  But in general, imo, automatic
indexing for books sucks raw eggs (it works much better for highly
regular source code like the python source base).

Nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to build 64-bit Python on Solaris with GCC?

2011-12-09 Thread Skip Montanaro
Karim kliateni at gmail.com writes:

 ./configure
 make
 make install

Thanks.  I have several different versions in my local sandbox.  None
are 64-bit ELFs.  Just to make sure I hadn't missed some new development
in this area, I cloned the hg repository and build the trunk version
from scratch.  I get a 32-bit executable on Solaris:

   % file ./python
   ./python: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
   dynamically linked (uses shared libs), not stripped

Skip


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


Re: [OT] Book authoring

2011-12-09 Thread Andrea Crotti

On 12/09/2011 03:25 AM, Miki Tebeka wrote:

Greetings,

Any recommendations for a book authoring system that supports the following:
1. Code examples (with syntax highlighting and line numbers)
2. Output HTML, PDF, ePub ...
3. Automatic TOC and index
4. Search (in HTML) - this is a nice to have

Can I somehow use Sphinx?

Thanks,
--
Miki


I think it depends on what you want exactly.
If it's a nice book with a scientific look and many complicated 
tables/figures
than I think that LaTeX is the way to go (maybe even org-mode but it's 
mainly

for emacs-fans).

The problem with LaTeX is that it's quite tricky to export to other 
formats, harder

to learn and not as flexible as a python-based solution as Sphinx.
I would suggest to try Sphinx and see if you're missing something..
--
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] Book authoring

2011-12-09 Thread Nick Dokos
Nick Dokos nicholas.do...@hp.com wrote:

 There is also orgmode, which has been used for a few books
 (http://orgmode.org ). I know it does HTML and PDF (the latter through
 latex), but I'm not sure about ePub: ISTR somebody actually did ePub for
 his book but I don't remember details. 

Avdi Grimm produced his book Exceptional Ruby
(http://exceptionalruby.com ) this way, including ePub formats (I hope
mentioning Ruby in this context is not a punishable offense...)


Apparently, there is calibre (http://calibre-ebook.com/ ) that will take
you from HTML to ePub. See this orgmode list article e.g.

 http://thread.gmane.org/gmane.emacs.orgmode/41826

Nick

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


Re: How to build 64-bit Python on Solaris with GCC?

2011-12-09 Thread Stefan Krah
Skip Montanaro s...@pobox.com wrote:
 Thanks.  I have several different versions in my local sandbox.  None
 are 64-bit ELFs.  Just to make sure I hadn't missed some new development
 in this area, I cloned the hg repository and build the trunk version
 from scratch.  I get a 32-bit executable on Solaris:
 
% file ./python
./python: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
dynamically linked (uses shared libs), not stripped

./configure CFLAGS=-m64 LDFLAGS=-m64 should work with a reasonably
recent revision.


Stefan Krah


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


Re: Contacts/Addressbook application - any good Python ones out there?

2011-12-09 Thread tinnews
Alec Taylor alec.tayl...@gmail.com wrote:
 Wammu?
 
I hadn't really considered gammu/wammu as I saw it as a mobile phone
synchrinsation tool, but I've looked a bit harder and it might very
well be what I need - thank you!

 On Sat, Dec 10, 2011 at 1:41 AM,  tinn...@isbd.co.uk wrote:
  I'm after an application for managing Contacts (i.e. an Address Book)
  and as I suspect I will want to 'tune' it a bit Python would be my
  preferred language.
 
  So far I have found :-
 
     pycocuma - reasonable but rather old and a bit clunky (uses TCL/Tk)
     pyaddressbook - newer but very minimal
 
  Does anyone have any other suggestions?  I'd prefer an application
  which uses vCards as its native data storage format but that's not
  vital and I'd also like to have a GUI but again that's not vital, a
  well designed curses/terminal application would be OK too.
 
  --
  Chris Green
  --
  http://mail.python.org/mailman/listinfo/python-list

-- 
Chris Green
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: order independent hash?

2011-12-09 Thread Hrvoje Niksic
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:

 Except for people who needed dicts with tens of millions of items.

Huge tree-based dicts would be somewhat slower than today's hash-based
dicts, but they would be far from unusable.  Trees are often used to
organize large datasets for quick access.

The case of dicts which require frequent access, such as those used to
implement namespaces, is different, and more interesting.  Those dicts
are typically quite small, and for them the difference between O(log n)
and O(1) is negligible in both theory (since n is small, i.e. bounded)
and practice.  In fact, depending on the details of the implementation,
the lookup in a small tree could even be marginally faster.
-- 
http://mail.python.org/mailman/listinfo/python-list


Execute python within Oracle

2011-12-09 Thread André Lopes
Hi all,



   I wrote a simple Java program to be called within an Oracle database.
The goal is to execute a Python program within the DB itself, by the means
of a Java program. The problem is that when I execute the procedure inside
the DB, nothing happens…



   If I create the same Java class outside the DB and execute it, the
python program works perfectly, only inside the DB nothing happens. The
program is the following.



CREATE OR REPLACE AND COMPILE java source named OSCommand as

import java.io.*;

public class OSCommand{

public static void Run(){

try

{

Runtime r = Runtime.getRuntime();

Process p = r.exec(cmd /c C:\\Python32\\python.exe
C:\\Ficheiros\\SAP\\Novos\\xls2csv.py
C:\\Ficheiros\\SAP\\Novos\\20111020_ListagemSAP.xlsx);



}

catch (Exception e)

{

e.printStackTrace();

}

}

}

/



   Can anyone help?



Thanks,

André
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: order independent hash?

2011-12-09 Thread Chris Angelico
On Sat, Dec 10, 2011 at 3:51 AM, Hrvoje Niksic hnik...@xemacs.org wrote:
 The case of dicts which require frequent access, such as those used to
 implement namespaces, is different, and more interesting.  Those dicts
 are typically quite small, and for them the difference between O(log n)
 and O(1) is negligible in both theory (since n is small, i.e. bounded)
 and practice.  In fact, depending on the details of the implementation,
 the lookup in a small tree could even be marginally faster.

This is something where, I am sure, far greater minds than mine
delve... but, would a splay tree be effective for name lookups? In
most cases, you'll have a huge puddle of names of which you use the
tiniest fraction; and a splay tree would, in effect, automatically
optimize itself to handle tight loops.

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


Re: Execute python within Oracle

2011-12-09 Thread Ian Kelly
2011/12/9 André Lopes andrecras...@gmail.com:
 Hi all,



    I wrote a simple Java program to be called within an Oracle database. The
 goal is to execute a Python program within the DB itself, by the means of a
 Java program. The problem is that when I execute the procedure inside the
 DB, nothing happens…



    If I create the same Java class outside the DB and execute it, the python
 program works perfectly, only inside the DB nothing happens. The program is
 the following.

Have you granted the necessary permissions to execute programs from Java?

http://asktom.oracle.com/pls/asktom/f?p=100:11:0P11_QUESTION_ID:952229840241

Note that article is for Oracle 8, I'm not sure whether the
permissions might have changed since then.

Cheers,
Ian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Misleading error message of the day

2011-12-09 Thread Ethan Furman

Jean-Michel Pichavant wrote:

Ethan Furman wrote:

Jean-Michel Pichavant wrote:
You have to opportunity to not use unpacking anymore :o) There is a 
recent thread were the dark side of unpacking was exposed. Unpacking 
is a cool feautre for very small applications but should be avoided 
whenever possible otherwise.


Which thread was that?


~Ethan~

A tuple in order to pass returned values ? was the thread.


Thanks.

~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list


Re: I love the decorator in Python!!!

2011-12-09 Thread 88888 Dihedral
On Thursday, December 8, 2011 7:43:12 PM UTC+8, Chris Angelico wrote:
 On Thu, Dec 8, 2011 at 10:22 PM, K.-Michael Aye kmicha...@gmail.com wrote:
  I am still perplexed about decorators though, am happily using Python for
  many years without them, but maybe i am missing something?
  For example in the above case, if I want the names attached to each other
  with a comma, why wouldn't I just create a function doing exactly this? Why
  would I first write a single name generator and then decorate it so that I
  never can get single names anymore (this is the case, isn't it? Once
  decorated, I can not get the original behaviour of the function anymore.
 
 The example given is a toy. It's hardly useful. However, there are a
 number of handy uses for decorators; mostly, they consist of giving a
 single simple keyword to a complicated set of logic. One example is
 the @classmethod and @staticmethod decorators - the code to implement
 them could be uglier than nested inline assembly, but you don't have
 to care, because you just type @staticmethod in front of your def
 statement and it does its magic.
 
 Here's a handy trick that I'm sure someone has done in a more sophisticated 
 way:
 
 def trace(func):
 if debugmode:
 return lambda *a,**ka:
 (print(+func.__name__),func(*a,**ka),print(+func.__name__))[1]
 return func
 
 Then you put @trace in front of all your functions, and if debugmode
 is False, nothing will be done - but set it to true, and you get
 console output at the entry and exit of each function.
 
  @trace
 def test(x):
   print(Test! +x)
   return 5
 
  test(asdf)
 test
 Test! asdf
 test
 5
 
 Again, it's helpful because it condenses all the logic (including the
 'debugmode' flag) down to a single high level directive: Trace this
 function.
 
 ChrisA

I did use decorators to turn functions into iterables to be traced. 




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


Buffering of sys.stdout and sys.stderr in python3 (and documentation)

2011-12-09 Thread Geoff Bache
Hi all,

Short version:

I'm a bit confused in general as to the changes between python2 and
python3 regarding how standard output and standard error do buffering.
A few things seem to have changed and I've failed to find any
documentation of how and why. Also, the meaning of python -u seems
to have changed and the docs don't seem to reflect the new behaviour
(and I can't find any docs about the change either)...

Long version:

From rude experiment it seems that:
1) In Python 2.x, standard error was always unbuffered while standard
output was buffered by default.  In python3, both are buffered. In
both cases, buffered means line-buffered when writing to the console
and not line-buffered when redirected to files.
2) In Python 2.x, the -u flag meant everything was totally
unbuffered. In Python 3.x, it means that both stdout and stderr are
line-buffered also when redirected to files.

Are either of these changes documented anywhere? (1) seems important :
it can lead to not seeing exception printouts, if stderr is redirected
to a file and the program is subsequently terminated with SIGTERM. I
just wasted quite a bit of time due to this situation...

This is what the Python 3 docs have to say about the -u flag:

Force the binary layer of the stdin, stdout and stderr streams (which
is available as their buffer attribute) to be unbuffered. The text I/O
layer will still be line-buffered.

The still seems misleading to me, as it is only relevant if writing
to the console. It would be useful to contrast the behaviour with and
without -u when writing to files I would say.

Regards,
Geoff Bache
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic variable creation from string

2011-12-09 Thread Ethan Furman

Massi wrote:

Thank you all for your replies, first of all my Sum function was an
example simplifying what I have to do in my real funciton. In general
the D dictionary is complex, with a lot of keys, so I was searching
for a quick method to access all the variables in it without doing the
explicit creation:

a, b, c = D['a'], D['b'], D['c']

and without using directly the D dictionary (boring...).
When I talked about nested function I meant both cases Chris, but this
is not a really tighten bound.
I tried to follow the hints of Chris together with some help by google
and used the following code:

for k in D : exec %s = D[k] %k

That seems to do the trick, but someone speaks about dirty code, can
anyone point me out which problems this can generate?
Again, thank you for your help!


Besides the serious security issues, this method won't make the problem 
any better in Python 3.


~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list


Re: Contacts/Addressbook application - any good Python ones out there?

2011-12-09 Thread tinnews
tinn...@isbd.co.uk wrote:
 Alec Taylor alec.tayl...@gmail.com wrote:
  Wammu?
  
 I hadn't really considered gammu/wammu as I saw it as a mobile phone
 synchrinsation tool, but I've looked a bit harder and it might very
 well be what I need - thank you!
 
Well one problem with wammu is that you can't do anything with the
program unless there's a phone connected.

-- 
Chris Green
-- 
http://mail.python.org/mailman/listinfo/python-list


Multiprocessing bug, is information ever omitted from a traceback?

2011-12-09 Thread John Ladasky
Hi folks,

A tangent off of this thread:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/751b7050c756c995#

I'm programming in Python 2.6 on Ubuntu Linux 10.10, if it matters.

I'm trying to track down a multiprocessing bug. Here's my traceback.
All lines of code referenced in the traceback are in the standard
library code:

Exception in thread Thread-1:
Traceback (most recent call last):
  File /usr/lib/python2.6/threading.py, line 532, in
__bootstrap_inner
self.run()
  File /usr/lib/python2.6/threading.py, line 484, in run
self.__target(*self.__args, **self.__kwargs)
  File /usr/lib/python2.6/multiprocessing/pool.py, line 284, in
_handle_tasks
put(task)
TypeError: expected string or Unicode object, NoneType found

Fortunately, I have a working version of my code.  I was trying to add
new features, and only my new code is causing trouble.  This has
allowed me to examine the contexts of task when everything works.

Task is not a string when the program works.  Task is not None when
the program doesn't work.  In fact, task is a deeply-nested tuple.  NO
PART of this tuple ever contains any strings, as far as I can tell.
More details in my original thread.

Now, of course I've seen that the standard traceback shows you the
lines where various steps in a chain of function calls were taken.
The traceback skips over any lines in the code between successive
function calls, and assumes that you can follow along.  No problem, I
can do that.

But when multiprocessing is involved, can this traceback be truncated
in some way, for example when code execution switches over to a
subprocess?  I'm wondering if more code is getting executed after
put(task) that I'm not seeing.

Thanks for any information!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2 or 3

2011-12-09 Thread Enrico 'Henryx' Bianchi
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Tobiah wrote:

 Use the newer version and don't look back.

Interesting reply, but if I have a platform wich doesn't support Python 3 
(e.g. RHEL 5.x)? ]:)

Enrico
P.S. note that: I *don't* want to recompile Python in production environment
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)

iQEcBAEBAgAGBQJO4pbOAAoJED3SMOGZLYdYQ7sIAI3vfvOyQc5Gx205cDMS7bPK
uXxZI7ShqybyEv0NMDapxURQhz59Kc9zh8E/OKDiXohjmkE1YA78K7qSKyrtXTMy
ppcGUU5USaQhPZ+RqOEj95aTxQj3CW/8w74rNEirIMn6+yGt4QjWRuGT1K6aUM51
BXF9I22f37z/sJ7x+fZUL9R7G1HA4saRGEiQGxBgkmt6gi28nboOibdxfw9bmP5x
aHbpVYQ6yo+7nOf0XZno/pl0zkpDvhS/tNvvuH8kYQIvMLyQZ/f+xZJ6yj58S5Se
AGSGXEDRemw0Ge83HjJvmQE3JXjy1fc1gCQSnmqQifXW7h18q99L3okJds+uHnE=
=PwK5
-END PGP SIGNATURE-

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


Re: Python 2 or 3

2011-12-09 Thread Steven D'Aprano
On Sat, 10 Dec 2011 00:16:30 +0100, Enrico 'Henryx' Bianchi wrote:

 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 Tobiah wrote:
 
 Use the newer version and don't look back.
 
 Interesting reply, but if I have a platform wich doesn't support Python
 3 (e.g. RHEL 5.x)? ]:)

RHEL supports Python 3, it just doesn't provide Python 3. It almost 
certainly will work if you install from source. I haven't tried it on 
RHEL myself, but I have done so on Fedora and Centos, and there's no 
problem.

But be warned that you should not replace the system python with Python 
3. When installing, don't use make install, as that will replace the 
system Python, instead use make altinstall. Then the command python 
will still refer to the system Python (probably Python 2.4 or 2.5?), and 
python3 should refer to Python 3.x.


 Enrico
 P.S. note that: I *don't* want to recompile Python in production
 environment

You shouldn't be learning programming on a production server :)


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


Re: I love the decorator in Python!!!

2011-12-09 Thread 88888 Dihedral
On Saturday, December 10, 2011 2:28:49 AM UTC+8, 8 Dihedral wrote:
 On Thursday, December 8, 2011 7:43:12 PM UTC+8, Chris Angelico wrote:
  On Thu, Dec 8, 2011 at 10:22 PM, K.-Michael Aye kmic...@gmail.com wrote:
   I am still perplexed about decorators though, am happily using Python for
   many years without them, but maybe i am missing something?
   For example in the above case, if I want the names attached to each other
   with a comma, why wouldn't I just create a function doing exactly this? 
   Why
   would I first write a single name generator and then decorate it so that I
   never can get single names anymore (this is the case, isn't it? Once
   decorated, I can not get the original behaviour of the function anymore.
  
  The example given is a toy. It's hardly useful. However, there are a
  number of handy uses for decorators; mostly, they consist of giving a
  single simple keyword to a complicated set of logic. One example is
  the @classmethod and @staticmethod decorators - the code to implement
  them could be uglier than nested inline assembly, but you don't have
  to care, because you just type @staticmethod in front of your def
  statement and it does its magic.
  
  Here's a handy trick that I'm sure someone has done in a more sophisticated 
  way:
  
  def trace(func):
  if debugmode:
  return lambda *a,**ka:
  (print(+func.__name__),func(*a,**ka),print(+func.__name__))[1]
  return func
  
  Then you put @trace in front of all your functions, and if debugmode
  is False, nothing will be done - but set it to true, and you get
  console output at the entry and exit of each function.
  
   @trace
  def test(x):
  print(Test! +x)
  return 5
  
   test(asdf)
  test
  Test! asdf
  test
  5
  
  Again, it's helpful because it condenses all the logic (including the
  'debugmode' flag) down to a single high level directive: Trace this
  function.
  
  ChrisA
 
 I did use decorators to turn functions into iterables to be traced.

It is easy to use decorators in python to mimic those programs in Erlang. 



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


Re: tracking variable value changes

2011-12-09 Thread Steven D'Aprano
On Thu, 08 Dec 2011 12:17:11 -0800, Catherine Moroney wrote:

 Hello,
 
 Is there a way to create a C-style pointer in (pure) Python so the
 following code will reflect the changes to the variable a in the
 dictionary x?

Strictly speaking, no, but there may be a way to get something close. See 
below.


 For example:
 
   a = 1.0
   b = 2.0
   x = {a:a, b:b}
   x
 {'a': 1.0, 'b': 2.0}
   a = 100.0
   x
 {'a': 1.0, 'b': 2.0}   ## at this point, I would like the value
 ## associated with the a key to be 100.0 ##
 rather than 1.0

The line a = 100 is a rebinding, and so what you are asking for isn't 
directly possible. But if you are willing to live with an explicit 
redirection, you can somewhat simulate a pointer with a list:


py aPtr = [1.0]  # not really a pointer, but let's pretend it is
py bPtr = [2.0]
py x = {'a': aPtr, 'b': bPtr}
py x
{'a': [1.0], 'b': [2.0]}
py aPtr[0] = 100.0
py x
{'a': [100.0], 'b': [2.0]}


If you prefer, you can write a simple class to handle the redirection 
with the interface of your choice. Something like this might be a good 
start:

class SharedValue:
def set(self, value):
self.value = value
def get(self):
return self.value
def __repr__(self):
# Somewhat dubious.
return str(self.value)

py a = SharedValue()  # create a pointer
py a.set(1.0)
py x = {'a': a}
py x
{'a': 1.0}
py a.set(100.0)
py x
{'a': 100.0}

Look at the automatic delegation pattern for a way to have operations on 
a automatically apply to the object being pointed to. (This will be 
*much* simpler if you don't inherit from object.)

But be warned, whatever you do, rebinding will behave in the standard 
Python way. E.g.:

py aPtr = [2000.0]  # Oops, rebound the name to something else!
py x  # and the connection is lost
{'a': [100.0], 'b': [2.0]}


 If I make a and b numpy arrays, then changes that I make to the
 values of a and b show up in the dictionary x.

Yes, because numpy arrays are mutable objects. In this case, you have two 
(or more) references to a single object: the name a, and the entry in 
dict x. When you modify the object in either place, the change is 
visible in both places because they are the same object.

But when you rebind the name a to another object -- not necessarily a 
*new* object, just a different one -- there is no way for the dict x to 
notice this change and follow along.

 My understanding is that when I redefine the value of a, that Python
 is creating a brand-new float with the value of 100.0, whereas when I
 use numpy arrays I am merely assigning a new value to the same object.

Correct. Although the float need not be brand-new. Python could (but 
probably doesn't) re-use an existing float object.



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


Obtaining user information

2011-12-09 Thread Tim Chase
Currently I can get the currently-logged-in-userid via 
getpass.getuser() which would yield something like tchase.


Is there a cross-platform way to get the full username (such as 
from the GECOS field of /etc/passed or via something like 
NetUserGetInfo on Win32 so I'd get Tim Chase instead?


Thanks,

-tkc




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


Re: How to build 64-bit Python on Solaris with GCC?

2011-12-09 Thread Skip Montanaro
 ./configure CFLAGS=-m64 LDFLAGS=-m64 should work with a reasonably
 recent revision.

Thanks, that did, indeed work with CPython trunk.  I eventually switched from
gcc to Sun's compiler though because I was getting link warnings.

Skip


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


Re: Buffering of sys.stdout and sys.stderr in python3 (and documentation)

2011-12-09 Thread Terry Reedy

On 12/9/2011 2:32 PM, Geoff Bache wrote:

Hi all,

Short version:

I'm a bit confused in general as to the changes between python2 and
python3 regarding how standard output and standard error do buffering.
A few things seem to have changed and I've failed to find any
documentation of how and why. Also, the meaning of python -u seems
to have changed and the docs don't seem to reflect the new behaviour
(and I can't find any docs about the change either)...

Long version:


From rude experiment it seems that:

1) In Python 2.x, standard error was always unbuffered while standard
output was buffered by default.  In python3, both are buffered. In
both cases, buffered means line-buffered when writing to the console
and not line-buffered when redirected to files.
2) In Python 2.x, the -u flag meant everything was totally
unbuffered. In Python 3.x, it means that both stdout and stderr are
line-buffered also when redirected to files.

Are either of these changes documented anywhere? (1) seems important :
it can lead to not seeing exception printouts, if stderr is redirected
to a file and the program is subsequently terminated with SIGTERM. I
just wasted quite a bit of time due to this situation...

This is what the Python 3 docs have to say about the -u flag:

Force the binary layer of the stdin, stdout and stderr streams (which
is available as their buffer attribute) to be unbuffered. The text I/O
layer will still be line-buffered.

The still seems misleading to me, as it is only relevant if writing
to the console. It would be useful to contrast the behaviour with and
without -u when writing to files I would say.


The difference from 2.x should be in What's New in 3.0, except that the 
new i/o module is in 2.6, so it was not exactly new. You might be able 
to find more in http://python.org/dev/peps/pep-3116/


You *should* be able to find sufficient info in the 3.x docs. If, after 
you get other responses (or not), you think the docs need upgrading, 
open an issue on the tracker at bugs.python.org with suggestions as 
specific as possible, including changed or new lines of text based on 
your experience and experiments.


--
Terry Jan Reedy

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


Re: Multiprocessing bug, is information ever omitted from a traceback?

2011-12-09 Thread Terry Reedy

On 12/9/2011 6:14 PM, John Ladasky wrote:


http://groups.google.com/group/comp.lang.python/browse_frm/thread/751b7050c756c995#

I'm programming in Python 2.6 on Ubuntu Linux 10.10, if it matters.


It might, as many bugs have been fixed since.
Can you try the same code with the most recent 2.x release, 2.7.2?
Do you have working and non-working code that you can publicly release?
Can you reduce the size and dependencies so the examples are closer to 
'small' than 'large'? And in any case, self-contained?


In my first response, I said you might have found a bug. A bogus 
exception message qualifies. But to do much, we need minimal good/bad 
examples that run or not on a current release (2.7.2 or 3.2.2).


--
Terry Jan Reedy

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


How to move scrollbar by code?

2011-12-09 Thread Muddy Coder
Hi Folks,

I am trying to make a listbox that will contain a looong data list,
sorted, so I will be able to pre-select a data line by coding. I have
done it. Say my listbox contains 1000 data lines, and my program has
figured out the data line 321 is needed, so just put the cursor on
data line 321. However, my scrollbar is still seating on the top, so I
just can view the data line from line 0 to 30 or 40, since I can't see
the desired data line 321.  I still need to manually pull the
scrollbar down to display the data line 321. What I want to do is to
grab the adjacent data lines, say from line 300 to 340, and display
this lines, while my cursor seating in the middle. I consulted the
Python Docs, but did not find such details. Can somebody give an idea?
Thanks!


Cosmo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to move scrollbar by code?

2011-12-09 Thread Chris Angelico
On Sat, Dec 10, 2011 at 4:05 PM, Muddy Coder cosmo_gene...@yahoo.com wrote:
 I am trying to make a listbox that will contain a looong data list,
 sorted, so I will be able to pre-select a data line by coding. I have
 done it.

Which GUI toolkit are you using? What you want is not the Python
language docs, but the docs for that toolkit (GTK, Qt, Tk, etc).


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


Re: Obtaining user information

2011-12-09 Thread Cameron Simpson
On 09Dec2011 19:44, Tim Chase python.l...@tim.thechases.com wrote:
| Currently I can get the currently-logged-in-userid via
| getpass.getuser() which would yield something like tchase.

_If_ you're on a terminal. _And_ that's exactly what you want.
Personally I need to the name of geteuid() or getuid() more often.

| Is there a cross-platform way to get the full username (such as from
| the GECOS field of /etc/passed or via something like NetUserGetInfo
| on Win32 so I'd get Tim Chase instead?

Hmm. Doesn't windows have a posix layer?

  pwd.getpwnam(os.getuid())[4].split(',')[0]

is the best I've got. ANd it probably doesn't work in Windows:-(
-- 
Cameron Simpson c...@zip.com.au DoD#743
http://www.cskk.ezoshosting.com/cs/

There's not a woman in his book, the plot hinges on unkindness to
animals, and the black characters mostly drown by chapter 29.
- P J O'Rourke parodying a PC review of Moby Dick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Obtaining user information

2011-12-09 Thread Hans Mulder

On 10/12/11 02:44:48, Tim Chase wrote:

Currently I can get the currently-logged-in-userid via getpass.getuser()
which would yield something like tchase.

Is there a cross-platform way to get the full username (such as from the
GECOS field of /etc/passed or via something like NetUserGetInfo on Win32
so I'd get Tim Chase instead?


How about:

pwd.getpwuid(os.getuid()).pw_gecos

This will give you the GECOS field of /etc/passed.
I'd assume it contains Tim Chase for your account.

Hope this helps,

-- HansM

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


[issue13547] Clean Lib/_sysconfigdata.py and Modules/_testembed

2011-12-09 Thread Stefan Krah

Stefan Krah stefan-use...@bytereef.org added the comment:

I guess this still needs to be fixed for Visual Studio.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13547
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13560] Add PyUnicode_DecodeLocale and PyUnicode_DecodeLocaleAndSize

2011-12-09 Thread Stefan Krah

Changes by Stefan Krah stefan-use...@bytereef.org:


--
nosy: +skrah

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13560
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13441] TestEnUSCollation.test_strxfrm() fails on Solaris

2011-12-09 Thread Roundup Robot

Roundup Robot devn...@psf.upfronthosting.co.za added the comment:

New changeset 2a2d0872d993 by Victor Stinner in branch 'default':
Issue #13441: Skip some locales (e.g. cs_CZ and hu_HU) on Solaris to workaround
http://hg.python.org/cpython/rev/2a2d0872d993

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13441
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12428] functools test coverage

2011-12-09 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

Brian's patch looks ok to me. There's a missing newline (or two) just before 
test_main() but that can easily be fixed on commit.

--
nosy: +pitrou
stage:  - commit review
versions: +Python 3.3 -Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12428
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13550] Rewrite logging hack of the threading module

2011-12-09 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

Tim, do you happen to know what the goal was with the threading._VERBOSE hack 
and the undocumented _Verbose class?

--
nosy: +pitrou, tim_one

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13550
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13563] Make use of with statement in ftplib

2011-12-09 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

The first hunk of the patch doesn't look right: ntransfercmd() is supposed to 
return the connection but the with statement closes it.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13563
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13441] TestEnUSCollation.test_strxfrm() fails on Solaris

2011-12-09 Thread Roundup Robot

Roundup Robot devn...@psf.upfronthosting.co.za added the comment:

New changeset 7ffe3d304487 by Victor Stinner in branch 'default':
Issue #13441: Enable the workaround for Solaris locale bug
http://hg.python.org/cpython/rev/7ffe3d304487

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13441
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13441] TestEnUSCollation.test_strxfrm() fails on Solaris

2011-12-09 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

I collected the locale list triggering the mbstowcs() bug thanks my previous 
commit:

 * hu_HU (ISO8859-2): character U+3020
 * de_AT (ISO8859-1): character U+3076
 * cs_CZ (ISO8859-2): character U+3020
 * sk_SK (ISO8859-2): character U+3020
 * pl_PL (ISO8859-2): character U+3020
 * fr_CA (ISO8859-1): character U+3020

Hum, the bug occurs maybe on all locales... I suppose that all xx_XX locales 
use an encoding different than UTF-8 and that the bug is specific to encodings 
different than UTF-8.

I don't understand why locale.strxfrm('à') doesn't crash anymore.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13441
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4352] imp.find_module() fails with a UnicodeDecodeError when called with non-ASCII search paths

2011-12-09 Thread Serg Asminog

Serg Asminog akudov...@gmail.com added the comment:

dirname = 'A-Za-z\xc4\xd6\xdc\xe4\xf6\xfc\xdf'

Traceback (most recent call last):
  File D:\temp\python bug\test.py, line 19, in module
file_object, file_path, description = imp.find_module(basename, [dirname])
UnicodeEncodeError: 'mbcs' codec can't encode characters in position 0--1: 
invalid character

--
nosy: +Serg.Asminog
Added file: http://bugs.python.org/file23891/test.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4352
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4352] imp.find_module() fails with a UnicodeDecodeError when called with non-ASCII search paths

2011-12-09 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

@Serg Asminog: What is your Python version? What is your locale encoding 
(print(sys.getfilesystemencoding())? What is your Windows version?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4352
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13565] test_multiprocessing.test_notify_all() hangs on AMD64 Snow Leopard 02 03.x

2011-12-09 Thread STINNER Victor

New submission from STINNER Victor victor.stin...@haypocalc.com:

[333/363] test_multiprocessing
Timeout (1:00:00)!
Thread 0x000112d0b000:
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/multiprocessing/connection.py,
 line 411 in _recv
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/multiprocessing/connection.py,
 line 432 in _recv_bytes
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/multiprocessing/connection.py,
 line 275 in recv
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/multiprocessing/managers.py,
 line 758 in _callmethod
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/multiprocessing/managers.py,
 line 994 in wait
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/test/test_multiprocessing.py,
 line 734 in f
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/threading.py, line 
682 in run
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/threading.py, line 
729 in _bootstrap_inner
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/threading.py, line 
702 in _bootstrap

Thread 0x000112908000:
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/multiprocessing/connection.py,
 line 411 in _recv
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/multiprocessing/connection.py,
 line 432 in _recv_bytes
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/multiprocessing/connection.py,
 line 275 in recv
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/multiprocessing/managers.py,
 line 758 in _callmethod
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/multiprocessing/managers.py,
 line 994 in wait
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/test/test_multiprocessing.py,
 line 734 in f
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/threading.py, line 
682 in run
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/threading.py, line 
729 in _bootstrap_inner
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/threading.py, line 
702 in _bootstrap

Thread 0x7fff7022ccc0:
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/multiprocessing/connection.py,
 line 411 in _recv
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/multiprocessing/connection.py,
 line 432 in _recv_bytes
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/multiprocessing/connection.py,
 line 275 in recv
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/multiprocessing/managers.py,
 line 758 in _callmethod
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/multiprocessing/managers.py,
 line 982 in acquire
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/test/test_multiprocessing.py,
 line 833 in test_notify_all
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/unittest/case.py, 
line 385 in _executeTestPart
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/unittest/case.py, 
line 440 in run
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/unittest/case.py, 
line 492 in __call__
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/unittest/suite.py, 
line 105 in run
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/unittest/suite.py, 
line 67 in __call__
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/unittest/suite.py, 
line 105 in run
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/unittest/suite.py, 
line 67 in __call__
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/unittest/suite.py, 
line 105 in run
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/unittest/suite.py, 
line 67 in __call__
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/unittest/runner.py,
 line 168 in run
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/test/support.py, 
line 1368 in _run_suite
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/test/support.py, 
line 1402 in run_unittest
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/test/test_multiprocessing.py,
 line 2392 in test_main
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/test/regrtest.py, 
line 1221 in runtest_inner
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/test/regrtest.py, 
line 907 in runtest
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/test/regrtest.py, 
line 710 in main
  File 
/Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/test/__main__.py, 
line 13 in module
  File /Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/runpy.py, 
line 73 in _run_code
  File /Users/buildbot/buildarea/3.x.parc-snowleopard-1/build/Lib/runpy.py, 
line 160 in _run_module_as_main
make: *** 

[issue11894] test_multiprocessing failure on AMD64 OpenIndiana 3.x: KeyError on id_to_obj[ident] in serve_client()

2011-12-09 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

I didn't see this failure again since the issue was opened, so I close it as 
invalid.

--
resolution:  - invalid
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11894
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13441] TestEnUSCollation.test_strxfrm() fails on Solaris

2011-12-09 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

The Solaris buildbot is green, let's close it. I didn't report the bug 
upstream. Feel free to report it to Oracle!

--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13441
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13566] Array objects pickled in 3.x with protocol =2 are unpickled incorrectly in 2.x

2011-12-09 Thread sbt

New submission from sbt shibt...@gmail.com:

If you pickle an array object on python 3 the typecode is encoded as a unicode 
string rather than as a byte string.  This makes python 2 reject the pickle.

#

Python 3.3.0a0 (default, Dec  8 2011, 17:56:13) [MSC v.1500 32 bit (Intel)] on 
win32
Type help, copyright, credits or license for more information.
 import pickle, array
 pickle.dumps(array.array('i', [1,2,3]), 2)
b'\x80\x02carray\narray\nq\x00X\x01\x00\x00\x00iq\x01]q\x02(K\x01K\x02K\x03e\x86q\x03Rq\x04.'

#

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on 
win32
Type help, copyright, credits or license for more information.
 import pickle
 pickle.loads(b'\x80\x02carray\narray\nq\x00X\x01\x00\x00\x00iq\x01]q\x02(K\x01K\x02K\x03e\x86q\x03Rq\x04.')
Traceback (most recent call last):
  File stdin, line 1, in module
  File c:\Python27\lib\pickle.py, line 1382, in loads
return Unpickler(file).load()
  File c:\Python27\lib\pickle.py, line 858, in load
dispatch[key](self)
  File c:\Python27\lib\pickle.py, line 1133, in load_reduce
value = func(*args)
TypeError: must be char, not unicode

--
components: Library (Lib)
messages: 149092
nosy: sbt
priority: normal
severity: normal
status: open
title: Array objects pickled in 3.x with protocol =2 are unpickled incorrectly 
in 2.x
type: behavior
versions: Python 3.2, Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13566
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13566] Array objects pickled in 3.x with protocol =2 are unpickled incorrectly in 2.x

2011-12-09 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +alexandre.vassalotti, pitrou

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13566
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13505] Bytes objects pickled in 3.x with protocol =2 are unpickled incorrectly in 2.x

2011-12-09 Thread sbt

sbt shibt...@gmail.com added the comment:

 sbt, the bug is not that the encoding is inefficient. The problem is we 
 cannot unpickle bytes streams from Python 3 using Python 2.

Ah.  Well you can do it using codecs.encode.

Python 3.3.0a0 (default, Dec  8 2011, 17:56:13) [MSC v.1500 32 bit (Intel)] on 
win32
Type help, copyright, credits or license for more information.
 import pickle, codecs

 class MyBytes(bytes):
... def __reduce__(self):
... return codecs.encode, (self.decode('latin1'), 'latin1')
...
 pickle.dumps(MyBytes(bhello), 2)
b'\x80\x02c_codecs\nencode\nq\x00X\x05\x00\x00\x00helloq\x01X\x06\x00\x00\x00latin1q\x02\x86q\x03Rq\x04.'

Actually, I notice that array objects created by Python 3 are not decodable on 
Python 2.  See Issue 13566.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13505
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2775] Implement PEP 3108

2011-12-09 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

 Brett, issue 2919 had a patch that merges profile/cProfile for a while 
 now but nobody test it yet.

 All I need it someone to download the patch, install it, test it on
 some random script and tell me if it works. I don't need more.

I don't see any patch there, only a .tgz and two Python files.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2775
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13549] Incorrect nested list comprehension documentation

2011-12-09 Thread Ezio Melotti

Ezio Melotti ezio.melo...@gmail.com added the comment:

In the first patch I included this example:
+swapped = []
+for i in [0, 1, 2]:
+   ... swapped.append([row[i] for row in mat])
+   ...
+print swapped
+   [[1, 4, 7], [2, 5, 8], [3, 6, 9]]

Because I applied the following transformation without looking at what expr was 
(another listcomp in this case):
res = [expr for elem in seq]
==
   res = []
   for elem in seq:
   res.append(expr)

If the reader does the same he/she wouldn't have any problem figuring out what 
is the order of the `for`s, but the second version of the patch only includes a 
fully expanded example:
+transposed = []
+for i in range(4):
+   ... # the following 3 lines implement the nested listcomp
+   ... transposed_row = []
+   ... for row in matrix:
+   ... transposed_row.append(row[i])
+   ... transposed.append(transposed_row)
+   ...
+transposed

Here it's easier to confuse the two `for` (not because they are similar, but 
because there are two of them, whereas in the previous example there's only 
one).

I added a comment to clarify that the inner loop is the listcomp, but maybe it 
would be better to show the first example too, followed by the fully expanded 
one, i.e.:

+   [[row[i] for row in mat] for i in range(4)]

+transposed = []
+for i in range(4):
+   ... transposed.append([row[i] for row in mat])
+   ...
+transposed

+transposed = []
+for i in range(4):
+   ... # the following 3 lines implement the nested listcomp
+   ... transposed_row = []
+   ... for row in matrix:
+   ... transposed_row.append(row[i])
+   ... transposed.append(transposed_row)
+   ...
+transposed

The step in the middle shows that in order to get to the fully expanded form, 
it's enough to apply the usual listcomp-for+append transformation twice, 
without worrying about left-to-right vs right-to-left.  Do you think it's worth 
adding this?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13549
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13557] exec of list comprehension fails on NameError

2011-12-09 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc amaur...@gmail.com added the comment:

This is expected and documented: 
http://docs.python.org/py3k/reference/executionmodel.html#interaction-with-dynamic-features
Free variables are not resolved in the nearest enclosing namespace, but in the 
global namespace., a free variable being a variable used in a code block but 
not defined there.
And yes, a list comprehension defines a code block.

Try using exec(code, locals()). It's a good habit anyway to always pass a 
namespace to exec().

--
nosy: +amaury.forgeotdarc
resolution:  - invalid
status: open - pending

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13557
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4352] imp.find_module() fails with a UnicodeDecodeError when called with non-ASCII search paths

2011-12-09 Thread Serg Asminog

Serg Asminog akudov...@gmail.com added the comment:

print(sys.getfilesystemencoding())
print(os.name)
print(sys.version)
print(sys.version_info)
print(sys.platform)

-
mbcs
nt
3.2.2 (default, Sep  4 2011, 09:07:29) [MSC v.1500 64 bit (AMD64)]
sys.version_info(major=3, minor=2, micro=2, releaselevel='final', serial=0)
win32

---
Windows 7 64bit

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4352
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4352] imp.find_module() fails with a UnicodeDecodeError when called with non-ASCII search paths

2011-12-09 Thread Serg Asminog

Serg Asminog akudov...@gmail.com added the comment:

Also 

Traceback (most recent call last):
  File D:\temp\python bug\test.py, line 20, in module
file_object, file_path, description = imp.find_module(basename, [dirname])
ImportError: No module named mymodule

with python  2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit 
(AMD64)]

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4352
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4352] imp.find_module() fails with a UnicodeDecodeError when called with non-ASCII search paths

2011-12-09 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

Oops, it's not sys.getfilesystemencoding(), but locale.getpreferredencoding() 
which is interesting. Can you give me your locale encoding?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4352
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13557] exec of list comprehension fails on NameError

2011-12-09 Thread Stephan R.A. Deibel

Stephan R.A. Deibel sdei...@wingware.com added the comment:

Ah, thanks, there it is... I thought this must be dealt with somewhere but 
couldn't find it.  Maybe should add something to the 'exec' statement docs 
http://docs.python.org/py3k/library/functions.html#exec to reference this (from 
a usability-of-docs standpoint).

BTW, my code already sends the namespaces to exec (from current stack frame; 
it's part of a debugger) and probably would break other cases to alter this.

Well, anyway, sorry for the invalid bug report...

--
status: pending - open

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13557
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13566] Array objects pickled in 3.x with protocol =2 are unpickled incorrectly in 2.x

2011-12-09 Thread maniram maniram

maniram maniram maniandra...@gmail.com added the comment:

The problem is that pickle is calling array.array(u'i',[1,2,3]) and array.array 
in Python 2 doesn't allow unicode strings as a typecode (typecode is the first 
argument)

The docs in Python 2 and Py3k doesn't specify the type of the typecode argument 
of array.array.
In Python 2 it seems that typecode has to be a bytes string.
In Python 3 it seems that typecode has to be a unicode string.

I suggest that array.array be changed in Python 2 to allow unicode strings as a 
typecode or that pickle detects array.array being called and fixes the call.

--
nosy: +maniram.maniram

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13566
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1757072] Zipfile robustness

2011-12-09 Thread James C. Ahlstrom

James C. Ahlstrom jahl...@gmail.com added the comment:

Problem was reported on 2.7.  I will check in detail this weekend.  Please 
stand by.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1757072
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4352] imp.find_module() fails with a UnicodeDecodeError when called with non-ASCII search paths

2011-12-09 Thread Serg Asminog

Serg Asminog akudov...@gmail.com added the comment:

cp1251

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4352
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13566] Array objects pickled in 3.x with protocol =2 are unpickled incorrectly in 2.x

2011-12-09 Thread sbt

sbt shibt...@gmail.com added the comment:

 I suggest that array.array be changed in Python 2 to allow unicode strings 
 as a typecode or that pickle detects array.array being called and fixes 
 the call.

Interestingly, py3 does understand arrays pickled by py2.  This appears to be 
because py2 pickles str using BINSTRING or SHORT_BINSTRING which will unpickle 
as str on py2 and py3.  py3 pickles str using BINUNICODE which will unpickle as 
unicode on py2 and str on py3.

I think it would be better to fix this in py3 if possible, but that does not 
look easy: modifying array.__reduce_ex__ alone would not be enough.

The only thing I can think of is for py3 to grow a _binstr type which only 
supports ascii strings and is special-cased by pickle to be pickled using 
BINSTRING.  Then array.__reduce_ex__ could be something like:

  def __reduce_ex__(self, protocol):
if protocol = 2:
  return array.array, (_binstr(self.typecode), list(self))
else:
  ...

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13566
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12428] functools test coverage

2011-12-09 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

Ezio and I made further minor comments that can be handled by the person doing 
the commit; I’d like to do it.

--
nosy: +eric.araujo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12428
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13567] HTTPError interface changes / breaks depending on what was passed to constructor

2011-12-09 Thread Pami Ketolainen

New submission from Pami Ketolainen pami.ketolai...@gmail.com:

In case of authentication error, HTTPError gets initialized without file object 
and constructor of addinfourl is not called. This means that url attribute is 
not set and geturl() (inherited from addinfourl) raises AttributeError.

geturl() is not documented as part of HTTPError interface, so I'm not sure if 
it is correct to expect it to work. And of course this can be worked around by 
using the HTTPError.filename which always contains the url passed to 
constructor.

How ever, I have made a simple patch to fix the missing attribute.


There is also Issue5286 with a patch, which makes the http_error_auth_reqed 
pass the fp to HTTPError making it a file-like object as stated in the 
documentation. So that would probably be the correct solution.

IMHO it's a bit bad design, when objects interface changes depending on how it 
was initialized.

--
components: Library (Lib)
files: httperror-geturl-fix-2.patch
keywords: patch
messages: 149106
nosy: Keto
priority: normal
severity: normal
status: open
title: HTTPError interface changes / breaks depending on what was passed to 
constructor
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file23892/httperror-geturl-fix-2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13567
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13567] HTTPError interface changes / breaks depending on what was passed to constructor

2011-12-09 Thread Pami Ketolainen

Pami Ketolainen pami.ketolai...@gmail.com added the comment:

Patch adapted to 3.3

--
Added file: http://bugs.python.org/file23893/httperror-geturl-fix-3.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13567
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3786] _curses, _curses_panel _multiprocessing can't be build in 2.6b3 w/ SunStudio 12

2011-12-09 Thread Jesús Cea Avión

Changes by Jesús Cea Avión j...@jcea.es:


--
nosy: +jcea

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue3786
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13547] Clean Lib/_sysconfigdata.py and Modules/_testembed

2011-12-09 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

None of these two files is generated under Windows (_sysconfigdata.py by design 
and _testembed because nobody volunteered to do it).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13547
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1757072] Zipfile robustness

2011-12-09 Thread James C. Ahlstrom

James C. Ahlstrom jahl...@gmail.com added the comment:

I grabbed a 2.7.2 zipfile.py, and my original comments stand.  If there is a 
garbage at end of file patch, I can't find it; please provide a line number 
or a hint.  The user at yale.edu reports that the patch works.  Here is a diff 
of my changes.  To test, append some junk to a good zipfile: echo junk  
good.zip, and try reading it.  Let me know if you want me to do anything else; 
maybe look at 3.2; or email me offline.

*** zipfile.py  2011-12-09 11:25:07.0 -0500
--- ../zipfile.py   2011-12-09 05:48:00.0 -0500
***
*** 237,248 
  recData = data[start:start+sizeEndCentDir]
  endrec = list(struct.unpack(structEndArchive, recData))
  comment = data[start+sizeEndCentDir:]
! ## Remove   # check that comment length is correct
! ## Remove   if endrec[_ECD_COMMENT_SIZE] == len(comment):
! # check that the offset to the Central Directory points to a valid 
item
! fpin.seek(endrec[_ECD_OFFSET], 0)
! dat = fpin.read(4)
! if dat == stringCentralDir:
  # Append the archive comment and start offset
  endrec.append(comment)
  endrec.append(maxCommentStart + start)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1757072
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12567] curses implementation of Unicode is wrong in Python 3

2011-12-09 Thread Jesús Cea Avión

Jesús Cea Avión j...@jcea.es added the comment:

Victor, I have these notes I wrote down when I set up the OpenIndiana 
buildbots. Maybe can be useful to you: (compiling from source)


  * ncurses 5.7: Instalación estándar ./configure --with-shared 
--without-normal --enable-widec --without-cxx-binding. Al curses que viene con 
OpenIndiana le faltan un par de funciones: mvwchgat y wchgat.



I installed ncurses because the lack of mvwchgat and wchgat.

When compiling Python, I add export CFLAGS=-I/usr/local/include/ncursesw to 
help it to find the right lib.

Hope to be useful.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12567
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12567] curses implementation of Unicode is wrong in Python 3

2011-12-09 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

 I wrote down when I set up the OpenIndiana buildbots

Hum, please use the issue #13552 for curses issues on OpenIndiana/Solaris.

 ... de funciones: mvwchgat y wchgat

See issues #3786 and  #13552 for this problem.

 I installed ncurses ... I add export CFLAGS=-I/usr/local/include/ncursesw

The curses module is compiled by setup.py, not Makefile. It looks that setup.py 
ignores CFLAGS. I don't know if setup.py permits to specify such option.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12567
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13547] Clean Lib/_sysconfigdata.py and Modules/_testembed

2011-12-09 Thread Stefan Krah

Stefan Krah stefan-use...@bytereef.org added the comment:

Excellent, closing then.

--
resolution:  - fixed
stage: needs patch - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13547
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13568] sqlite3 convert_date error with DATE type

2011-12-09 Thread Gianluigi Tiesi

New submission from Gianluigi Tiesi sher...@gmail.com:

When using the 'DATE' datatype in a sqlite3 db and type converters are enabled 
the function in sqlite3/dbapi2.py fails

I'm not sure why sqlite3 returns something like 10-JAN-11, but the function 
expects a ts

example:

import sqlite3
d = sqlite3.connect(:memory:, detect_types=sqlite3.PARSE_DECLTYPES)
c = d.cursor()
c.execute(create table testdate (t1 date))
c.execute(insert into testdate values ('now'))
c.execute(select * from testdate)

--
components: Library (Lib)
messages: 149113
nosy: sherpya
priority: normal
severity: normal
status: open
title: sqlite3 convert_date error with DATE type
type: behavior
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13568
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13505] Bytes objects pickled in 3.x with protocol =2 are unpickled incorrectly in 2.x

2011-12-09 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

  sbt, the bug is not that the encoding is inefficient. The problem is we 
  cannot unpickle bytes streams from Python 3 using Python 2.
 
 Ah.  Well you can do it using codecs.encode.

Great. A bit hackish but functional and not too inefficient (50% average
expansion).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13505
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5905] strptime fails in non-UTF locale

2011-12-09 Thread Roundup Robot

Roundup Robot devn...@psf.upfronthosting.co.za added the comment:

New changeset 8620e6901e58 by Victor Stinner in branch '3.2':
Issue #5905: time.strftime() is now using the locale encoding, instead of
http://hg.python.org/cpython/rev/8620e6901e58

New changeset bee7694988a4 by Victor Stinner in branch 'default':
(Merge 3.2) Issue #5905: time.strftime() is now using the locale encoding,
http://hg.python.org/cpython/rev/bee7694988a4

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5905
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5905] strptime fails in non-UTF locale

2011-12-09 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@haypocalc.com:


--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5905
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13560] Add PyUnicode_DecodeLocale and PyUnicode_DecodeLocaleAndSize

2011-12-09 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

I fixed issue #5905 (strptime fails in non-UTF locale). The fix is not enough 
if the locale is changed in Python.

Update the patch to fix time.strftime() (if wcsftime() is not available).

--
Added file: http://bugs.python.org/file23894/pyunicode_decodelocale-2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13560
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6699] IDLE: Warn user about overwriting a file that has a newer version on filesystem

2011-12-09 Thread Roger Serwy

Roger Serwy roger.se...@gmail.com added the comment:

The patch won't apply against 3.3a0 because self.set_saved(1) became 
self.set_saved(True) in r70054 (da7a120c0478)

After correcting this minor point, the patch works as expected.

--
nosy: +serwy
versions: +Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6699
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2919] Merge profile/cProfile in 3.0

2011-12-09 Thread Eric Snow

Changes by Eric Snow ericsnowcurren...@gmail.com:


--
nosy: +eric.snow

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2919
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13569] multiprocessing module: Process.start() fails with EOFError: pickle.PicklingError: Can't pickle type 'thread.lock': it's not found as thread.lock

2011-12-09 Thread Nikita Pchelin

New submission from Nikita Pchelin nikita.pche...@gmail.com:

I've wrote a little application that uses multiprocessing module:
https://github.com/jango/PC/blob/master/pc/pc-example.py

When I run it in my Linux setup, I get the expected output (Python 2.7.1+):
2011-12-09 14:16:29,014 Started Producer 0.
2011-12-09 14:16:29,076 Started Producer 1.
2011-12-09 14:16:29,076 Producer process (0) exited...
2011-12-09 14:16:29,131 Started Producer 2.
2011-12-09 14:16:29,188 Started Producer 3.
2011-12-09 14:16:29,218 Started Producer 4.
2011-12-09 14:16:29,281 Started Producer 5.
2011-12-09 14:16:29,327 Started Producer 6.
2011-12-09 14:16:29,377 Started Producer 7.
2011-12-09 14:16:29,403 Producer process (1) exited...
2011-12-09 14:16:29,412 Started Producer 8.
2011-12-09 14:16:29,504 Started Producer 9.
2011-12-09 14:16:29,528 Producer process (4) exited...
2011-12-09 14:16:29,570 Started Producer 10.
2011-12-09 14:16:29,615 Started Producer 11.
2011-12-09 14:16:29,622 Producer process (3) exited...
2011-12-09 14:16:29,637 Producer process (7) exited...
2011-12-09 14:16:29,653 Producer process (5) exited...
2011-12-09 14:16:29,692 Started Producer 12.
2011-12-09 14:16:29,731 Producer process (12) exited...
2011-12-09 14:16:29,747 Started Producer 13.
2011-12-09 14:16:29,809 Started Producer 14.
2011-12-09 14:16:29,860 Started Producer 15.
2011-12-09 14:16:29,903 Producer process (2) exited...
2011-12-09 14:16:29,905 Started Producer 16.
2011-12-09 14:16:29,918 Producer process (8) exited...
2011-12-09 14:16:29,970 Started Producer 17.
2011-12-09 14:16:30,001 Started Producer 18.
2011-12-09 14:16:30,070 Started Producer 19.
2011-12-09 14:16:30,090 Producer process (11) exited...
2011-12-09 14:16:30,105 Producer process (10) exited...
2011-12-09 14:16:30,137 Started Producer 20.
2011-12-09 14:16:30,152 Producer process (6) exited...
2011-12-09 14:16:30,183 Producer process (9) exited...
2011-12-09 14:16:30,183 Producer process (17) exited...
2011-12-09 14:16:30,251 Started Producer 21.
2011-12-09 14:16:30,288 Started Producer 22.
2011-12-09 14:16:30,308 Producer process (18) exited...
2011-12-09 14:16:30,308 Producer process (20) exited...
2011-12-09 14:16:30,355 Producer process (16) exited...
2011-12-09 14:16:30,380 Started Producer 23.
2011-12-09 14:16:30,436 Started Producer 24.
2011-12-09 14:16:30,472 Started Producer 25.
2011-12-09 14:16:30,480 Producer process (22) exited...
2011-12-09 14:16:30,509 Started Producer 26.
2011-12-09 14:16:30,554 Started Producer 27.
2011-12-09 14:16:30,609 Started Producer 28.
2011-12-09 14:16:30,620 Producer process (14) exited...
2011-12-09 14:16:30,636 Producer process (15) exited...
2011-12-09 14:16:30,660 Started Producer 29.
2011-12-09 14:16:30,667 Producer process (19) exited...
2011-12-09 14:16:30,667 Producer process (13) exited...
2011-12-09 14:16:30,667 Producer process (27) exited...
2011-12-09 14:16:30,750 Started Consumer 0.
2011-12-09 14:16:30,761 -- 0 produces 0.
2011-12-09 14:16:30,776 Producer process (28) exited...
2011-12-09 14:16:30,770 -- 1 produces 10.
2011-12-09 14:16:30,783 -- 4 produces 40.
2011-12-09 14:16:30,797 Started Consumer 1.
2011-12-09 14:16:30,807 -- 3 produces 30.
2011-12-09 14:16:30,816 -- 5 produces 50.
2011-12-09 14:16:30,817 -- 12 produces 120.
2011-12-09 14:16:30,819 -- 2 produces 20.
2011-12-09 14:16:30,826 -- 8 produces 80.
2011-12-09 14:16:30,835 -- 11 produces 110.
2011-12-09 14:16:30,848 -- 10 produces 100.
2011-12-09 14:16:30,849 -- 6 produces 60.
2011-12-09 14:16:30,852 -- 17 produces 170.
2011-12-09 14:16:30,853 -- 9 produces 90.
2011-12-09 14:16:30,859 -- 18 produces 180.
2011-12-09 14:16:30,860 -- 20 produces 200.
2011-12-09 14:16:30,865 -- 16 produces 160.
2011-12-09 14:16:30,866 -- 22 produces 220.
2011-12-09 14:16:30,867 -- 14 produces 140.
2011-12-09 14:16:30,868 -- 15 produces 150.
2011-12-09 14:16:30,869 -- 19 produces 190.
2011-12-09 14:16:30,874 -- 13 produces 130.
2011-12-09 14:16:30,823 Producer process (21) exited...
2011-12-09 14:16:30,812 -- 7 produces 70.
2011-12-09 14:16:30,893 -- 28 produces 280.
2011-12-09 14:16:30,854 Producer process (25) exited...
2011-12-09 14:16:30,894 Started Consumer 2.
2011-12-09 14:16:30,875 -- 27 produces 270.
2011-12-09 14:16:30,905 -- 25 produces 250.
2011-12-09 14:16:30,917 -- 21 produces 210.
2011-12-09 14:16:30,943 Started Consumer 3.
2011-12-09 14:16:31,002 Started Consumer 4.
2011-12-09 14:16:31,049 Started Consumer 5.
2011-12-09 14:16:31,091 Started Consumer 6.
2011-12-09 14:16:31,137 Started Consumer 7.
2011-12-09 14:16:31,197 Producer process (23) exited...
2011-12-09 14:16:31,213 -- 23 produces 230.
2011-12-09 14:16:31,206 Started Consumer 8.
2011-12-09 14:16:31,263 Started Consumer 9.
2011-12-09 14:16:31,275 Producer process (24) exited...
2011-12-09 14:16:31,307 Started Consumer 10.
2011-12-09 14:16:31,322 -- 24 produces 240.
2011-12-09 14:16:31,357 Started Consumer 11.
2011-12-09 14:16:31,386 Started Consumer 12.
2011-12-09 14:16:31,400 Producer process (26) 

[issue13569] multiprocessing module: Process.start() fails with EOFError: pickle.PicklingError: Can't pickle type 'thread.lock': it's not found as thread.lock

2011-12-09 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

Yes, Windows needs to pickle objects which are sent to (or returned from) a 
child process. Now you should wonder why you are sending a threading lock to 
the child. Are you sure this is deliberate?

--
nosy: +pitrou
versions: +Python 2.7, Python 3.2, Python 3.3 -Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13569
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11886] test_time.test_tzset() fails on x86 FreeBSD 7.2 3.x: AEST timezone called EST

2011-12-09 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

The FreeBSD 7.2 3.x buildbot is green.

--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11886
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13569] multiprocessing module: Process.start() fails with EOFError: pickle.PicklingError: Can't pickle type 'thread.lock': it's not found as thread.lock

2011-12-09 Thread Nikita Pchelin

Nikita Pchelin nikita.pche...@gmail.com added the comment:

I am not sending locks explicetly (i.e. I am not using locks), but I do
pass a Queue object from PC instance to _Consumer and _Producer instances
that get/put values from/to the queue -- this is done deliberately.

2011/12/9 Antoine Pitrou rep...@bugs.python.org


 Antoine Pitrou pit...@free.fr added the comment:

 Yes, Windows needs to pickle objects which are sent to (or returned from)
 a child process. Now you should wonder why you are sending a threading lock
 to the child. Are you sure this is deliberate?

 --
 nosy: +pitrou
 versions: +Python 2.7, Python 3.2, Python 3.3 -Python 2.6

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue13569
 ___


--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13569
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13569] multiprocessing module: Process.start() fails with EOFError: pickle.PicklingError: Can't pickle type 'thread.lock': it's not found as thread.lock

2011-12-09 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

 I am not sending locks explicetly (i.e. I am not using locks), but I do
 pass a Queue object from PC instance to _Consumer and _Producer instances
 that get/put values from/to the queue -- this is done deliberately.

Is it a Queue.Queue or a multiprocessing.Queue?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13569
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13569] multiprocessing module: Process.start() fails with EOFError: pickle.PicklingError: Can't pickle type 'thread.lock': it's not found as thread.lock

2011-12-09 Thread Nikita Pchelin

Nikita Pchelin nikita.pche...@gmail.com added the comment:

It's multiprocessing Queue:

from multiprocessing import Process, Queue, Event

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13569
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13570] Expose faster unicode-ascii functions in the C-API

2011-12-09 Thread Stefan Krah

New submission from Stefan Krah stefan-use...@bytereef.org:

I just ran the telco benchmark ...

  http://www.bytereef.org/mpdecimal/quickstart.html#telco-benchmark

... on _decimal to see how the PEP-393 changes affect the module.
The benchmark reads numbers from a binary file, does some calculations
and prints the result strings to a file.


Average results (10 iterations each):

Python 2.7:5.87s
Revision 1726fa560112: 6.07s
Revision 7ffe3d304487: 6.56s


The bottleneck in telco.py is the line that writes a Decimal to the
output file:

  outfil.write(%s\n % t)

The bottleneck in _decimal is (res is ascii):

   PyUnicode_FromString(res);

PyUnicode_DecodeASCII(res) has the same performance.


With this function ...

  static PyObject*
unicode_fromascii(const char* s, Py_ssize_t size)
{
PyObject *res;
res = PyUnicode_New(size, 127);
if (!res)
return NULL;
memcpy(PyUnicode_1BYTE_DATA(res), s, size);
return res;
}

... I get the same performance as with Python 2.7 (5.85s)!


I think it would be really beneficial for C-API users to have
more ascii low level functions that don't do error checking and
are simply as fast as possible.

--
components: Unicode
messages: 149124
nosy: ezio.melotti, haypo, loewis, skrah
priority: normal
severity: normal
status: open
title: Expose faster unicode-ascii functions in the C-API
type: performance
versions: Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13570
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10364] IDLE: make .py default added extension on save

2011-12-09 Thread Roger Serwy

Roger Serwy roger.se...@gmail.com added the comment:

This is a duplicate of #4832.

--
nosy: +serwy

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10364
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >