Re: Default paranmeter for packed values

2010-04-19 Thread Gregory Ewing

MRAB wrote:

Xavier Ho wrote:


 def t(a, *b = (3, 4)):


  File input, line 1
def t(a, *b = (3, 4)):
^
SyntaxError: invalid syntax

What was the rationale behind this design?


The concept of a default value for the * argument doesn't
really apply, because there is always a value for it, even
if it's just an empty tuple.

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


Operations on sparse matrices

2010-04-19 Thread pp
I am currently dealing with sparse matrices and have doubts on whether
we can use
1.) dot (for matrix multiplication) and inv (inverse) operations of
numpy on sparse matrices of CSR format.

I initially constructed my sparse matrix using COO format and then
converted it to CSR format now I want to know whether normal inverse
and matrix multiplications work with sparse csr matrices.

Also can these operations be applied directly to csr matrices


Thanks a lot
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Usable street address parser in Python?

2010-04-19 Thread Paul McGuire
On Apr 17, 2:23 pm, John Nagle na...@animats.com wrote:
    Is there a usable street address parser available?  There are some
 bad ones out there, but nothing good that I've found other than commercial
 products with large databases.  I don't need 100% accuracy, but I'd like
 to be able to extract street name and street number for at least 98% of
 US mailing addresses.

    There's pyparsing, of course. There's a street address parser as an
 example at http://pyparsing.wikispaces.com/file/view/streetAddressParser.py;.
 It's not very good.  It gets all of the following wrong:

         1500 Deer Creek Lane    (Parses Creek as a street type)
         186 Avenue A            (NYC street)
         2081 N Webb Rd          (Parses N Webb as a street name)
         2081 N. Webb Rd         (Parses N as street name)
         1515 West 22nd Street   (Parses West as name)
         2029 Stierlin Court     (Street names starting with St misparse.)

 Some special cases that don't work, unsurprisingly.
         P.O. Box 33170
         The Landmark @ One Market, Suite 200
         One Market, Suite 200
         One Market


Please take a look at the updated form of this parser.  It turns out
there actually *were* some bugs in the old form, plus there was no
provision for PO Boxes, avenues that start with Avenue instead of
ending with them, or house numbers spelled out as words.  The only one
I consider a special case is the support for Avenue X instead of
X Avenue - adding support for the rest was added in a fairly general
way.  With these bug fixes, I hope this improves your hit rate. (There
are also some simple attempts at adding apt/suite numbers, and APO and
AFP in addition to PO boxes - if not exactly what you need, the means
to extend to support other options should be pretty straightforward.)

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


Re: Usable street address parser in Python?

2010-04-19 Thread Stefan Behnel

John Nagle, 17.04.2010 21:23:

  Is there a usable street address parser available?


What kind of street address are you talking about? Only US-American ones?

Because street addresses are spelled differently all over the world. Some 
have house numbers, some use letters or a combination, some have no house 
numbers at all. Some use ordinal numbers, others use regular numbers. Some 
put the house number before the street name, some after it. And this is 
neither a comprehensive list, nor is this topic finished after parsing the 
line that gives you the street (assuming there is such a thing in the first 
place).


Stefan

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


About the grammar

2010-04-19 Thread franck
Dear all,

I'm wondering why in Python's grammar, keyword arguments are specified
as:

argument: ... | test '=' test

I would have expected something like

argument: ... | NAME '=' test

Indeed, I cannot imagine a case where the keyword is something else
than an identifier. Moreover, in the Python language reference (see
http://docs.python.org/reference/expressions.html#grammar-token-keyword_item)
one can read:

keyword_item ::= identifier = expression

which is what I was expecting.

Does any one knows why the grammar is so coded? Any intuition?

Thanks in advance!
Franck
-- 
http://mail.python.org/mailman/listinfo/python-list


help req debugging python and c together

2010-04-19 Thread sanam singh

Hi,
I am working in gnuradio compiler. I need some help in debugging python and c 
together.
By this i mean that i have written some blocks in c that are connected together 
using python. So i need to debug( breakpoints ect ) python such that when a 
specific c block is called at the back end  (in python script ) the debugger 
takes me into the c code and after that switches back to python and so on.

Thanks in advance.
Regards,
Sanam
  
_
Hotmail: Powerful Free email with security by Microsoft.
https://signup.live.com/signup.aspx?id=60969-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About the grammar

2010-04-19 Thread Steven D'Aprano
On Sun, 18 Apr 2010 23:29:44 -0700, franck wrote:

 Dear all,
 
 I'm wondering why in Python's grammar, keyword arguments are specified
 as:
 
 argument: ... | test '=' test


Where are you finding that?


 I would have expected something like
 
 argument: ... | NAME '=' test
 
 Indeed, I cannot imagine a case where the keyword is something else than
 an identifier. Moreover, in the Python language reference (see
 http://docs.python.org/reference/expressions.html#grammar-token-
keyword_item)
 one can read:
 
 keyword_item ::= identifier = expression
 
 which is what I was expecting.

This tells you that keyword arguments cannot have keywords that aren't 
identifiers:

 sum(1=2)
  File stdin, line 1
SyntaxError: keyword can't be an expression


The only thing I can think of is that you're extrapolating from use cases 
like this:


 def f(x):
... return x
...
 x=2
 f(x=x)
2

But that's just a special case of this:

 y=2
 f(x=y)
2


Of course, I could be completely misunderstanding what you mean.




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


Re: UnicodeEncodeError during repr()

2010-04-19 Thread Martin v. Loewis
 Do I need to do something especial to get repr to work strictly
 with unicode?

Yes, you need to switch to Python 3 :-)

 Or should __repr__ *always* return bytes rather than unicode?

In Python 2.x: yes.

 What about __str__ ?

Likewise.

 If both of these are supposed to return bytes,
 then what method should I use to define the unicode representation
 for instances of a class?

__unicode__.

HTH,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About the grammar

2010-04-19 Thread Martin v. Loewis
 Does any one knows why the grammar is so coded? Any intuition?

The 2.7 Grammar clarifies that:

# The reason that keywords are test nodes instead of NAME is that using
# NAME results in an ambiguity. ast.c makes sure it's a NAME.
argument: test [comp_for] | test '=' test

The ambiguity is this: if I have

foo(a, b = 2)

and have parsed it up to

foo(a,

then, if I get b, should I enter the test clause (for the left
alternative) or the right clause? With the grammar being as stated,
it can be parsed as

argument: test ([comp_for] | '=' test)

so that parsing always starts with a test. Afterwards, I either get a
'=', indicating a keyword argument, or not: the '=' is not in the FIRST
set of comp_for, so there is no ambiguity here.

HTH,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Default paranmeter for packed values

2010-04-19 Thread Terry Reedy

On 4/18/2010 7:23 PM, Xavier Ho wrote:

G'day Pythoneers,

I ran into a strange problem today: why does Python not allow default
paranmeters for packed arguments in a function def?


 def test(a = 1, b = (2, 3)):

... print a, b
...

 test()

1 (2, 3)


 def t(a, *b = (3, 4)):

   File input, line 1
 def t(a, *b = (3, 4)):
 ^
SyntaxError: invalid syntax

What was the rationale behind this design?


To reword what G. Ewing said, because t(3) causes b to be empty. In 
actually use cases, I believe that that is usually the appropriate thing 
to do.


tjr

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


Re: About the grammar

2010-04-19 Thread franck
Thank you for this very clear (and quick) explanation!  :-)

Cheers,
Franck

On 19 avr, 08:58, Martin v. Loewis mar...@v.loewis.de wrote:
 # The reason that keywords are test nodes instead of NAME is that using
 # NAME results in an ambiguity. ast.c makes sure it's a NAME.
 argument: test [comp_for] | test '=' test
[...]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About the grammar

2010-04-19 Thread franck
      argument: ... | test '=' test
 Where are you finding that?

This comes from Python-2.6/Grammar/Grammar in the source distribution.

 This tells you that keyword arguments cannot have keywords that aren't
 identifiers:

  sum(1=2)

   File stdin, line 1
 SyntaxError: keyword can't be an expression

Sure! So my surprise.

But Martin did provide a very good explanation that this form in the
grammar actually allows to avoid an ambiguity.

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


Re: Operations on sparse matrices

2010-04-19 Thread pp
I tried csr_matrix.dot(A,N) where A and N are two sparse matrices.
 is it correct for multiplication of two sparse matrices ?
I still do not now how to perform matrix inversion for a  sparse
matrix. Can anyone please help.

Thanks!!

On Apr 19, 12:03 am, pp parul.pande...@gmail.com wrote:
 I am currently dealing with sparse matrices and have doubts on whether
 we can use
 1.) dot (for matrix multiplication) and inv (inverse) operations of
 numpy on sparse matrices of CSR format.

 I initially constructed my sparse matrix using COO format and then
 converted it to CSR format now I want to know whether normal inverse
 and matrix multiplications work with sparse csr matrices.

 Also can these operations be applied directly to csr matrices

 Thanks a lot

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


installing debug symbols

2010-04-19 Thread sanam singh

hi,
i am using ubuntu 9.10. it comes with preinstalled python2.6 having no debug 
symbols.How can i add debug symbols to it. Secondly i cant afford to install a 
fresh python version using OPT=-g way. Please tell me how can i add symbols to 
existing python2.6.
The error that i get in gdb when i attach a pid to it is :
Loaded symbols for /usr/lib/python2.6/dist-packages/numpy/random/mtrand.so
Reading symbols from /usr/lib/python2.6/lib-dynload/_ctypes.so...Reading 
symbols from /usr/lib/debug/usr/lib/python2.6/lib-dynload/_ctypes.so...done.
(no debugging symbols found)...done.
Loaded symbols for /usr/lib/python2.6/lib-dynload/_ctypes.so
Reading symbols from /usr/lib/python2.6/lib-dynload/cmath.so...Reading symbols 
from /usr/lib/debug/usr/lib/python2.6/lib-dynload/cmath.so...done.
(no debugging symbols found)...done.
Loaded symbols for /usr/lib/python2.6/lib-dynload/cmath.so
0xb78a5422 in __kernel_vsyscall ()

Thanks in advance.
  
_
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
https://signup.live.com/signup.aspx?id=60969-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help req debugging python and c together

2010-04-19 Thread CHEN Guang
Hi,
I am working in gnuradio compiler. I need some help in debugging python and c 
together.
By this i mean that i have written some blocks in c that are connected 
together using python. So i need to debug
( breakpoints ect ) python such that when a specific c block is called at the 
back end  (in python script ) the 
debugger takes me into the c code and after that switches back to python and 
so on.

Thanks in advance.
Regards,
Sanam
 
PythoidC ( http://pythoidc.googlecode.com or http://pythoidc.sf.net ) is a C 
language tool for Python, C code and Python code coexist in the same IDE or 
even the same file, thus avoids most of the switches in debugging python and c 
together.
 -- 
http://mail.python.org/mailman/listinfo/python-list


Re: Incorrect scope of list comprehension variables

2010-04-19 Thread Duncan Booth
Dave Angel da...@ieee.org wrote:

 2) In original C, and I think in C++, the lifetime of i lasted long 
 after the loop ended.
  for (int i=0; i limit; ++i)
  {
z += i;
  }
   i is still valid after this curly brace
 
 In C99, and at least in later C++, the scope of i ends with the curly, 
 as though there were another invisible pair of braces:
  {
  for (int i=0; i limit; ++i)
  {
z += i;
  }}
   i is no longer valid here
 

Leading to the wonderful header declaration:

#define for if(0);else for

which moves the entire for loop including the declaration inside another 
statement and therefore 'fixes' the variable scope for older compilers.

Ah, those were the days. :^)

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


ctypes return char array with null chars

2010-04-19 Thread chris cannady
Hi all,

I am passing a ctypes struct byref to a dll. When I get the struct
back, it looks like the char array in the struct was truncated at the
first null char. It should be 192 bytes long, but I know the 3rd
through 6th byte are null chars and the array was truncated right
before byte 3.

Is there any way to get the full array back including null chars?

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


Req. for feedback -- writings on error handling cleanup (Py3)

2010-04-19 Thread Alf P. Steinbach
After at least 3 false starts on my programming introduction's chapter 3, and 
some good and bad feedback from this group[1], I finally think the present 
chapter 3 approach is Good (enough).


So no, I haven't given up in this book project, even though 4 months to produce 
these chapter 3's first 30 pages or so might seem excessive!


This is a PDF document [03 - asd.pdf] at Google Docs, available via

  url: http://tinyurl.com/programmingbookP3

I've tried to take earlier feedback to heart. E.g. verbosity: earlier attempt's 
1+ page intro reduced to 1 line. And example selection: no scary math here.



Contents so far:

contents
3 [chapter title, undecided].
3.1 Error handling.
3.1.1 Error, failure, success (terminology).
3.1.2 The concept of exceptions.
3.1.3 Routine call hierarchies, call stack unwinding and stack traces.
3.1.4 Raising an exception / exception types / exception objects.
3.1.5 Handling an exception by using a try statement.
3.1.6 Interlude I: numerical input in a console program.
3.1.7 Exception translation and chained exceptions.
3.2 Cleanup handling.
3.2.1 Why automatic cleanup via object destruction (RAII) is ungood in Python.
3.2.2 Performing cleanup by using a finally clause (low level technique).
3.2.3 Performing cleanup by using a with statement.
/contents


Comments welcome!


Cheers,

- Alf

Notes:
[1] I'm posting this only to [comp.lang.python], for now seeking feedback mainly 
on the language aspects and general approach. Partially that's because, 
empirically, there is some risk of a flame war erupting in this group, and I 
don't want that spilling over into some other group. If/when the chapter's draft 
is complete I'll cross-post a request for feedback to [comp.programming], or 
perhaps post only to that group for the more pedagogical aspects.

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


Re: class instance customization

2010-04-19 Thread Jean-Michel Pichavant

Alexander wrote:

On 17.04.2010 18:32, Steven D'Aprano wrote:
  

On Sat, 17 Apr 2010 13:09:43 +0400, Alexander wrote:

  


Hi, list.

I've some nontrivial class implementation MyClass and its instance my:

my = MyClass(args)

MyClass uses in internals some variable which is not defined in MyClass
itself. I want to extend instance of MyClass at runtime defining this
variable and making new instance. It is like a class inheritance in a
static way

  
I'm afraid I don't understand what you are asking. MyClass uses a 
variable which is not defined in MyClass. Where is it defined? Is it a 
global variable?


What do you mean, like a class inheritance in a static way?

Perhaps you should give an example of what you want to happen.
  



Ok, I'll try to explain on the following example. Let's consider class
MyClass that holds one string and concatenate it with other not defined
in this class:

class MyClass(object):
def __init__(s): pass
def set(s, key):
s.__key = key
def __str__(s):
return s.__key + ' ' + s.__other
def new(s, value):
return SubClass(s, value)

The problem is how to implement class SubClass which inherits MyClass,
define new variable __other accessible from MyClass intance and with
working application:

a = MyClass()
a.set('key1')

b1 = a.new('value1')
b2 = a.new('value2')

print b1, , ,b2 # give 'key1 value1 , key1 value2'

a.set('key2')

print b1, ,, b2 # give 'key2 value1 , key2 value2'


  

Unfortunately I'm not sure you description clarifies anything.
My *guess* is that you would need a Factory class.

class Factory:  # this is a Factory class

class MyClass: # the class you actually need

redFactory = Factory('red')
blueFactory = Factory('blue')


ex1 = redFactory.new('value1') # use the factory to return an instance 
of MyClass initialized with the proper parameters

ex2 = blueFactory.new('value1')

print ex1
'red value1'
print ex2
'blue value1'

Is that want you want to do ? If so, I may elaborate a little more...

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


copy some files from IE temporary internet files

2010-04-19 Thread CHEN Guang
Hi friends,
I want to program Python to copy some video files (.flv) from the IE folder 
temporary internet files, but 
 
os.listdir('C:\\Documents and Settings\\Administrator\\Local 
Settings\\Temporary Internet Files') 
 
seemed unable to find any video file (although they really exist and can be 
manually copied with Windows explorer).
I googled and found that temporary internet files is not a normal folder. 
Will any friend tell me how to do this?
 
ChenGuang-- 
http://mail.python.org/mailman/listinfo/python-list


pyconfig.h

2010-04-19 Thread omnia neo
Hi All,

I am working on porting python on vxworks and hence was updating the PC
\pyconfig.h file for configurng python. As I am reading the file and
updating manually I come across lot many preprocessor directives which
I dont understand e.g. HAVE_NICE etc. May be this is standard
nomenclature and I am not aware of it.
My point and qwery is that how can I get info about all these
directives. I am perplexed to enable or disable any of them with half
knowledge.

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


Re: Python 2.6 SSL module: Fails on key file error, with Errno 336265225, without a key file.

2010-04-19 Thread Antoine Pitrou
Le Sun, 18 Apr 2010 22:37:30 -0700, John Nagle a écrit :
 
 The cert file is the same PEM file I use with M2Crypto, and it's derived
 from Firefox's cert file.
 
 Why am I getting a private key related error?  I'm not submitting a
 keyfile, just a cert file.

I'm not an expert but this is what the SSL doc says:

« The keyfile and certfile parameters specify optional files which 
contain a certificate to be used to identify the local side of the 
connection. »

From that, I understand that you need to specify both at the same time, 
and that one of them (probably the keyfile) needs to be a private key. 
Otherwise how would the local side identify itself?

Perhaps you are using the wrong parameters and looking for ca_certs 
instead:

« The ca_certs file contains a set of concatenated “certification 
authority” certificates, which are used to validate certificates passed 
from the other end of the connection. »


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


Re: installing debug symbols

2010-04-19 Thread shaunak saha
Hi,

You need to install the python debugging packages for your ubuntu version. I
guess its python-dbg

Regards,
Shaunak

2010/4/19 sanam singh sanamsi...@hotmail.com

  hi,
 i am using ubuntu 9.10. it comes with preinstalled python2.6 having no
 debug symbols.How can i add debug symbols to it. Secondly i cant afford to
 install a fresh python version using OPT=-g way. Please tell me how can i
 add symbols to existing python2.6.
 The error that i get in gdb when i attach a pid to it is :
 Loaded symbols for /usr/lib/python2.6/dist-packages/numpy/random/mtrand.so
 Reading symbols from /usr/lib/python2.6/lib-dynload/_ctypes.so...Reading
 symbols from /usr/lib/debug/usr/lib/python2.6/lib-dynload/_ctypes.so...done.
 (no debugging symbols found)...done.
 Loaded symbols for /usr/lib/python2.6/lib-dynload/_ctypes.so
 Reading symbols from /usr/lib/python2.6/lib-dynload/cmath.so...Reading
 symbols from /usr/lib/debug/usr/lib/python2.6/lib-dynload/cmath.so...done.
 (no debugging symbols found)...done.
 Loaded symbols for /usr/lib/python2.6/lib-dynload/cmath.so
 0xb78a5422 in __kernel_vsyscall ()

 Thanks in advance.

 --
 Hotmail: Trusted email with Microsoft’s powerful SPAM protection. Sign up
 now. https://signup.live.com/signup.aspx?id=60969

 ___
 ddd mailing list
 d...@gnu.org
 http://lists.gnu.org/mailman/listinfo/ddd


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


Re: (a==b) ? 'Yes' : 'No'

2010-04-19 Thread Dotan Cohen
On 30 March 2010 18:40, gentlestone tibor.b...@hotmail.com wrote:
 Hi, how can I write the popular C/JAVA syntax in Python?

 Java example:
    return (a==b) ? 'Yes' : 'No'

 My first idea is:
    return ('No','Yes')[bool(a==b)]

 Is there a more elegant/common python expression for this?


I'm a little late to the party, but I just saw this in Dive Into Python:
multiple = 1024 if a_kilobyte_is_1024_bytes else 1000

It's kind of sloppy as the condition is between the possible values,
but it works.

-- 
Dotan Cohen

http://bido.com
http://what-is-what.com

Please CC me if you want to be sure that I read your message. I do not
read all list mail.
-- 
http://mail.python.org/mailman/listinfo/python-list


default value in list comprehension

2010-04-19 Thread AlienBaby
Hi,

just a quick one,

Is it possible to achieve a default value in a list comprehension
where the if-clause is false?

Ie, something similar to:

[ a for a in b if something(a) else 'default' ]

the idea being that, rather than skip a value if the if-clause is
false, to place a default value at that position in the returned list
instead.

?

Thanks,


Matt.


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


Re: default value in list comprehension

2010-04-19 Thread eb303
On Apr 19, 2:20 pm, AlienBaby matt.j.war...@gmail.com wrote:
 Hi,

 just a quick one,

 Is it possible to achieve a default value in a list comprehension
 where the if-clause is false?

 Ie, something similar to:

 [ a for a in b if something(a) else 'default' ]

 the idea being that, rather than skip a value if the if-clause is
 false, to place a default value at that position in the returned list
 instead.

 ?

 Thanks,

 Matt.

[a if something(a) else 'default' for a in b]

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


Re: copy some files from IE temporary internet files

2010-04-19 Thread Tim Golden

On 19/04/2010 10:49, CHEN Guang wrote:

Hi friends,
I want to program Python to copy some video files (.flv) from the IE folder 
temporary internet files, but

os.listdir('C:\\Documents and Settings\\Administrator\\Local 
Settings\\Temporary Internet Files')

seemed unable to find any video file (although they really exist and can be 
manually copied with Windows explorer).
I googled and found that temporary internet files is not a normal folder. 
Will any friend tell me how to do this?


Have a look at the win32inet module from the pywin32 package

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


Re: default value in list comprehension

2010-04-19 Thread AlienBaby
On Apr 19, 1:23 pm, eb303 eric.brunel.pragma...@gmail.com wrote:
 On Apr 19, 2:20 pm, AlienBaby matt.j.war...@gmail.com wrote:





  Hi,

  just a quick one,

  Is it possible to achieve a default value in a list comprehension
  where the if-clause is false?

  Ie, something similar to:

  [ a for a in b if something(a) else 'default' ]

  the idea being that, rather than skip a value if the if-clause is
  false, to place a default value at that position in the returned list
  instead.

  ?

  Thanks,

  Matt.

 [a if something(a) else 'default' for a in b]

 HTH
  - Eric -- Hide quoted text -

 - Show quoted text -

Ahh.  Gotcha, thankyou :)
-- 
http://mail.python.org/mailman/listinfo/python-list


[pylint] why pylint wants only capitals identifiers?

2010-04-19 Thread Giacomo Boffi
i have this code

def example(a):
return lambda b: a+b+1

fun = example(10)
k_1 = fun(7)
...

and pylint tells me

[...]
C:  4: Invalid name fun (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C:  5: Invalid name k_1 (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
[...]

afaict, [A-Z_][A-Z0-9_]* identifiers should be used for constants, and
i don't think of fun or k_1 as constants... what's going on?

tia,
g
-- 
la lenza penzola
   -- PMF, in IHC
-- 
http://mail.python.org/mailman/listinfo/python-list


urllib2.urlopen taking way too much time

2010-04-19 Thread Phonethics Mobile Media
handler = urllib2.urlopen(req) is taking way too much time to retrieve
the URL. The same code using sockets in PHP doesn't delay this long.
I had 'Authorization':'Basic ' + base64.b64encode(username:password)
in my header though.
[ I didnt use HTTPPasswordMgr  HTTPPasswordMgrWithDefaultRealm
because I was unable to send headers with the example shown here :
http://docs.python.org/howto/urllib2.html#id6 ]

I have data = handler.readline() in a loop - this is an endless
network script (twitter streaming) so cant really wait for the entire
url contents to finish loading.

I had to socket.setdefaulttimeout to 30 to make it work.
Is it because python is getting chunks in high number of KBs ?

Python 2.6.2

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


RE: installing debug symbols

2010-04-19 Thread sanam singh

Hi,
Thanks for your reply. well the problem is that for gfb you need a python 
interpreter with debugging symbols, but unfortunately as i am using ubuntu9.10 
it has python2.6 without debugging symbols. now there are two ways out of 
it.first is that if we could add debug symbols to pre installed pyhon2.6.Second 
is that i have installed python3.1 with debugging symbols but it has been 
installed in usr/local/bin opposed to usr/bin where python2.6 is installed. now 
can we somehow tell ubuntu to use python3.1 instead of python2.6?
Thirdly, when i type python in command shell python2.6 opens.
Thanks in advance.
Regards,
Sanam

Date: Mon, 19 Apr 2010 16:53:47 +0530
From: reach2shauna...@gmail.com
To: sanamsi...@hotmail.com
CC: python-list@python.org; d...@gnu.org
Subject: Re: installing debug symbols

Hi,

You need to install the python debugging packages for your ubuntu version. I 
guess its python-dbg

Regards,
Shaunak

2010/4/19 sanam singh sanamsi...@hotmail.com






hi,
i am using ubuntu 9.10. it comes with preinstalled python2.6 having no debug 
symbols.How can i add debug symbols to it. Secondly i cant afford to install a 
fresh python version using OPT=-g way. Please tell me how can i add symbols to 
existing python2.6.

The error that i get in gdb when i attach a pid to it is :
Loaded symbols for /usr/lib/python2.6/dist-packages/numpy/random/mtrand.so
Reading symbols from /usr/lib/python2.6/lib-dynload/_ctypes.so...Reading 
symbols from /usr/lib/debug/usr/lib/python2.6/lib-dynload/_ctypes.so...done.

(no debugging symbols found)...done.
Loaded symbols for /usr/lib/python2.6/lib-dynload/_ctypes.so
Reading symbols from /usr/lib/python2.6/lib-dynload/cmath.so...Reading symbols 
from /usr/lib/debug/usr/lib/python2.6/lib-dynload/cmath.so...done.

(no debugging symbols found)...done.
Loaded symbols for /usr/lib/python2.6/lib-dynload/cmath.so
0xb78a5422 in __kernel_vsyscall ()

Thanks in advance.
  
Hotmail: Trusted email with Microsoft’s powerful SPAM protection. Sign up now.


___

ddd mailing list

d...@gnu.org

http://lists.gnu.org/mailman/listinfo/ddd



  
_
Hotmail: Powerful Free email with security by Microsoft.
https://signup.live.com/signup.aspx?id=60969-- 
http://mail.python.org/mailman/listinfo/python-list


[CfP] DLS'10

2010-04-19 Thread Pascal Costanza
Dynamic Languages Symposium 2010

October 18, 2010

Co-located with SPLASH (OOPSLA) 2010
In cooperation with ACM SIGPLAN
John Ascuaga's Nugget, Reno/Tahoe, Nevada, USA

http://www.dynamic-languages-symposium.org/dls-10/

* Call for papers *

The 6th Dynamic Languages Symposium (DLS) at the conference formerly
known as OOPSLA is a forum for discussion of dynamic languages, their
implementation and application. While mature dynamic languages
including Smalltalk, Lisp, Scheme, Self, Prolog, and APL continue to
grow and inspire new converts, a new generation of dynamic scripting
languages such as Python, Ruby, PHP, Tcl, and JavaScript are
successful
in a wide range of applications. DLS provides a place for researchers
and practitioners to come together and share their knowledge,
experience, and ideas for future research and development.

DLS 2010 invites high quality papers reporting original research,
innovative contributions or experience related to dynamic languages,
their implementation and application. Accepted Papers will be
published
in the ACM Digital Library.

Areas of interest include but are not limited to:

* Innovative language features and implementation techniques
* Development and platform support, tools
* Interesting applications
* Domain-oriented programming
* Very late binding, dynamic composition, and runtime adaptation
* Reflection and meta-programming
* Software evolution
* Language symbiosis and multi-paradigm languages
* Dynamic optimization
* Hardware support
* Experience reports and case studies
* Educational approaches and perspectives
* Object-oriented, aspect-oriented, and context-oriented programming

=== Submissions and proceedings ===

We invite original contributions that neither have been published
previously nor are under review by other refereed events or
publications. Research papers should describe work that advances the
current state of the art. Experience papers should be of broad
interest
and should describe insights gained from substantive practical
applications. The program committee will evaluate each contributed
paper based on its relevance, significance, clarity, and originality.

Accepted papers will be published in the ACM Digital Library.

Papers are to be submitted electronically at
http://www.easychair.org/conferences?conf=dls2010 in PDF format.
Submissions must not exceed 12 pages and need to use the ACM format,
templates for which can be found at
http://www.acm.org/sigs/pubs/proceed/template.html.

=== Important dates ===

Submission of papers:  June 1, 2010 (hard deadline)
Author notification:  July 15, 2010
Final versions due: August 13, 2010
DLS 2010:  October 18, 2010
SPLASH/OOPSLA 2010: October 17-21, 2010

=== Program chair ===

William Clinger, Northeastern University, Boston, Massachusetts, USA

=== Program committee ===

Robby Findler (Northwestern University)
Jeffrey S. Foster (University of Maryland)
Lars Thomas Hansen (Adobe Systems)
Charlotte Herzeel (University of Brussels)
S. Alexander Spoon (Google)
Eric Tanter (University of Chile)
Jan Vitek (Purdue University)
Alessandro Warth (Viewpoints Research Institute)

[to be completed]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [pylint] why pylint wants only capitals identifiers?

2010-04-19 Thread Alexandre Fayolle
top level variables in real code are often constants and pylint tries to help 
you get rid of global variables. 

---
frmsrcurl: 
http://compgroups.net/comp.lang.python/-pylint-why-pylint-wants-only-capitals-identifiers
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Write web apps in Python?

2010-04-19 Thread Bruno Desthuilliers

Gilles Ganault a écrit :

On Thu, 15 Apr 2010 12:41:56 +0200, Bruno Desthuilliers
bruno.42.desthuilli...@websiteburo.invalid wrote:
The PHP execution model (mostly based on CGI FWIW) tends to be a bit 
unpractical for non-trivial applications since you have to rebuild the 
whole world for each and any incoming request, while with a long-running 
process, you load all your libs, parse your config etc only once.


Apart from the ease of having the application run at all times, I'd be
curious to read about an application that was written in PHP and then
a long-running process and see if performance improved.


I'm not sure there's a way to do such a thing in PHP, at least in a way 
that wouldn't make the whole benchmark totally meaningless. And trying 
to compare a PHP app with a similar non-PHP would also be (mostly) 
meaningless.


Now there are a couple Symfony / Django benchmarks around (Symfony being 
probably the closest thing to Django in the PHP world). They are just as 
reliable as most benchmarks (that is, at best a rough indicator once you 
understand what's effectively being measured), but it seems that they 
confirm the empirical evidence that PHP is not well suited for such 
heavy OO frameworks.




Regardless, Python has an easier syntax, so AFAIC, that's already a
good enough reason to use this to write web apps.


Indeed !-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: default value in list comprehension

2010-04-19 Thread Bruno Desthuilliers

eb303 a écrit :

On Apr 19, 2:20 pm, AlienBaby matt.j.war...@gmail.com wrote:

Hi,

just a quick one,

Is it possible to achieve a default value in a list comprehension
where the if-clause is false?

Ie, something similar to:

[ a for a in b if something(a) else 'default' ]

the idea being that, rather than skip a value if the if-clause is
false, to place a default value at that position in the returned list
instead.

?

Thanks,

Matt.


[a if something(a) else 'default' for a in b]


Or you could have something taking a default argument and returning 
either it's argument (instead of True) or the default one (instead of 
False), and get rid of the if/else test in the list comp, ie:


def something(obj, default=False):
if whatever(obj):
   return obj
else:
   return default

results = [something(a, default=default) for a in b]

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


Re: installing debug symbols

2010-04-19 Thread shaunak saha
Change PATH and LD_LIBRARY_PATH variable to use /usr/local instead of /usr

2010/4/19 sanam singh sanamsi...@hotmail.com

  Hi,
 Thanks for your reply. well the problem is that for gfb you need a python
 interpreter with debugging symbols, but unfortunately as i am using
 ubuntu9.10 it has python2.6 without debugging symbols. now there are two
 ways out of it.first is that if we could add debug symbols to pre installed
 pyhon2.6.Second is that i have installed python3.1 with debugging symbols
 but it has been installed in usr/local/bin opposed to usr/bin where
 python2.6 is installed. now can we somehow tell ubuntu to use python3.1
 instead of python2.6?
 Thirdly, when i type python in command shell python2.6 opens.
 Thanks in advance.
 Regards,
 Sanam

 --
 Date: Mon, 19 Apr 2010 16:53:47 +0530
 From: reach2shauna...@gmail.com
 To: sanamsi...@hotmail.com
 CC: python-list@python.org; d...@gnu.org
 Subject: Re: installing debug symbols


 Hi,

 You need to install the python debugging packages for your ubuntu version.
 I guess its python-dbg

 Regards,
 Shaunak

 2010/4/19 sanam singh sanamsi...@hotmail.com

  hi,
 i am using ubuntu 9.10. it comes with preinstalled python2.6 having no
 debug symbols.How can i add debug symbols to it. Secondly i cant afford to
 install a fresh python version using OPT=-g way. Please tell me how can i
 add symbols to existing python2.6.
 The error that i get in gdb when i attach a pid to it is :
 Loaded symbols for /usr/lib/python2.6/dist-packages/numpy/random/mtrand.so
 Reading symbols from /usr/lib/python2.6/lib-dynload/_ctypes.so...Reading
 symbols from /usr/lib/debug/usr/lib/python2.6/lib-dynload/_ctypes.so...done.
 (no debugging symbols found)...done.
 Loaded symbols for /usr/lib/python2.6/lib-dynload/_ctypes.so
 Reading symbols from /usr/lib/python2.6/lib-dynload/cmath.so...Reading
 symbols from /usr/lib/debug/usr/lib/python2.6/lib-dynload/cmath.so...done.
 (no debugging symbols found)...done.
 Loaded symbols for /usr/lib/python2.6/lib-dynload/cmath.so
 0xb78a5422 in __kernel_vsyscall ()

 Thanks in advance.

 --
 Hotmail: Trusted email with Microsoft’s powerful SPAM protection. Sign up
 now. https://signup.live.com/signup.aspx?id=60969

 ___
 ddd mailing list
 d...@gnu.org
 http://lists.gnu.org/mailman/listinfo/ddd



 --
 Hotmail: Powerful Free email with security by Microsoft. Get it 
 now.https://signup.live.com/signup.aspx?id=60969

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


extra room in Paris in your are stuck at the airport

2010-04-19 Thread Jean Daniel
Hello,

I live in Paris, my roommate and I would gladly host a poor soul
blocked at the airport due to the ash cloud.

See me for details,

Cheers,


PS: disambiguation: talking about real physical cloud here... :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [pylint] why pylint wants only capitals identifiers?

2010-04-19 Thread Jean-Michel Pichavant

Giacomo Boffi wrote:

i have this code

def example(a):
return lambda b: a+b+1

fun = example(10)
k_1 = fun(7)
...

and pylint tells me

[...]
C:  4: Invalid name fun (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C:  5: Invalid name k_1 (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
[...]

afaict, [A-Z_][A-Z0-9_]* identifiers should be used for constants, and
i don't think of fun or k_1 as constants... what's going on?

tia,
g
  
Pylint default rules need some tuning, it's highly configurable for that 
purpose.
Some ppl like to think 'module variables' are constants thus should be 
upper case. If you disagree with that statement like I do, you can 
simply rewrite the regexp for module variables.


However, given you example, you should not insert code execution at you 
module level, unless it's required only at the module import. I dont 
know what is your module purpose but I bet it has no legitimate 
attribute 'fun'.


JM


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


Is it better to extend a class, or do something repetitious in the main part of a program?

2010-04-19 Thread J
First, before I get farther,

Is there a way for the logging module to natively handle lists and
dict objects when logging?

e.g. take this {'key1':'val1','key2':'val2'} and have it logged like this:

INFO: key1: val1
INFO: key2: val2

If I pass the dict or list directly to the logger, it is logged the
same as if you simply did this:

mydict={1:1, 2:2}
mylist=[1,2,3]

print mydict
print mylist

 {1:1,2:2}
 [1,2,3]

It came up that I wanted to have logging present command line options
from optparse if the log level was set to debug...  so they'd look
something like this in the output:

debug: True
sleep_time: 30
log_file: /tmp/testlog

So the options I've managed to work out are to either parse the list
or dict object item by item and feed those items one at a time into
the logger:

for i in mylist:
logging.info(i)

Or to extend the StreamHandler class to handle this by creating a new
report.msg...

Then the discussion came up: which is better?  To parse a dictionary
or list in the main code and pass each item to the logger one at a
time, or to extend the logger to handle it natively?

Any thoughts on which is the more proper way to handle cases like this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ctypes return char array with null chars

2010-04-19 Thread Mark Tolonen


chris cannady booo...@gmail.com wrote in message 
news:b103e85a-05d5-4195-a18f-bd143e9f5...@b33g2000yqc.googlegroups.com...

Hi all,

I am passing a ctypes struct byref to a dll. When I get the struct
back, it looks like the char array in the struct was truncated at the
first null char. It should be 192 bytes long, but I know the 3rd
through 6th byte are null chars and the array was truncated right
before byte 3.

Is there any way to get the full array back including null chars?

Thanks


It could depend on how your struct is declared.  Maybe this demo will help?

x=(c_char*10)()
x
   __main__.c_char_Array_10 object at 0x00A049E0
x.raw
   '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
x.value
   ''

'value' prints it is a string, stopping at the first null.  'raw' dumps the 
whole array.


-Mark


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


Re: class instance customization

2010-04-19 Thread Alexander
On 18.04.2010 13:23, Steven D'Aprano wrote:
 On Sat, 17 Apr 2010 19:55:44 +0400, Alexander wrote:
  
   
 Ok, I'll try to explain on the following example. Let's consider class
 MyClass that holds one string and concatenate it with other not defined
 in this class:
 
 [...]
   
 and with working application:

 a = MyClass()
 a.set('key1')

 b1 = a.new('value1')
 b2 = a.new('value2')

 print b1, , ,b2 # give 'key1 value1 , key1 value2'

 a.set('key2')

 print b1, ,, b2 # give 'key2 value1 , key2 value2'
 
 Looking at your design, I can't see any reason for SubClass to be a 
 subclass of MyClass. It doesn't inherit any behaviour, and the 
 constructor takes completely different arguments. Why make it a Subclass?
   
It was a very simple example that express the crux of my question. There
isn't any sense discuss design on it. In real implementation SubClass
has almost the same functionality and methods as MyClass, the difference
only in a state variable (one instance has one state and second the
other, see example below).
 MyClass is dangerous: creating an instance doesn't fully initialise the 
 instance, it leaves it in a half-initialised state that can cause 
 exceptions from simple operations like:

 instance = MyClass()
 print instance

 This is very bad design.
   
This actualy depends on practical implementation of class. There could
be a checkup in __str__() member for presence of variable in instance
and result of each evaluation of instance.__str__() could be a valid:

class MyClass(object):
def __init__(s):
s.__default = 'value3'
def set(s, key):
s.__key = key
def __str__(s):
if '__other' in s.__dict__:
return s.__key + ' ' + s.__other
else:
return s.__key + ' ' + s.__default
def new(s, value):
return SubClass(s, value)


Assume MyClass implementation is already given and SubClass have to be
implemented in some way.


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


Re: Can someone please make it more pythonic or better?

2010-04-19 Thread J Kenneth King
Oltmans rolf.oltm...@gmail.com writes:

 Greetings Python superstars,

 I've a directory structure like following

 tests /
   __init__.py
   testfile.py

 testfile.py contains following code

 import unittest

 class Calculator(unittest.TestCase):
 def test_add(self):
 print 'just add'
 def test_divide(self):
 print 'diviide'
 def test_multiply(self):
 print 'mul'


 class Car(unittest.TestCase):
 def test_start(self):
 print 'start'
 def test_move_right(self):
 print 'move right'
 def test_move_left(self):
 print 'move left'
 def test_stop(self):
 print 'stop'


 Now give the following user-input I want to get all test-names.
 user-input = tests.testfile (get all test-names from all
 unittest.TestCase derived classes in test.testfile)
 user-input = tests.testfile.Car (get all test-names from the Car
 class)
 user-input = tests.testfile.Cacr.test_stop

 and I'm doing it this the following way and I really think there has
 to be more readable, more pythonic and more possibly short way to do
 it

 import unittest
 import sys
 import inspect

 def get_test_names(full_name,module):
 name = full_name.split('.')
 loader = unittest.TestLoader()
 if len(name) == 4:
 return full_name
 elif len(name) == 3:
 exec from %s.%s import %s %(module,name[1],name[2])
 return loader.getTestCaseNames(eval(name[2]))
 elif len(name) == 2:
 exec 'from %s import %s' % (module,name[1])
 tests = []
 for _name, obj in inspect.getmembers(sys.modules[full_name]):
 if inspect.isclass(obj) and
 issubclass(obj,unittest.TestCase):
 exec from %s.%s import %s %
 (module,name[1],obj.__name__)
 tests.append(loader.getTestCaseNames(obj))
 return tests



 if __name__ == __main__:
 input = tests.testfile
 module = input.split('.')[0]
 _tests = get_test_names(input,module)
 print _tests


 So guys, can you kindly point me to a more Pythonic, more readable and
 possible more short way to acheive this? I will really appreciate any
 help. Many thanks in advance.

First of all, exec is bad if it's going to be processing user input.

You might want to:

 help(__import__)

It will give you an idea on how to hook into python's import machinery
for tasks such as this.

You could also modify the function's arglist to remove the
string-splitting you're doing.  Those magic numbers stick out a bit.
One can understand what they're for after reading the code in this case,
but it's not quite necessary if you make a keyword argument for package
names you can pass into the 'fromlist' argument in __import__.

ie:

def get_test_names(module_name, packagelist=[]):
...

hth,

j_king


 Best regards,
 Oltmans
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [pylint] why pylint wants only capitals identifiers?

2010-04-19 Thread Giacomo Boffi
Jean-Michel Pichavant jeanmic...@sequans.com writes:

 Giacomo Boffi wrote:
 i have this code

 def example(a):
 return lambda b: a+b+1

 fun = example(10)
 k_1 = fun(7)
 ...

 and pylint tells me

 [...]
 C:  4: Invalid name fun (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
 C:  5: Invalid name k_1 (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
 [...]
 g

 Pylint default rules need some tuning

ok, but maybe it's not my specific problem (see below)

 However, given you example, you should not insert code execution at
 you module level, unless it's required only at the module import. I
 dont know what is your module

module? this was not well specified in my OP, but i'd rather speak of
a script instead of a module...

maybe should i use the

if __name__ == __main__:
main()

idiom to keep happy my pylint? oh, let's do it... it should be easy
isn't it?

thanks,
g
-- 
 I wish we'd come to our senses and see there is no truth
 In those who promote the confusion for this ever changing mood.
(people get ready people get ready people get ready people get ready)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [pylint] why pylint wants only capitals identifiers?

2010-04-19 Thread Giacomo Boffi
Giacomo Boffi giacomo.bo...@polimi.it writes:

 However, given you example, you should not insert code execution at
 you module level, unless it's required only at the module import. I
 dont know what is your module

 module? this was not well specified in my OP, but i'd rather speak of
 a script instead of a module...

 maybe should i use the

 if __name__ == __main__:
 main()

 idiom to keep happy my pylint? oh, let's do it... it should be easy
 isn't it?

well, it's not so easy... pylint complains (correctly) about too many
local variables in main(), and about other things for different
adjustments i tried

i think i will put some variable at top level, CAPITALIZED, with the
intention of making evident that those values are the data of the
problem, as well as other quantities that are computed once from base
data, and then use these capitalized global variables inside my main
function --- tonight, at home

thank you again,
g
-- 
l'amore e' un sentimento a senso unico. a volte una via comincia dove
finisce un'altra e viceversa   -- Caldana, in IFQ
-- 
http://mail.python.org/mailman/listinfo/python-list


Can this be done simpler ?

2010-04-19 Thread Stef Mientki
hello,

I want to use Python to give users the possibility to analyze data and
create their custom reports.
So I want a very simple language definition for the user, like :
- the script must be case-insensitive
- user-words are automatically translated into function names
- users strings, should be entered without the quotes, so these strings will
be defined as names

Now the code below seems to fulfill these wishes (in real life, the number
of dummy procedures is about 40),
but I always wonder if there's an easier way to achieve the same effect.

thanks,
Stef Mientki

def _Meting ( Nr, Test, Subschaal ) :

here the real calculation will be done

global Result
Result += str ( Nr ) + ': ' + Test + '/' + Subschaal + '\n'

# Dummy procedures to add the extra argument Nr
def _Meting_1 ( *args, **kwargs ) :
_Meting ( 1, *args, **kwargs )

def _Meting_2 ( *args, **kwargs ) :
_Meting ( 2, *args, **kwargs )
# end of dummy procedures

# These are names definied by the user, retrieved from a database
Meting_Namen = {}
Meting_Namen [1] = 'Voormeting'
Meting_Namen [2] = 'Nameting'

# Make the user definied names available in the current namespace
for Meting in Meting_Namen :
Name = Meting_Namen [ Meting ].lower ()   # 'voormeting'
exec ( Name + '= _Meting_' + str ( Meting ) )

# Another set of strings should be available as names (also retrieved from a
database)
test1 = 'Test1'
fat = 'Fat'

# Storage for the results
Result = ''

# Script entered by the user
Code = Voormeting ( Test1, fat )

# execute the user script in the current namespace  (make code
case-insensitive)
exec ( Code.lower () )

# for test print the result
print Result
-- 
http://mail.python.org/mailman/listinfo/python-list


PLEASE HELP--Button images refuse to show.

2010-04-19 Thread Barrett
I have been fighting the same bug for weeks now with zero success: I
am trying to get images to come up on my buttons, but they are way too
small. Regardless of whether I used my old Python 2.5.1 or now 2.6.5,
the following code:


'''Minesweeper.'''

from Tkinter import *
#from PIL import Image
import Tkinter as tk
#import PIL as pil
import random
#import glob, os

BEGINNER = 1
INTERMEDIATE = 2
EXPERT = 3

OFFSET = 2

BUTTON_SIZE = 2

class Board(Frame, object):
def __init__(self, master, difficulty, photo):
Frame.__init__(self, master)
if difficulty == BEGINNER:
self.x = 9
self.y = 9
self.mines = 10
elif difficulty == INTERMEDIATE:
self.x = 16
self.y = 16
self.mines = 40
elif difficulty == EXPERT:
self.x = 30
self.y = 16
self.mines = 99

self.grid()
self.photo = photo
self.create_widgets()

def create_widgets(self):
#Create the grid.
self.square = []
self.isAMine = []
self.selected = []
for i in range(self.x):
squareColumn = []
mineColumn = []
selectedColumn = []
for j in range(self.y):
squareColumn.append(Button(self, width = 3, height =
2,\
   padx = -1, pady = -1))
squareColumn[j].grid(row = j + OFFSET, column = i)
mineColumn.append(False)
selectedColumn.append(False)
self.square.append(squareColumn)
self.isAMine.append(mineColumn)
self.selected.append(selectedColumn)

#Plant the mines.
print 'Dimensions:', self.x, self.y
for i in range(self.mines):
mineSquare = random.randrange(self.x * self.y)
mine_y = mineSquare / self.x
mine_x = mineSquare % self.x
self.isAMine[mine_x][mine_y] = True
self.square[mine_x][mine_y]['text'] = 'X' #temp line;
shows mines
#photo = tk.PhotoImage(file=1.gif)
#self.square[mine_x][mine_y]['image'] = photo #temp line;
shows mines


for i in range(self.y):
for j in range(self.x):
self.square[j][i]['command'] = lambda x=j, y=i:
self.hit(x, y)

#Runs when a button (square) is clicked.
def hit(self, x, y):
self.selected[x][y] = True
self.square[x][y].config(relief=SUNKEN)

#print x, y
if self.isAMine[x][y]:
print 'Mine found.  Location:', x, y
else:
#Look at all eight neighbors and see if they are mines.
#x0, etc. avoid looking off the edge of the map.
adjMines = 0
if (x  0 and y  0) and self.isAMine[x-1][y-1]: #NW
adjMines+=1
if y  0 and self.isAMine[x][y-1]: #N
adjMines+=1
if (x  self.x-1 and y  0) and self.isAMine[x+1][y-1]:
#NE
adjMines+=1
if x  0 and self.isAMine[x-1][y]: #W
adjMines+=1
if x  self.x-1 and self.isAMine[x+1][y]: #E
adjMines+=1
if (x  0 and y  self.y-1) and self.isAMine[x-1][y+1]:
#SW
adjMines+=1
if y  self.y-1 and self.isAMine[x][y+1]: #S
adjMines+=1
if (x  self.x-1 and y  self.y-1) and\
   self.isAMine[x+1][y+1]: #SE
adjMines+=1

if adjMines != 0 and adjMines  3:
self.square[x][y]['text'] = ''
self.square[x][y]['image'] = self.photo[adjMines]

elif adjMines0: #temp line until the pix are ready
self.square[x][y]['text'] = adjMines

else: #adjMines == 0
#If none of the adjacent squares have mines, it is
safe to hit
#them all.  Just like the official game, this game
does
#precisely that.
if (x  0 and y  0) and not self.selected[x-1][y-1]:
Board.hit(self, x-1, y-1) #NW
if y  0 and not self.selected[x][y-1]: #N
Board.hit(self, x, y-1)
if (x  self.x-1 and y  0) and not self.selected[x+1]
[y-1]: #NE
Board.hit(self, x+1, y-1)
if x  0 and not self.selected[x-1][y]: #W
Board.hit(self, x-1, y)
if x  self.x-1 and not self.selected[x+1][y]: #E
Board.hit(self, x+1, y)
if (x  0 and y  self.y-1) and not self.selected[x-1]
[y+1]: #SW
Board.hit(self, x-1, y+1)
if y  self.y-1 and not self.selected[x][y+1]: #S
Board.hit(self, x, y+1)
if (x  self.x-1 and y  self.y-1) and\
   not self.selected[x+1][y+1]:
Board.hit(self, x+1, y+1) #SE

self.square[x][y]['command'] = 

Re: Python 2.6 SSL module: Fails on key file error, with Errno 336265225, without a key file.

2010-04-19 Thread John Nagle

Antoine Pitrou wrote:
Perhaps you are using the wrong parameters and looking for ca_certs 
instead:


   That's right.  Thanks.

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


Re: [pylint] why pylint wants only capitals identifiers?

2010-04-19 Thread Jean-Michel Pichavant

Giacomo Boffi wrote:

Jean-Michel Pichavant jeanmic...@sequans.com writes:

  

Giacomo Boffi wrote:


i have this code

def example(a):
return lambda b: a+b+1

fun = example(10)
k_1 = fun(7)
...

and pylint tells me

[...]
C:  4: Invalid name fun (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C:  5: Invalid name k_1 (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
[...]
g

  

Pylint default rules need some tuning



ok, but maybe it's not my specific problem (see below)

  

However, given you example, you should not insert code execution at
you module level, unless it's required only at the module import. I
dont know what is your module



module? this was not well specified in my OP, but i'd rather speak of
a script instead of a module...
  


If by script you mean quick-and-dirty, then why bother running pylint 
on it ? Sounds out of topic to me.


But if you still care about how correctly structured you script should 
be, then it should be written almost like a module.


- do not write executable code at the module level
- if a function needs an information, it should ask for it as a 
parameter, not using a de-scoped variable (aka global variables)
- if a function ask for too many parameters, then it may ask for few 
objects instead (e.g. plot(x,y,z) = plot(point), poor example though, 3 
paramaters are acceptable)
- it's better if your script can be imported in a separate file and 
tested there


the list could contain many more items, and the more item you implement 
the closer to a module you get.


JM


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


ssl module doesn't validate that domain of certificate is correct

2010-04-19 Thread John Nagle

   I'm converting some code from M2Crypto to the new ssl module, and
I've found what looks like a security hole.  The ssl module will
validate the certificate chain, but it doesn't check that the certificate
is valid for the domain.

   Here's the basic code:

sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock = ssl.wrap_socket(sk, ca_certs=certfile,
cert_reqs=ssl.CERT_REQUIRED)
sock.connect((domain,443))  
cert = sock.getpeercert()
print('SSL cert for %s:' % (domain,))
for fieldname in cert :
print('%s = %s' % (fieldname, cert[fieldname]))

Note that I'm sending a CA cert list and am specifying CERT_REQUIRED,
so I should get a proper cert check.

Now let's try a host that presents the wrong SSL cert. Try, in
a browser,

https://www.countrysidecabinetry.com

You'll get an error.  But the ssl module is happy with this cert:

SSL cert for www.countrysidecabinetry.com:
notAfter = Dec  8 23:30:48 2010 GMT
subject = ((('serialNumber', u'E5gMXaDjnqfFPID2KNdLTVNEE6PjtqOr'),), 
(('countryName', u'US'),), (('organizationName', u'customla
serengravings.com'),), (('organizationalUnitName', u'GT57631608'),), 
(('organizationalUnitName', u'See www.rapidssl.com/resources/cp
s (c)09'),), (('organizationalUnitName', u'Domain Control Validated - 
RapidSSL(R)'),), (('commonName', u'customlaserengravings.com')

,))

Note that the cert is for customlaserengravings.com, but is being
presented by countrysidecabinetry.com.  Fail.

When I try this with M2Crypto, I get an SSL.Checker.WrongHost exception.
That's what should happen.

John Nagle

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


Tkinter scrollbar background color doesn't work

2010-04-19 Thread KL
Tkinter scrollbar widget's background and relief options seem not
work.

The below is the codes I tried and the python/tk information:
===

ActivePython 2.6.4.8 (ActiveState Software Inc.) based on
Python 2.6.4 (r264:75706, Nov  3 2009, 13:23:17) [MSC v.1500 32 bit
(Intel)] on
win32
 from Tkinter import *
 r=Tk()
 s=Scrollbar(r,bg=#000)
 s.grid()
 s['activebackground'] = #000
 s['relief'] = sunken

 TkVersion
8.5
 import sys
 sys.version
'2.6.4 (r264:75706, Nov  3 2009, 13:23:17) [MSC v.1500 32 bit
(Intel)]'

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


Re: ssl module doesn't validate that domain of certificate is correct

2010-04-19 Thread exarkun

On 04:51 pm, na...@animats.com wrote:

   I'm converting some code from M2Crypto to the new ssl module, and
I've found what looks like a security hole.  The ssl module will
validate the certificate chain, but it doesn't check that the 
certificate

is valid for the domain.

   Here's the basic code:

sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock = ssl.wrap_socket(sk, ca_certs=certfile,
cert_reqs=ssl.CERT_REQUIRED)
sock.connect((domain,443))
cert = sock.getpeercert()
print('SSL cert for %s:' % (domain,))
for fieldname in cert :
print('%s = %s' % (fieldname, cert[fieldname]))

Note that I'm sending a CA cert list and am specifying CERT_REQUIRED,
so I should get a proper cert check.

Now let's try a host that presents the wrong SSL cert. Try, in
a browser,

https://www.countrysidecabinetry.com

You'll get an error.  But the ssl module is happy with this cert:

SSL cert for www.countrysidecabinetry.com:
notAfter = Dec  8 23:30:48 2010 GMT
subject = ((('serialNumber', 
u'E5gMXaDjnqfFPID2KNdLTVNEE6PjtqOr'),), (('countryName', u'US'),), 
(('organizationName', u'customla
serengravings.com'),), (('organizationalUnitName', u'GT57631608'),), 
(('organizationalUnitName', u'See www.rapidssl.com/resources/cp
s (c)09'),), (('organizationalUnitName', u'Domain Control Validated - 
RapidSSL(R)'),), (('commonName', u'customlaserengravings.com')

,))

Note that the cert is for customlaserengravings.com, but is being
presented by countrysidecabinetry.com.  Fail.

When I try this with M2Crypto, I get an SSL.Checker.WrongHost 
exception.

That's what should happen.


It's a bit debatable.  There probably should be a way to make this 
happen, but it's far from clear that it's the only correct behavior. 
And, as it turns out, there is a way to make it happen - call 
getpeercert() and perform the check yourself. ;)


Here's some related discussion for an equivalent API in a different 
module:


 http://twistedmatrix.com/trac/ticket/4023

At the very least, the documentation for this should be very clear about 
what is and is not being checked.


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


Re: UnicodeEncodeError during repr()

2010-04-19 Thread gb345
In hqguja$t...@online.de Martin v. Loewis mar...@v.loewis.de writes:

 Do I need to do something especial to get repr to work strictly
 with unicode?

Yes, you need to switch to Python 3 :-)

 Or should __repr__ *always* return bytes rather than unicode?

In Python 2.x: yes.

 What about __str__ ?

Likewise.

 If both of these are supposed to return bytes,
 then what method should I use to define the unicode representation
 for instances of a class?

__unicode__.

Thanks!

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


scipy error undefined symbol: lsame_

2010-04-19 Thread gerardob

I installed scipy (and all the required libraries) and the following error
appears when i tried run a simple example which uses the optimize package of
scipy. I tried also numpy alone and it works ( at least for printing
numpy.array([10,20,10])) 

error:

Traceback (most recent call last):
  File main_test.py, line 2, in module
from scipy import optimize
  File
/home/gberbeglia/python/Python-2.6.5/lib/python2.6/site-packages/scipy/optimize/__init__.py,
line 11, in module
from lbfgsb import fmin_l_bfgs_b
  File
/home/gberbeglia/python/Python-2.6.5/lib/python2.6/site-packages/scipy/optimize/lbfgsb.py,
line 30, in module
import _lbfgsb
ImportError:
/home/gberbeglia/python/Python-2.6.5/lib/python2.6/site-packages/scipy/optimize/_lbfgsb.so:
undefined symbol: lsame_
gberbeg...@actarus:~/python/mycodes

Any ideas on how to solve this problem? Thanks.

PS: the example is below:

import numpy
from scipy import optimize

a = numpy.array([10,20,10])
print a

def f_(x):
return x*x

x,f,d = optimize.fmin_l_bfgs_b(f_,[0.1],fprime=None, approx_grad = True,
bounds = [(-1,1)], iprint=30, maxfun=15)


-- 
View this message in context: 
http://old.nabble.com/scipy-error-undefined-symbol%3A-lsame_-tp28287715p28287715.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: ssl module doesn't validate that domain of certificate is correct

2010-04-19 Thread John Nagle

exar...@twistedmatrix.com wrote:

On 04:51 pm, na...@animats.com wrote:

   I'm converting some code from M2Crypto to the new ssl module, and
I've found what looks like a security hole.  The ssl module will
validate the certificate chain, but it doesn't check that the certificate
is valid for the domain.


...
It's a bit debatable.  There probably should be a way to make this 
happen, but it's far from clear that it's the only correct behavior. 
And, as it turns out, there is a way to make it happen - call 
getpeercert() and perform the check yourself. ;)


   Checking it yourself is non-trivial. The checking code has to
understand DNS wildcards and additional domains in cert extensions.
The SSL module doesn't seem to let you read all the cert extensions,
(in particular, you don't get certificatePolicies, so you can't
tell if a cert is an extended validation cert) but it looks like
you do get the subjectAltName fields present in the extensions, like this:

  subjectAltName = (('DNS', 'www.chapinfurniture.com'),
('DNS', 'chapinfurniture.com')))

   So it's at least possible to check.  Almost.

   (DNS wildcards look like this: *.example.com.  It's also possible
to have *.*.example.com.  However, no DNS wildcard cert should cover
more than one second-level domain (huge security hole if you allow that)
and no extended validation cert should have a wildcard.)

   There may also be issues with internationalized domain names.

   It's very bad for the ssl module to both ignore this check and
not have that mentioned prominently in the documentation.  This is
a security-critical function.  Somewhere, there's a Python program that
can be exploited due to this bug.

   Here's a comparison of what M2Crypto and the SSL module return, for
verisign.com, which uses most cert features.

Trying domain www.verisign.com
Host: www.verisign.com Port: 443

Info from M2Crypto: module:

Cipher = DHE-RSA-AES256-SHA
   Subject info: [('CN', 'verisign.com'),
('OU', 'production Security Services  '),
('O', 'VeriSign, Inc.'),
('streetAddress', '487 East Middlefield Road'),
('L', 'Mountain View'),
('ST', 'California'),
('postalCode', '94043'),
('C', 'US'),
('serialNumber', '2497886'),
('2.5.4.15', 'V1.0, Clause 5.(b)'),
('jurisdictionOfIncorporationStateOrProvinceName', 'Delaware'),
('jurisdictionOfIncorporationCountryName', 'US')]

  Certificate has 10 extensions.
Extension #0: subjectAltName = DNS:verisign.com, DNS:www.verisign.com, 
DNS:verisign.mobi, DNS:www.verisign.mobi, DNS:verisign.eu, DN

S:www.verisign.eu
Extension #1: basicConstraints = CA:FALSE
Extension #2: subjectKeyIdentifier = 
0F:75:C5:F7:06:11:CE:74:FC:5F:DA:B6:2A:53:CE:39:1C:D6:7D:19

Extension #3: keyUsage = Digital Signature, Key Encipherment
Extension #4: crlDistributionPoints = 
URI:http://EVIntl-crl.verisign.com/EVIntl2006.crl


Extension #5: certificatePolicies = Policy: 2.16.840.1.113733.1.7.23.6
  CPS: https://www.verisign.com/rpa

Extension #6: extendedKeyUsage = TLS Web Server Authentication, TLS Web Client 
Authentication, Netscape Server Gated Crypto
Extension #7: authorityKeyIdentifier = 
keyid:4E:43:C8:1D:76:EF:37:53:7A:4F:F2:58:6F:94:F3:38:E2:D5:BD:DF


Extension #8: authorityInfoAccess = OCSP - URI:http://EVIntl-ocsp.verisign.com
CA Issuers - URI:http://EVIntl-aia.verisign.com/EVIntl2006.cer

Extension #9: UNDEF = None

Info from ssl module:

SSL cert for www.verisign.com:
notAfter = Apr  2 23:59:59 2012 GMT
subject = ((('1.3.6.1.4.1.311.60.2.1.3', u'US'),),
(('1.3.6.1.4.1.311.60.2.1.2', u'Delaware'),),
(('2.5.4.15', u'V1.0, Clause 5.(b)'),),
(('serialNumber', u'2497886'),),
(('countryName', u'US'),),
(('postalCode', u'94043'),),
(('stateOrProvinceName', u'California'),),
(('localityName', u'Mountain View'),),
(('streetAddress', u'487 East Middlefield Road'),),
(('organizationName', u'VeriSign, Inc.'),),
(('organizationalUnitName', u'production Security Services  
'),),
(('commonName', u'verisign.com'),))


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


Re: scipy error undefined symbol: lsame_

2010-04-19 Thread Joaquin Abian
On Apr 19, 7:15 pm, gerardob gberbeg...@gmail.com wrote:
 I installed scipy (and all the required libraries) and the following error
 appears when i tried run a simple example which uses the optimize package of
 scipy. I tried also numpy alone and it works ( at least for printing
 numpy.array([10,20,10]))

 error:

 Traceback (most recent call last):
   File main_test.py, line 2, in module
     from scipy import optimize
   File
 /home/gberbeglia/python/Python-2.6.5/lib/python2.6/site-packages/scipy/optimize/__init__.py,
 line 11, in module
     from lbfgsb import fmin_l_bfgs_b
   File
 /home/gberbeglia/python/Python-2.6.5/lib/python2.6/site-packages/scipy/optimize/lbfgsb.py,
 line 30, in module
     import _lbfgsb
 ImportError:
 /home/gberbeglia/python/Python-2.6.5/lib/python2.6/site-packages/scipy/optimize/_lbfgsb.so:
 undefined symbol: lsame_
 gberbeg...@actarus:~/python/mycodes

 Any ideas on how to solve this problem? Thanks.

 PS: the example is below:

 import numpy
 from scipy import optimize

 a = numpy.array([10,20,10])
 print a

 def f_(x):
         return x*x

 x,f,d = optimize.fmin_l_bfgs_b(f_,[0.1],fprime=None, approx_grad = True,
 bounds = [(-1,1)], iprint=30, maxfun=15)

 --
 View this message in 
 context:http://old.nabble.com/scipy-error-undefined-symbol%3A-lsame_-tp282877...
 Sent from the Python - python-list mailing list archive at Nabble.com.

Um... The snip works perfect on my computer. Just copy and paste.
What libraries are you talking about you had to download? Are you on
windows or linux? On windows you dont need to download anything but
numpy and scipy packages.
joaquin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ssl module doesn't validate that domain of certificate is correct

2010-04-19 Thread geremy condra
On Mon, Apr 19, 2010 at 1:49 PM, John Nagle na...@animats.com wrote:
 exar...@twistedmatrix.com wrote:

 On 04:51 pm, na...@animats.com wrote:

   I'm converting some code from M2Crypto to the new ssl module, and
 I've found what looks like a security hole.  The ssl module will
 validate the certificate chain, but it doesn't check that the certificate
 is valid for the domain.

 ...

 It's a bit debatable.  There probably should be a way to make this happen,
 but it's far from clear that it's the only correct behavior. And, as it
 turns out, there is a way to make it happen - call getpeercert() and perform
 the check yourself. ;)

   Checking it yourself is non-trivial. The checking code has to
 understand DNS wildcards and additional domains in cert extensions.
 The SSL module doesn't seem to let you read all the cert extensions,
 (in particular, you don't get certificatePolicies, so you can't
 tell if a cert is an extended validation cert) but it looks like
 you do get the subjectAltName fields present in the extensions, like this:

  subjectAltName = (('DNS', 'www.chapinfurniture.com'),
        ('DNS', 'chapinfurniture.com')))

   So it's at least possible to check.  Almost.

   (DNS wildcards look like this: *.example.com.  It's also possible
 to have *.*.example.com.  However, no DNS wildcard cert should cover
 more than one second-level domain (huge security hole if you allow that)
 and no extended validation cert should have a wildcard.)

   There may also be issues with internationalized domain names.

   It's very bad for the ssl module to both ignore this check and
 not have that mentioned prominently in the documentation.  This is
 a security-critical function.  Somewhere, there's a Python program that
 can be exploited due to this bug.

   Here's a comparison of what M2Crypto and the SSL module return, for
 verisign.com, which uses most cert features.

 Trying domain www.verisign.com
 Host: www.verisign.com Port: 443

 Info from M2Crypto: module:

 Cipher = DHE-RSA-AES256-SHA
   Subject info: [('CN', 'verisign.com'),
        ('OU', 'production Security Services  '),
        ('O', 'VeriSign, Inc.'),
        ('streetAddress', '487 East Middlefield Road'),
        ('L', 'Mountain View'),
        ('ST', 'California'),
        ('postalCode', '94043'),
        ('C', 'US'),
        ('serialNumber', '2497886'),
        ('2.5.4.15', 'V1.0, Clause 5.(b)'),
        ('jurisdictionOfIncorporationStateOrProvinceName', 'Delaware'),
        ('jurisdictionOfIncorporationCountryName', 'US')]

  Certificate has 10 extensions.
 Extension #0: subjectAltName = DNS:verisign.com, DNS:www.verisign.com,
 DNS:verisign.mobi, DNS:www.verisign.mobi, DNS:verisign.eu, DN
 S:www.verisign.eu
 Extension #1: basicConstraints = CA:FALSE
 Extension #2: subjectKeyIdentifier =
 0F:75:C5:F7:06:11:CE:74:FC:5F:DA:B6:2A:53:CE:39:1C:D6:7D:19
 Extension #3: keyUsage = Digital Signature, Key Encipherment
 Extension #4: crlDistributionPoints =
 URI:http://EVIntl-crl.verisign.com/EVIntl2006.crl

 Extension #5: certificatePolicies = Policy: 2.16.840.1.113733.1.7.23.6
  CPS: https://www.verisign.com/rpa

 Extension #6: extendedKeyUsage = TLS Web Server Authentication, TLS Web
 Client Authentication, Netscape Server Gated Crypto
 Extension #7: authorityKeyIdentifier =
 keyid:4E:43:C8:1D:76:EF:37:53:7A:4F:F2:58:6F:94:F3:38:E2:D5:BD:DF

 Extension #8: authorityInfoAccess = OCSP -
 URI:http://EVIntl-ocsp.verisign.com
 CA Issuers - URI:http://EVIntl-aia.verisign.com/EVIntl2006.cer

 Extension #9: UNDEF = None

 Info from ssl module:

 SSL cert for www.verisign.com:
    notAfter = Apr  2 23:59:59 2012 GMT
    subject = ((('1.3.6.1.4.1.311.60.2.1.3', u'US'),),
                (('1.3.6.1.4.1.311.60.2.1.2', u'Delaware'),),
                (('2.5.4.15', u'V1.0, Clause 5.(b)'),),
                (('serialNumber', u'2497886'),),
                (('countryName', u'US'),),
                (('postalCode', u'94043'),),
                (('stateOrProvinceName', u'California'),),
                (('localityName', u'Mountain View'),),
                (('streetAddress', u'487 East Middlefield Road'),),
                (('organizationName', u'VeriSign, Inc.'),),
                (('organizationalUnitName', u'production Security Services
  '),),
                (('commonName', u'verisign.com'),))


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


I talked about this in my pycon lighting talk- it's actually been
known for some time, and in fact there's some comments in
Zope core that mention this problem being a motivation for
rewriting SSL support from scratch. IIRC (I seem to recall
this, but I seem to have lost my test harness for it) it also
impacts higher level libraries like urllib, but I would verify that
before taking it as gospel. Several of the other members of
python-crypto would know more about it than I.

As a side note, it also impacts IronPython.

Geremy Condra
-- 

Re: Operations on sparse matrices

2010-04-19 Thread Robert Kern

On 4/19/10 1:03 AM, pp wrote:

I am currently dealing with sparse matrices and have doubts on whether
we can use
1.) dot (for matrix multiplication) and inv (inverse) operations of
numpy on sparse matrices of CSR format.

I initially constructed my sparse matrix using COO format and then
converted it to CSR format now I want to know whether normal inverse
and matrix multiplications work with sparse csr matrices.

Also can these operations be applied directly to csr matrices


You will want to ask scipy questions on the scipy mailing list.

  http://www.scipy.org/Mailing_Lists

--
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: scipy error undefined symbol: lsame_

2010-04-19 Thread Robert Kern

On 4/19/10 12:15 PM, gerardob wrote:


I installed scipy (and all the required libraries) and the following error
appears when i tried run a simple example which uses the optimize package of
scipy. I tried also numpy alone and it works ( at least for printing
numpy.array([10,20,10]))

error:

Traceback (most recent call last):
   File main_test.py, line 2, inmodule
 from scipy import optimize
   File
/home/gberbeglia/python/Python-2.6.5/lib/python2.6/site-packages/scipy/optimize/__init__.py,
line 11, inmodule
 from lbfgsb import fmin_l_bfgs_b
   File
/home/gberbeglia/python/Python-2.6.5/lib/python2.6/site-packages/scipy/optimize/lbfgsb.py,
line 30, inmodule
 import _lbfgsb
ImportError:
/home/gberbeglia/python/Python-2.6.5/lib/python2.6/site-packages/scipy/optimize/_lbfgsb.so:
undefined symbol: lsame_


This is a FORTRAN symbol. It means that this extension module was not 
linked correctly to the FORTRAN standard library appropriate for your 
system.


If you need more help, please ask scipy questions on the scipy mailing list.

  http://www.scipy.org/Mailing_Lists

--
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: ssl module doesn't validate that domain of certificate is correct

2010-04-19 Thread exarkun

On 05:49 pm, na...@animats.com wrote:

exar...@twistedmatrix.com wrote:

On 04:51 pm, na...@animats.com wrote:
   I'm converting some code from M2Crypto to the new ssl module, 
and

I've found what looks like a security hole.  The ssl module will
validate the certificate chain, but it doesn't check that the 
certificate

is valid for the domain.

...
It's a bit debatable.  There probably should be a way to make this 
happen, but it's far from clear that it's the only correct behavior. 
And, as it turns out, there is a way to make it happen - call 
getpeercert() and perform the check yourself. ;)


   Checking it yourself is non-trivial.


Yes.  It'd be nice to having something in the stdlib which accepted a 
hostname and a certificate and told you if they line up or not.

The SSL module doesn't seem to let you read all the cert extensions,


Yes.  That sucks.  It was argued about on python-dev and ultimately the 
people writing the code didn't want to expose everything.   I don't 
remember the exact argument for that position.

   It's very bad for the ssl module to both ignore this check and
not have that mentioned prominently in the documentation.


I agree.  As I said, I think the behavior should be well documented.

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


Re: pyconfig.h

2010-04-19 Thread Martin v. Loewis
omnia neo wrote:
 Hi All,
 
 I am working on porting python on vxworks and hence was updating the PC
 \pyconfig.h file for configurng python. As I am reading the file and
 updating manually I come across lot many preprocessor directives which
 I dont understand e.g. HAVE_NICE etc. May be this is standard
 nomenclature and I am not aware of it.
 My point and qwery is that how can I get info about all these
 directives. I am perplexed to enable or disable any of them with half
 knowledge.

See the main pyconfig.h.in for comments when to define each of these
macros. HAVE_NICE should be defined if you have (i.e. your system has)
the nice() function.

Regards,
Martin

NICE(P)   POSIX Programmer's Manual   NICE(P)

NAME
   nice - change the nice value of a process

SYNOPSIS
   #include unistd.h

   int nice(int incr);

DESCRIPTION
   The  nice()  function  shall add the value of incr to the nice
   value of the calling process. A process' nice value is a  non-
   negative  number  for which a more positive value shall result
   in less favorable scheduling.

   A maximum nice value of 2*{NZERO}-1 and a minimum  nice  value
   of 0 shall be imposed by the system. Requests for values above
   or below these limits shall result in the nice value being set
   to  the  corresponding  limit. Only a process with appropriate
   privileges can lower the nice value.

   Calling the nice() function has no effect on the  priority  of
   processes  or  threads with policy SCHED_FIFO or SCHED_RR. The
   effect on processes or threads with other scheduling  policies
   is implementation-defined.

   The  nice  value  set  with  nice()  shall  be  applied to the
   process.  If the process is  multi-threaded,  the  nice  value
   shall affect all system scope threads in the process.

   As -1 is a permissible return value in a successful situation,
   an application wishing to check for  error  situations  should
   set  errno to 0, then call nice(), and if it returns -1, check
   to see whether errno is non-zero.

RETURN VALUE
   Upon successful completion, nice() shall return the  new  nice
   value  -{NZERO}. Otherwise, -1 shall be returned, the process'
   nice value shall not be changed, and errno  shall  be  set  to
   indicate the error.
   indicate the error.

ERRORS
   The nice() function shall fail if:

   EPERM  The  incr  argument is negative and the calling process
  does not have appropriate privileges.

   The following sections are informative.

EXAMPLES
   Changing the Nice Value
   The following example adds the value  of  the  incr  argument,
   -20, to the nice value of the calling process.

  #include unistd.h
  ...
  int incr = -20;
  int ret;

  ret = nice(incr);

APPLICATION USAGE
   None.

RATIONALE
   None.

FUTURE DIRECTIONS
   None.

SEE ALSO
   getpriority() , setpriority() , the Base Definitions volume of
   IEEE Std 1003.1-2001, limits.h, unistd.h

COPYRIGHT
   Portions of this text are reprinted and  reproduced  in  elec‐
   tronic  form  from IEEE Std 1003.1, 2003 Edition, Standard for
   Information Technology -- Portable Operating System  Interface
   (POSIX), The Open Group Base Specifications Issue 6, Copyright
   (C) 2001-2003 by the Institute of Electrical  and  Electronics
   Engineers,  Inc  and  The Open Group. In the event of any dis‐
   crepancy between this version and the original  IEEE  and  The
   Open  Group  Standard,  the  original  IEEE and The Open Group
   Standard is the referee document. The original Standard can be
   obtained online at http://www.opengroup.org/unix/online.html .

IEEE/The Open Group  2003 NICE(P)
-- 
http://mail.python.org/mailman/listinfo/python-list


problems creating and adding class instances to a list:

2010-04-19 Thread Robert Somerville
I am trying to create a list of consisting of multiple instances of the 
same class, The Problems i am having is that i seem to be accessing the 
same memory.. How should i solve this Python problem ?


Here is some sample code demonstraing my problem (same memory) :
from copy import copy as cp

class ctest():
   x = int
   y = [1,2,3]
  


def return_class(i):
   d = ctest()
   d.y[1] = i*10
   return (d)

if __name__ == '__main__':
   c_list= []
   print 'len-a =',len(c_list)
   for i in range(5):
   e = cp(return_class(i))
   c_list.append(e)
   print 'i= ',i,c_list[i].y[1]
   if ( i  0):
   print 'i-1= ',i-1,c_list[i-1].y[1]   
  
   print 'len = ' , len(c_list)   
   for i in range(5):

   print 'i= ',i,c_list[i].y[1]


here is the output demonstrating that i am addressing the same memory:

rsomervi...@galena:~/workspace/CSIRO_gui/trunk/src$ python test4.py
len-a = 1
i=  0 0
i=  1 10
i-1=  0 10
i=  2 20
i-1=  1 20
i=  3 30
i-1=  2 30
i=  4 40
i-1=  3 40
len =  6
i=  0 40
i=  1 40
i=  2 40
i=  3 40
i=  4 40

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


Re: problems creating and adding class instances to a list:

2010-04-19 Thread Xavier Ho
On Tue, Apr 20, 2010 at 7:21 AM, Robert Somerville 
rsomervi...@sjgeophysics.com wrote:

 class ctest():
   x = int
   y = [1,2,3]


Variables defined directly under the class are known as static variables
in many other languages. Here in Python it's called a class variable, but
they're still the same concept.

What you want is instance variables, which are not shared by the class
instances, but different depending on each instance instead. That said,

class ctest():
def __init__(self):
self.x = int
self.y = [1, 2, 3]

is probably what you're after.

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


Re: problems creating and adding class instances to a list:

2010-04-19 Thread Chris Rebert
On Mon, Apr 19, 2010 at 2:29 PM, Xavier Ho cont...@xavierho.com wrote:
 On Tue, Apr 20, 2010 at 7:21 AM, Robert Somerville
 rsomervi...@sjgeophysics.com wrote:

 class ctest():
   x = int
   y = [1,2,3]

 Variables defined directly under the class are known as static variables
 in many other languages. Here in Python it's called a class variable, but
 they're still the same concept.

 What you want is instance variables, which are not shared by the class
 instances, but different depending on each instance instead. That said,

 class ctest():
     def __init__(self):
         self.x = int

Additionally, `self.x = int` might not do what you thought it does. It
does *not* create a new instance variable of type 'int'. Instead, it
literally assigns to a new instance variable x the *function*† that
converts values into integers.

Cheers,
Chris
--
† This isn't entirely accurate; I'm oversimplifying for ease of understanding.
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Oktest 0.2.1 released - a new style testing library.

2010-04-19 Thread kwatch
Hi,

I released Oktest 0.2.1.

homepage:  http://packages.python.org/Oktest/
download:  http://pypi.python.org/pypi/Oktest/
repository: http://bitbucket.org/kwatch/oktest/

Oktest is a new-style testing library for Python.

from oktest import ok
ok (x)  0 # same as assert_(x  0)
ok (s) == 'foo'# same as assertEqual(s, 'foo')
ok (s) != 'foo'# same as assertNotEqual(s, 'foo')
ok (f).raises(ValueError)  # same as assertRaises(ValueError, f)
ok (u'foo').is_a(unicode)  # same as assert_(isinstance(u'foo',
ode))
not_ok (u'foo').is_a(int)  # same as assert_(not
isinstance(u'foo', )
ok ('A.txt').is_file() # same as
assert_(os.path.isfile('A.txt'))
not_ok ('A.txt').is_dir()  # same as assert_(not
os.path.isdir('A.txt'))

You can use ok() instead of 'assertXxx()' in unittest.

Oktest requires Python 2.3 or later. Oktest is ready for Python 3.

NOTICE!! Oktest is a young project and specification may change in the
future.

See http://packages.python.org/Oktest/ for details.

--
regards,
makoto kuwata
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problems creating and adding class instances to a list:

2010-04-19 Thread Xavier Ho
On Tue, Apr 20, 2010 at 7:38 AM, Chris Rebert c...@rebertia.com wrote:

 Additionally, `self.x = int` might not do what you thought it does. It
 does *not* create a new instance variable of type 'int'. Instead, it
 literally assigns to a new instance variable x the *function*† that
 converts values into integers.


Thanks, Chris. I'm well aware of that. =]

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


Re: problems creating and adding class instances to a list:

2010-04-19 Thread Chris Rebert
On Mon, Apr 19, 2010 at 3:41 PM, Xavier Ho cont...@xavierho.com wrote:
 On Tue, Apr 20, 2010 at 7:38 AM, Chris Rebert c...@rebertia.com wrote:
 Additionally, `self.x = int` might not do what you thought it does. It
 does *not* create a new instance variable of type 'int'. Instead, it
 literally assigns to a new instance variable x the *function*† that
 converts values into integers.

 Thanks, Chris. I'm well aware of that. =]

It was obviously directed at the OP. :-)

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


Re: unexpected output from difflib.SequenceMatcher

2010-04-19 Thread Vlastimil Brom
From: Vlastimil Brom vlastimil.b...@gmail.com
Date: 2010/4/16
Subject: unexpected output from difflib.SequenceMatcher

...
Instead of just reporting the insertion and deletion of these single
characters ... the output of the
SequenceMatcher decides to delete a large part of the string in
between the differences and to insert the almost same text after that.
...

Just for the record, althought it seemed unlikely to me first, it
turns out, that this may have the same cause like several difflib
items in the issue tracker regarding unexpected outputs for long
sequences with relatively highly repetitive items, e.g.

http://bugs.python.org/issue2986
http://bugs.python.org/issue1711800
http://bugs.python.org/issue4622
http://bugs.python.org/issue1528074

In my case, disabling the popular heuristics as mentioned in
http://bugs.python.org/issue1528074#msg29269
i.e. modifying the difflib source (around line 314 for py.2.5.4) to

if 0:   # disable popular heuristics
if n = 200 and len(indices) * 100  n:
populardict[elt] = 1
del indices[:]

seems to work perfectly.
Anyway, I would appreciate comments, whether this is the appropriate
solution for the given task - i.e. the character-wise comparison of
strings; or are there maybe some drawbacks to be aware of? Wouldn't
some kind of control over the pouplar heuristics be useful in the
exposed interface of difflib?
Or is this just the inappropriate tool for the character-wise string
comparison, as is suggested e.g. in
http://bugs.python.org/issue1528074#msg29273  althought it seems to
work just right for the most part?

regards,
vbr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cross-platform coloured text in terminal

2010-04-19 Thread Jonathan Hartley
On Apr 17, 11:52 am, Jonathan Hartley tart...@tartley.com wrote:
 On Apr 16, 5:59 pm, Lie Ryan lie.1...@gmail.com wrote:



  On 04/16/10 19:28, Jonathan Hartley wrote:

   I'm playing with ideas of what API to expose. My favourite one is to
   simply embed ANSI codes in the stream to be printed. Then this will
   work as-is on Mac and *nix. To make it work on Windows, printing could
   be done to a file0-like object which wraps stdout:

  The problem with that is you're simply reinventing ANSI.SYS device driver.

  An alternative API is you could override .__add__(), like so (completely
  untested):

  classColor(object):
     def __init__(self,color):
         self.color=  map_the_color(color)
         self.string = 
     def __add__(self, string):
         self.string += string
         return self
     def __str__(self):
         if terminal_can_do_ansi_color:
             return ansicolorescape(self.string, self.color)
         elif windows:
             syscalltocolor(self.color)
             print self.string
             syscalltocolor(reset thecolor)
             return 

  GREEN =Color('green')
  print GREEN + Great + Good

  you can even go a bit further and allow chained calls (again, completely
  untested, but you get the idea):

  classColor(object):
     def __init__(self,color):
         self.color=  map_the_color(color)
         self.stack = []
     def __add__(self, string):
         if isinstance(string,Color):
             # not a string, chain the calls
             self.stack.append((string.color, []]))
         else:
             # a string,
             self.stack[-1][1].append(string)
         return self
     def __radd__(self, string):
         self.stack.append([self.default, string])
         return self

     def __str__(self):
         if ansi_capable:
             return colorescape(format, string)
         elif windows:
             for format, string in self.stack:
                 syscalltocolor(color)
                 print string
                 return 

  GREEN =Color('green')
  RED =Color('red')

  print Fairly + GREEN + Great + RED + Poor

  or something like that, and you will have an API that works
  transparently on all platforms. The downside is that you cannot call
  str(GREEN + foo) on windows.

 Hey Lie,

 Thanks heaps for the reply!

  The problem with that is you're simply reinventing ANSI.SYS device driver.

 I don't see that as a problem - in fact I think it's exactly my
 goal! :-)

 The difference is that the ANSI driver requires installation and a
 reboot on the end-user's computer, which is a fiddly and intrusive
 thing for a Python developer to achieve. Whereas doing the same job in
 a Python module is easy to use for the Python developer - they just
 import the module, maybe call an 'init()' function, and then the ANSI
 functionality works on all platforms.

 Your ideas about generating and chaining the ANSI code strings are
 great. I worry though, about intermingling the code that generates
 ANSI escape sequences with the code which makes them work on Windows.
 The problem is that then, only applications which use your ANSI-
 generation library will work on Windows. Whereas if these two things
 are kept separate, then applications which use any other ANSI-
 generation techniques, such as using 'termcolor', or manaully printing
 raw ANSI sequences, these can also all work on Windows too, simply by
 adding an import and an 'init()' call to the start of the application.

 Am I making sense? Many thanks for your thoughts.

   Jonathan


I have implemented these ideas here. It seems to work.
http://pypi.python.org/pypi/colorama
-- 
http://mail.python.org/mailman/listinfo/python-list


any modules having a function to partition a list by predicate provided?

2010-04-19 Thread knifenomad
i know it's not very hard to get that solution.
just by implementing simple function like below.

  def partition(target, predicate):

split a list into two partitions with a predicate
provided.
any better ideas? :)

true = []
false= []
for item in target:
if predicates(item):
true.append(item)
else:
false.append(item)
return true, false

but i wonder if there's another way to do this with standard libraries
or .. built-ins.
if it's not, i'd like the list objects to have partition method like
string module has.

true, false = [1,2,3,4].partition(lambda x: x 1)

print true, false
[2,3,4]   [1]

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


Re: any modules having a function to partition a list by predicate provided?

2010-04-19 Thread Chris Rebert
On Mon, Apr 19, 2010 at 6:00 PM, knifenomad knifeno...@gmail.com wrote:
 i know it's not very hard to get that solution.
 just by implementing simple function like below.

      def partition(target, predicate):
            
            split a list into two partitions with a predicate
 provided.
            any better ideas? :)
            
            true = []
            false= []
            for item in target:
                if predicates(item):
                    true.append(item)
                else:
                    false.append(item)
            return true, false

 but i wonder if there's another way to do this with standard libraries
 or .. built-ins.
 if it's not, i'd like the list objects to have partition method like
 string module has.

(A) str.partition() has a /completely/ different meaning from your partition()
(B) You'd probably have better luck getting it added to the itertools
module since the concept is applicable to all iterables.
[http://docs.python.org/library/itertools.html]

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any modules having a function to partition a list by predicate provided?

2010-04-19 Thread segunai
On 4월20일, 오전10시16분, Chris Rebert c...@rebertia.com wrote:
 On Mon, Apr 19, 2010 at 6:00 PM, knifenomad knifeno...@gmail.com wrote:
  i know it's not very hard to get that solution.
  just by implementing simple function like below.

       def partition(target, predicate):
             
             split a list into two partitions with a predicate
  provided.
             any better ideas? :)
             
             true = []
             false= []
             for item in target:
                 if predicates(item):
                     true.append(item)
                 else:
                     false.append(item)
             return true, false

  but i wonder if there's another way to do this with standard libraries
  or .. built-ins.
  if it's not, i'd like the list objects to have partition method like
  string module has.

 (A) str.partition() has a /completely/ different meaning from your partition()
 (B) You'd probably have better luck getting it added to the itertools
 module since the concept is applicable to all iterables.
 [http://docs.python.org/library/itertools.html]

 Cheers,
 Chris
 --http://blog.rebertia.com

yep, my mistake. i shouldn't have compared it to string's partition().
i just wanted that convenience string.partition() has as a built-in.
anyway, thanks for itertools. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeEncodeError during repr()

2010-04-19 Thread Dave Angel

gb345 wrote:

In hqguja$t...@online.de Martin v. Loewis mar...@v.loewis.de writes:

  

Do I need to do something especial to get repr to work strictly
with unicode?
  


  

Yes, you need to switch to Python 3 :-)



  

Or should __repr__ *always* return bytes rather than unicode?
  


  

In Python 2.x: yes.



  

What about __str__ ?
  


  

Likewise.



  

If both of these are supposed to return bytes,
then what method should I use to define the unicode representation
for instances of a class?
  


  

__unicode__.



Thanks!


  
More precisely, __str__() and __repr__() return characters.  Those 
characters are 8 bits on Python 2.x, and Unicode on 3.x.   If you need 
unicode on 2.x, use __unicode__().


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


dict.keys() and dict.values() are always the same order, is it?

2010-04-19 Thread Menghan Zheng
Hello!

Is it assured the following statement is always True?
If it is always True, in which version, python2.x or python3.x?

 a = dict()
...
 assert(a.values == [a[k] for k in a.keys()])
-- ?


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


Re: ssl module doesn't validate that domain of certificate is correct

2010-04-19 Thread John Nagle

exar...@twistedmatrix.com wrote:

On 05:49 pm, na...@animats.com wrote:

exar...@twistedmatrix.com wrote:

On 04:51 pm, na...@animats.com wrote:

   I'm converting some code from M2Crypto to the new ssl module, and
I've found what looks like a security hole.  The ssl module will
validate the certificate chain, but it doesn't check that the 
certificate

is valid for the domain.

...
It's a bit debatable.  There probably should be a way to make this 
happen, but it's far from clear that it's the only correct behavior. 
And, as it turns out, there is a way to make it happen - call 
getpeercert() and perform the check yourself. ;)


   Checking it yourself is non-trivial.


Yes.  It'd be nice to having something in the stdlib which accepted a 
hostname and a certificate and told you if they line up or not.

The SSL module doesn't seem to let you read all the cert extensions,


Yes.  That sucks.  It was argued about on python-dev and ultimately the 
people writing the code didn't want to expose everything.   I don't 
remember the exact argument for that position.

   It's very bad for the ssl module to both ignore this check and
not have that mentioned prominently in the documentation.


I agree.  As I said, I think the behavior should be well documented.

Jean-Paul


   What a mess.

   The cause of the problem seems to be someone named Bill Janssen (janssen)
See http://bugs.python.org/issue1589;.  He shouted down attempts to put in
this check, apparently because he saw use cases for a backdoor.  He
claimed he would change the documentation, but did not do so, leaving
the backdoor enabled.

   Without host name checking, you lose all man in the middle protection
in SSL.

Jannsen wrote:
Nope.  Hostname verification was never a good idea -- the hostname is
just a vague notion, at best -- lots of hostnames can map to one or more
IP addresses of the server.

This is an weak objection for the SSL module, since the SSL connect
function can take a domain name, not an IP address.  You can pass an
IP address to connect, but if you pass a domain name, it should
be validated against the certificate.   Also, with TLS, name validation
is supposed to work even for multiple domains on the same IP address.
(But see http://en.wikipedia.org/wiki/Server_Name_Indication;, which
says that it works in most current browsers, but not Python.)

Heikki Toivonen (heikki), author of M2Crypto, wrote:

I would definitely recommend providing as strict as possible hostname
verification in the stdlib, but provide application developers a way to
override that.

Hekki put a warning about this on his blog at
http://www.heikkitoivonen.net/blog/2008/10/14/ssl-in-python-26/;.

All major browsers make this check.  Most Python users will expect the
SSL module to do the checks a browser does.  If the user went to the
trouble to provide a certificate authority file, and specified CERT_REQUIRED,
they presumably want their connections fully validated.

But Jannsen closed the issue anyway.  Looks like a developer in denial
situation.

The sample code suggested for a user-level check at

http://bugs.python.org/msg58508

does not handle valid domain wildcards, which makes it unusable in practice.
It's non-trivial to do this in accordance with the spec.

Here's an example of code written by someone who wasn't aware of this bug.
http://www.muchtooscrawled.com/2010/03/https-certificate-verification-in-python-with-urllib2/;

It's not clear if this hole made it into Twisted, or the Python
BitTorrent client.

Who's reviewing the SSL module for security?  Is anyone checking for backdoors?


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


Re: dict.keys() and dict.values() are always the same order, is it?

2010-04-19 Thread Cameron Simpson
On 20Apr2010 11:03, Menghan Zheng menghan...@gmail.com wrote:
| Is it assured the following statement is always True?
| If it is always True, in which version, python2.x or python3.x?
| 
|  a = dict()
| ...
|  assert(a.values == [a[k] for k in a.keys()])
| -- ?

It is always true. At this URL:

  http://docs.python.org/library/stdtypes.html?highlight=values#dict.items

it says:

  If items(), keys(), values(), iteritems(), iterkeys(), and
  itervalues() are called with no intervening modifications to the
  dictionary, the lists will directly correspond. This allows the
  creation of (value, key) pairs using zip(): pairs = zip(d.values(),
  d.keys()).

BTW, I got to that particular piece of text by starting at the doco for
the .values() method of dict, which links to the .items() method.

Cheers,
-- 
Cameron Simpson c...@zip.com.au DoD#743
http://www.cskk.ezoshosting.com/cs/

I couldn't think of anything else to do with it, so I put it on the web.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dict.keys() and dict.values() are always the same order, is it?

2010-04-19 Thread alex23
On Apr 20, 1:03 pm, Menghan Zheng menghan...@gmail.com wrote:
 Is it assured the following statement is always True?
 If it is always True, in which version, python2.x or python3.x?

I believe its an implementation detail and should not be relied on. If
you need consistent ordering, use an OrderedDict[1] or sort() the
lists beforehand.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any modules having a function to partition a list by predicate provided?

2010-04-19 Thread Krister Svanlund
On Tue, Apr 20, 2010 at 3:40 AM, segunai osk@gmail.com wrote:
 On 4월20일, 오전10시16분, Chris Rebert c...@rebertia.com wrote:
 On Mon, Apr 19, 2010 at 6:00 PM, knifenomad knifeno...@gmail.com wrote:
  i know it's not very hard to get that solution.
  just by implementing simple function like below.

   def partition(target, predicate):
 
 split a list into two partitions with a predicate
  provided.
 any better ideas? :)
 
 true = []
 false= []
 for item in target:
 if predicates(item):
 true.append(item)
 else:
 false.append(item)
 return true, false

  but i wonder if there's another way to do this with standard libraries
  or .. built-ins.
  if it's not, i'd like the list objects to have partition method like
  string module has.

 (A) str.partition() has a /completely/ different meaning from your 
 partition()
 (B) You'd probably have better luck getting it added to the itertools
 module since the concept is applicable to all iterables.
 [http://docs.python.org/library/itertools.html]

 Cheers,
 Chris
 --http://blog.rebertia.com

 yep, my mistake. i shouldn't have compared it to string's partition().
 i just wanted that convenience string.partition() has as a built-in.
 anyway, thanks for itertools. :)
 --
 http://mail.python.org/mailman/listinfo/python-list


The way I would do it is probably apply filter to the list:
 def f(x): return x % 2 != 0 and x % 3 != 0
...
 filter(f, range(2, 25))
[5, 7, 11, 13, 17, 19, 23]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dict.keys() and dict.values() are always the same order, is it?

2010-04-19 Thread alex23
Cameron Simpson c...@zip.com.au wrote:
   If items(), keys(), values(), iteritems(), iterkeys(), and
   itervalues() are called with no intervening modifications to the
   dictionary, the lists will directly correspond. This allows the
   creation of (value, key) pairs using zip(): pairs = zip(d.values(),
   d.keys()).

I stand corrected. Thanks Cameron.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Usable street address parser in Python?

2010-04-19 Thread John Nagle

John Nagle wrote:

  Is there a usable street address parser available?  There are some
bad ones out there, but nothing good that I've found other than commercial
products with large databases.  I don't need 100% accuracy, but I'd like
to be able to extract street name and street number for at least 98% of
US mailing addresses.

  There's pyparsing, of course. There's a street address parser as an
example at 
http://pyparsing.wikispaces.com/file/view/streetAddressParser.py;.


  The author of that module has changed the code, and it has some
new features.  This is much better.

  Unfortunately, now it won't run with the released
version of pyparsing (1.5.2, from April 2009), because it uses
originalTextFor, a feature introduced since then.  I worked around that,
but discovered that the new version is case-sensitive.  Changed
Keyword to CaselessKeyword where appropriate.

  I put in the full list of USPS street types, and discovered
that 1500 DEER CREEK LANE still parses with a street name
of DEER, and a street type fo CREEK, because CREEK is a
USPS street type.  Need to do something to pick up the last street
type, not the first.  I'm not sure how to do that with pyparsing.
Maybe if I buy the book...

  There's still a problem with: 2081 N Webb Rd, where the street name
comes out as N WEBB.
Addresses like 1234 5th St. S. yield a street name of 5 TH,
but if the directional is before the name, it ends up with the name.

  Getting closer, though.  If I can get to 95% of common cases, I'll
be happy.


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


Re: dict.keys() and dict.values() are always the same order, is it?

2010-04-19 Thread Cameron Simpson
On 19Apr2010 21:31, alex23 wuwe...@gmail.com wrote:
| Cameron Simpson c...@zip.com.au wrote:
|    If items(), keys(), values(), iteritems(), iterkeys(), and
|    itervalues() are called with no intervening modifications to the
|    dictionary, the lists will directly correspond. This allows the
|    creation of (value, key) pairs using zip(): pairs = zip(d.values(),
|    d.keys()).
| 
| I stand corrected. Thanks Cameron.

Oh, I was all ready to say what you said, but decided to check the docs
myself first:-)

Cheers,
-- 
Cameron Simpson c...@zip.com.au DoD#743
http://www.cskk.ezoshosting.com/cs/

I really don't like :-) symbols as well. I feel that if you can't see the pie
coming, you deserve whipped cream up your nose.
- r...@cherry.cray.com (rob derrick)
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue8453] build_installer.py breaks bzip compilation

2010-04-19 Thread Martin v . Löwis

New submission from Martin v. Löwis mar...@v.loewis.de:

The current build_installer fails to build dependencies, e.g. with

gcc-4.0 -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk  -o 
bzip2 bzip2.o -L. -lbz2
collect2: cannot find 'ld'
collect2: cannot find 'ld'
lipo: can't open input file: /var/tmp//cc8o5UUU.out (No such file or directory)

For the full buildlog, see

http://www.python.org/dev/buildbot/builders/2.7.dmg/builds/9/steps/compile/logs/stdio

--
assignee: ronaldoussoren
messages: 103557
nosy: loewis, ronaldoussoren
severity: normal
status: open
title: build_installer.py breaks bzip compilation
versions: Python 2.7

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



[issue8451] syslog.syslog('msg') logs message with ident python.

2010-04-19 Thread Sean Reifschneider

Changes by Sean Reifschneider j...@tummy.com:


Added file: http://bugs.python.org/file16983/syslog-kwargs2.patch

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



[issue6095] os.curdir as the default argument for os.listdir

2010-04-19 Thread Virgil Dupras

Virgil Dupras hs...@hardcoded.net added the comment:

Here's another one. I hadn't realized that it was useless to target the 2.x 
codebase. So I re-worked this on py3k. The change is non-trivial, since the 
non-windows/non-os2 part of the code has significantly changed in 3k. This 
time, since oname is released later and used in error conditions, I thought 
it was worth it to allocate a new PyBytes for the default value.

I also modified the documentation so that it tells about path's default value.

--
Added file: http://bugs.python.org/file16984/t6095_py3k.diff

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



[issue8449] buildbot: test_dbm and test_dbm_ndbm

2010-04-19 Thread roundup-admin
failures
To: python-bugs-list@python.org
From: STINNER Victor rep...@bugs.python.org
Date: Sun, 18 Apr 2010 23:17:46 +
Precedence: bulk
X-Roundup-Name: Python tracker
X-Roundup-Loop: hello
X-Roundup-Version: 1.4.10
Reply-To: Python tracker rep...@bugs.python.org
Message-Id: 1271632666.33.0.388840040556.issue8...@psf.upfronthosting.co.za
X-Roundup-issue-status: open
X-Roundup-issue-keywords: buildbot
X-Roundup-issue-severity: normal
X-Roundup-issue-versions: Python 3.1
In-Reply-To: 1271629817.22.0.668476357491.issue8...@psf.upfronthosting.co.za
Content-Transfer-Encoding: quoted-printable


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

The tests delete generated files before and after the test using support.un=
link(). This function calls os.unlink() but ignores OSError.

I guess that the tests are unable to delete the file for an unknown reason,=
 and so the tests fail.

--

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



[issue8393] subprocess: support undecodable current working directory on POSIX OS

2010-04-19 Thread Amaury Forgeot d'Arc

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

It does not work on Windows:

 subprocess.Popen(c:/windows/notepad.exe, cwd=b'c:/temp')
Traceback (most recent call last):
  File stdin, line 1, in module
  File D:\afa\python\py3k-1\lib\subprocess.py, line 681, in __init__
restore_signals, start_new_session)
  File D:\afa\python\py3k-1\lib\subprocess.py, line 892, in _execute_child
startupinfo)
TypeError: must be string or None, not bytes

The function sp_CreateProcess() in PC/_subprocess.c should probably be fixed.
And please add unit tests...

--
nosy: +amaury.forgeotdarc
resolution: fixed - 
status: closed - open

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



[issue5650] Obsolete RFCs should be removed from doc of urllib.urlparse

2010-04-19 Thread Ezio Melotti

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

The 'See also' in the documentation should also be updated:
http://docs.python.org/dev/library/urlparse.html#urlparse.urldefrag

--
nosy: +ezio.melotti
priority:  - normal
status: closed - open
versions: +Python 3.2 -Python 3.0

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



[issue8438] Codecs: surrogateescape error handler in Python 2.7

2010-04-19 Thread Marc-Andre Lemburg

Marc-Andre Lemburg m...@egenix.com added the comment:

STINNER Victor wrote:
 
 STINNER Victor victor.stin...@haypocalc.com added the comment:
 
 I think it would be best to backport the handler (even though 
 it is not needed in Python 2.7), since it makes porting apps 
 to 3.x easier.
 
 surrogateescape should not be used directly be applications. It's used by 
 Python3 internals using unicode by default.
 
 I don't know if it's would help porting applications from Python2 to Python3. 
 I don't know a use case of surrogateescape in Python2. By default, Python2 
 uses byte string everywhere, especially for filenames, and so it doesn't need 
 any unicode error handler.
 
 Another point to consider is that utf8 encoder rejects surrogates in Python3, 
 whereas surrogates are accepted by the Python2 utf8 encoder.

Sorry, I think I need to correct myself: I mixed up the handlers
surrogateescape and surrogatepass. I was actually thinking of the
surrogatepass handler which makes the Python3 UTF-8 codec have like the
Python2 UTF-8 codec (without extra handler), not the surrogatescape
handler which implements the UTF-8b logic of escaping non-encodable
bytes to lone surrogates.

* The surrogatepass handler is needed in Python 2.7 to make it
possible to write applications that work in both 2.7 and 3.x
without changing the code.

I consider this an important missing backport for 2.7, since
without this handler, the UTF-8 codecs in 2.7 and 3.x are
incompatible and there's no other way to work around this
other than to make use of the errorhandler conditionally
depend on the Python version.

As such, it's a bug rather than a new feature.

* The surrogateescape handler implements the UTF-8b escaping
logic:

b'\x91\x92'

In Python 3.x this is needed to work around problems with
wrong I/O encoding settings or situations where you have mixed
encoding settings used in external resources such as environment
variable content, filesystems using different encodings than
the system one, remote shell output, pipes which don't carry
any encoding information, etc. etc.

Backporting this handler would be useful for Python 2.7 as
well, since it allows preparing 2.7 applications for use in
3.x and again allows using the same code for 2.7 and 3.x.

Not having this handler in 2.7 is not as serious as the
surrogatepass handler, but still useful for applications to
use that are meant to run in 2.7 and 3.x unchanged.

--

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



[issue8438] Codecs: surrogateescape error handler in Python 2.7

2010-04-19 Thread Ezio Melotti

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

 I consider this an important missing backport for 2.7, since
 without this handler, the UTF-8 codecs in 2.7 and 3.x are
 incompatible and there's no other way to work around this
 other than to make use of the errorhandler conditionally
 depend on the Python version.

FWIW I tried to updated the UTF-8 codec on trunk from RFC 2279 to RFC 3629 
while working on #8271, and found out this difference in the handling of 
surrogates (only on 3.x they are invalid).
I didn't change the behavior of the codec in the patch I attached to #8271 
because it was out of the scope of the issue, but I consider the fact that in 
Python 2.x surrogates can be encoded as a bug, because it doesn't follow RFC 
3629.
IMHO Python 2.x should provide an RFC-3629-compliant UTF-8 codec, however I 
didn't have time yet to investigate how Python 3 handles this and what is the 
best solution (e.g. adding another codec or change the default behavior).

--

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



[issue8393] subprocess: support undecodable current working directory on POSIX OS

2010-04-19 Thread STINNER Victor

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

 And please add unit tests...

I'm thinking on this. I plan to write tests for all my last changes about 
surrogates.

--

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



[issue8394] ctypes.dlopen() doesn't support surrogates

2010-04-19 Thread Amaury Forgeot d'Arc

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

It does not work on Windows:

 ctypes.CDLL(b'kernel32')
Traceback (most recent call last):
  File stdin, line 1, in module
  File D:\afa\python\py3k-1\lib\ctypes\__init__.py, line 350, in __init__
self._handle = _dlopen(self._name, mode)
TypeError: bad argument type for built-in operation

--
resolution: fixed - 
status: closed - open

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



[issue8393] subprocess: support undecodable current working directory on POSIX OS

2010-04-19 Thread STINNER Victor

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

 It does not work on Windows

I always consider Windows as a special case because Windows uses unicode 
internally. Byte string are converted quickly to unicode using the current 
locale.

My patch was for UNIX/BSD which uses byte string internally.

sp_CreateProcess() in PC/_subprocess.c uses CreateProcessW. To support byte 
string, we should use the byte string version of CreateProcess 
(CreateProcessA ?) or convert current directory to unicode (using the current 
locale). The second solution minimize the changes.

--

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



[issue8394] ctypes.dlopen() doesn't support surrogates

2010-04-19 Thread STINNER Victor

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

load_library() uses LoadLibraryW() which use a WCHAR*. To support bytes, we can 
use LoadLibraryA() and TCHAR*.

--

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



[issue8438] Codecs: surrogateescape error handler in Python 2.7

2010-04-19 Thread Marc-Andre Lemburg

Marc-Andre Lemburg m...@egenix.com added the comment:

Ezio Melotti wrote:
 
 Ezio Melotti ezio.melo...@gmail.com added the comment:
 
 I consider this an important missing backport for 2.7, since
 without this handler, the UTF-8 codecs in 2.7 and 3.x are
 incompatible and there's no other way to work around this
 other than to make use of the errorhandler conditionally
 depend on the Python version.
 
 FWIW I tried to updated the UTF-8 codec on trunk from RFC 2279 to RFC 3629 
 while working on #8271, and found out this difference in the handling of 
 surrogates (only on 3.x they are invalid).
 I didn't change the behavior of the codec in the patch I attached to #8271 
 because it was out of the scope of the issue, but I consider the fact that in 
 Python 2.x surrogates can be encoded as a bug, because it doesn't follow RFC 
 3629.
 IMHO Python 2.x should provide an RFC-3629-compliant UTF-8 codec, however I 
 didn't have time yet to investigate how Python 3 handles this and what is the 
 best solution (e.g. adding another codec or change the default behavior).

We have good reasons to allow lone surrogates in the UTF-8
codec.

Please remember that Python is a programming language
meant to allow writing applications, which also includes constructing
Unicode data from scratch, rather than an application which is
only meant to work with UTF-8 data.

Also note that lone surrogates were considered valid UTF-8 at the
time of adding Unicode support to Python and many years after that.

Since the codec is used in lots of applications, following the
Unicode consortium change in 2.7 is not possible.

This is why it was done in the 3.x branch and then only with
the additional surrogatepass handler to get back the old behavior
where needed.

But this is getting offtopic for the issue in question... I'll
open a new ticket for the backports.

--

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



[issue8393] subprocess: support undecodable current working directory on POSIX OS

2010-04-19 Thread Amaury Forgeot d'Arc

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

PEP 277 explicitly states that unicode strings should be passed to 
wide-character functions, whereas byte strings use standard functions.
This is done in posixmodule.c, for example.

The current locale is a moving thing.

--

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



[issue8394] ctypes.dlopen() doesn't support surrogates

2010-04-19 Thread STINNER Victor

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

I only fixed UNIX/BSD versions of subprocess/ctypes.dlopen() because it's not 
possible to open some files with an undecodable filename. On Windows, the file 
system and Python3 use Unicode, and so there is no such corner case.

On Windows, should we encourage people migrating from byte to character string? 
Or should we support byte string for backward compatibility or because there is 
really a corner case where it's not possible to open a file with an unicode 
string?

See also my msg103565 (Issue #8393, subprocess),

--

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



[issue8394] ctypes.dlopen() doesn't support surrogates

2010-04-19 Thread Amaury Forgeot d'Arc

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

yes, except that TCHAR* depends on compilation settings (it resolves to wchar_t 
when UNICODE is #defined); simply use char*.

--

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



[issue8453] build_installer.py breaks bzip compilation

2010-04-19 Thread Ned Deily

Ned Deily n...@acm.org added the comment:

Odd, works for me on 10.4, 10.5, and 10.6 (but I have never tried running under 
buildbot, if that is what is happening here).
  
For 10.4 with its most-recent Xcode installed:

$ /usr/bin/ld -v
Apple Computer, Inc. version cctools-622.9~2
$ /usr/bin/gcc -v
Using built-in specs.
Target: powerpc-apple-darwin8
Configured with: /var/tmp/gcc/gcc-5370~2/src/configure --disable-checking 
-enable-werror --prefix=/usr --mandir=/share/man 
--enable-languages=c,objc,c++,obj-c++ 
--program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ 
--with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib 
--build=powerpc-apple-darwin8 --host=powerpc-apple-darwin8 
--target=powerpc-apple-darwin8
Thread model: posix
gcc version 4.0.1 (Apple Computer, Inc. build 5370)
$ uname -a
Darwin hostname 8.11.0 Darwin Kernel Version 8.11.0: Wed Oct 10 18:26:00 PDT 
2007; root:xnu-792.24.17~1/RELEASE_PPC Power Macintosh powerpc
$ /usr/bin/python ./build-installer.py --build-dir ../../dmg
...
gcc-4.0 -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk  -o 
bzip2 bzip2.o -L. -lbz2
gcc-4.0 -arch i386 -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -c 
bzip2recover.c
...
echo .so man1/bzdiff.1  
/Users/nad/2.7.dmg/build/dmg/libraries/usr/local//man/man1/bzcmp.1
Done Bzip2 1.0.5

Using local copy of ZLib 1.2.3
...

--
nosy: +ned.deily

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



[issue8393] subprocess: support undecodable current working directory on POSIX OS

2010-04-19 Thread STINNER Victor

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

 PEP 277 explicitly states that unicode strings should be passed to
  wide-character functions, whereas byte strings use standard
 functions. This is done in posixmodule.c, for example.

CreateProcessW takes a lot of arguments. Should we CreateProcessA or 
CreateProcessW if some arguments are byte string and other are unicode string?

 The current locale is a moving thing.

Don't CreateProcessA do the same thing? Convert byte string to unicode using 
the current locale. To use the right words, by current locale I mean the 
mbcs Windows codec.

--

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



[issue8451] syslog.syslog('msg') logs message with ident python.

2010-04-19 Thread Antoine Pitrou

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

Some notes about the patch:

- NEWS blurbs generally appear antichronologically, that is newest first :-)
- you don't have to mention that The 3.2 changes mentioned above are included 
in 2.7
- the part of the PyArg_ParseTupleAndKeywords string after the semi-colon is 
supposed to be a custom error message, which [ident string [, logoption [, 
facility]]] doesn't look like; how about simply using a colon and putting the 
function name?
- you should check PyList_Size()'s return value for error (sys.argv could have 
been overriden to something else than a list)
- similarly, scriptobj is not guaranteed to be a string object, so you have to 
check for that too
- to check for string length  0, it looks more natural to check either that 
script[0] != 0, or that PyString_GET_SIZE(...)  0 (rather than calling 
PyObject_IsTrue())
- why do you Py_INCREF() the openargs tuple? It looks like a reference leak
- if PyTuple_New(0) fails (which I admit is highly unlikely), you should free 
all other resources and bail out
- when manually calling syslog_openlog(), you should check the return value and 
either Py_DECREF it (if non-NULL) or bail out

--
nosy: +pitrou

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



[issue8410] Fix emulated lock to be 'fair'

2010-04-19 Thread Kristján Valur Jónsson

Kristján Valur Jónsson krist...@ccpgames.com added the comment:

Also, _POSIX_SEMAPHORES must be defined to be greater than 200112L.  If it 
isn't, then it isn't supported.

--

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



  1   2   3   >