Sphinx 1.1.1 released

2011-11-01 Thread Georg Brandl
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi all,

I'm happy to announce the release of Sphinx 1.1.1, a bug-fix release
in the 1.1 series, fixing a number of bugs of the initial 1.1 release.

What is it?
===

Sphinx is a tool that makes it easy to create intelligent and beautiful
documentation for Python projects (or other documents consisting of
multiple reStructuredText source files).

Website: http://sphinx.pocoo.org/

cheers,
Georg
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.18 (GNU/Linux)

iEYEARECAAYFAk6wBcsACgkQN9GcIYhpnLBZ9ACgqRh4+UDIHYeWP+8qWumAGTNA
e8sAn1lfnSzg54a3JpDu6b+2OBxxq9gi
=9opx
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


IMDbPY 4.8

2011-11-01 Thread Davide Alberani
IMDbPY 4.8 is available (tgz, rpm, exe) from:
  http://imdbpy.sourceforge.net/

IMDbPY is a Python package useful to retrieve and manage the data of
the IMDb movie database about movies, people, characters and
companies.

This is release contains a lot of bug fixes, and some legacy code
was removed.
With the new release, we also have a shiny new website, courtesy
of Alberto Malagoli.

Platform-independent and written in pure Python (and few C lines),
IMDbPY can retrieve data from both the IMDb's web server and a local
copy of the whole database.

IMDbPY package can be very easily used by programmers and developers
to provide access to the IMDb's data to their programs.
Some simple example scripts are included in the package; other
IMDbPY-based programs are available from the home page.

--
Davide Alberani
http://www.mimante.net/
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: Efficient, built-in way to determine if string has non-ASCII chars outside ASCII 32-127, CRLF, Tab?

2011-11-01 Thread Steven D'Aprano
On Mon, 31 Oct 2011 20:44:45 -0400, Terry Reedy wrote:

[...]
 def is_ascii_text(text):
  for c in text:
  if c not in LEGAL:
  return False
  return True
 
 If text is 3.x bytes, this does not work ;-). OP did not specify bytes
 or unicode or Python version.

The OP specified *string*. Whether that's a byte-string in Python 2, or a 
unicode string in Python 3, it will still work, so long as both `text` 
and `LEGAL` are strings.

[steve@sylar ~]$ python2 -c print 'a' in 'abc'  # both byte strings
True
[steve@sylar ~]$ python2 -c print u'a' in u'abc'  # both unicode strings
True
[steve@sylar ~]$ python3 -c print('a' in 'abc')  # both unicode strings
True

Mixing bytes and characters may or may not do what you expect.

[steve@sylar ~]$ python2 -c print 'a' in u'abc'  # one of each
True

Whether that's a good thing or a bad thing is open for debate :)


 Algorithmically, that's as efficient as possible:
 
 This is a bit strange since you go on to explain that it is inefficient
 -- O(n*k) where n = text length and k = legal length -- whereas below is
 O(n).

But since k is a constant, O(nk) is O(n).

When using Big Oh notation, it is acceptable to hand-wave away a lot of 
detail. For example, it's common to assume that n+7, n//7 and n**7 all 
take the same constant amount of time, which is patently untrue: division 
and exponentiation both require more work than addition. In this case, 
relative to the size of the input text, both a linear string search and a 
constant-time hash lookup are O(1). That doesn't imply that they 
*literally* take constant time.

[...]
 Since all() is guaranteed to keep short-cut semantics, that will be as
 fast as possible in Python,
 
 A dangerous statement to make.

I like living dangerously :)

 'c in legal' has to get hash(c) and look
 that up in the hash table, possible skipping around a bit if t If text
 is byte string rather than unicode, a simple lookup 'mask[c]', where
 mask is a 0-1 byte array, should be faster (see my other post).

Oooh, clever! I like! It's not necessary to assume bytes, nor is it 
necessary to create a bitmask the size of the entire Unicode range. 
Here's a version for strings (bytes or unicode in Python 2, unicode in 
Python 3):

LEGAL = ''.join(chr(n) for n in range(32, 128)) + '\n\r\t\f'
MASK = ''.join('\01' if chr(n) in LEGAL else '\0' for n in range(128))

# Untested
def is_ascii_text(text):
for c in text:
n = ord(c)
if n = len(MASK) or MASK[n] == '\0': return False
return True


Optimizing it is left as an exercise :)

I *suspect*, even with any optimizations, that this will be slower than 
the version using a set.

 On my
 new Pentium Win 7 machine, it is -- by albout 5%. For 100,000,000 legal
 bytes, a minimum of 8.69 versus 9.17 seconds.

On my old Linux box, I get the opposite result: set lookup is a tiny bit 
faster, coincidentally also by almost 5%.


 from time import time
 legal_set = frozenset(range(32, 128))
 text = b'a' * 1
 t = time(); all(c in legal_set for c in text); time()-t
True
27.174341917037964
 
 legal_ray = 128 * b'\1'
 t = time(); all(legal_ray[c] for c in text); time()-t
True
28.39691996574402




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


Re: Efficient, built-in way to determine if string has non-ASCII chars outside ASCII 32-127, CRLF, Tab?

2011-11-01 Thread Steven D'Aprano
On Mon, 31 Oct 2011 22:12:26 -0400, Dave Angel wrote:

 I would claim that a well-written (in C) translate function, without
 using the delete option, should be much quicker than any python loop,
 even if it does copy the data.

I think you are selling short the speed of the Python interpreter. Even 
for short strings, it's faster to iterate over a string in Python 3 than 
to copy it with translate:

 from timeit import Timer
 t1 = Timer('for c in text: pass', 'text = abcd')
 t2 = Timer('text.translate(mapping)', 
... 'text = abcd; mapping = .maketrans(, )')
 min(t1.repeat())
0.450606107711792
 min(t2.repeat())
0.9279451370239258


 Incidentally, on the Pentium family,
 there's a machine instruction for that, to do the whole loop in one
 instruction (with rep prefix).

I'm pretty sure that there isn't a machine instruction for copying an 
entire terabyte of data in one step. Since the OP explicitly said he was 
checking text up to a TB in size, whatever solution is used has to scale 
well.



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


Re: Efficient, built-in way to determine if string has non-ASCII chars outside ASCII 32-127, CRLF, Tab?

2011-11-01 Thread Peter Otten
Steven D'Aprano wrote:

 On Mon, 31 Oct 2011 22:12:26 -0400, Dave Angel wrote:
 
 I would claim that a well-written (in C) translate function, without
 using the delete option, should be much quicker than any python loop,
 even if it does copy the data.
 
 I think you are selling short the speed of the Python interpreter. Even
 for short strings, it's faster to iterate over a string in Python 3 than
 to copy it with translate:
 
 from timeit import Timer
 t1 = Timer('for c in text: pass', 'text = abcd')
 t2 = Timer('text.translate(mapping)',
 ... 'text = abcd; mapping = .maketrans(, )')
 min(t1.repeat())
 0.450606107711792
 min(t2.repeat())
 0.9279451370239258

Lies, damn lies, and benchmarks ;)

Copying is fast:

 Timer(text + 'x', text='abcde '*10**6).timeit(100)
1.819761037826538
 Timer(for c in text: pass, text='abcde '*10**6).timeit(100)
18.89239192008972

The problem with str.translate() (unicode.translate() in 2.x) is that it 
needs a dictionary lookup for every character. However, if like the OP you 
are going to read data from a file to check whether it's (a subset of) 
ascii, there's no point converting to a string, and for bytes (where a 
lookup table with the byte as an index into that table can be used) the 
numbers look quite different:

 t1 = Timer(for c in text: pass, text = b'abcd '*10**6)
 t1.timeit(100)
15.818882942199707
 t2 = Timer(text.translate(mapping), text = b'abcd '*10**6; mapping = 
b''.maketrans(b'', b''))
 t2.timeit(100)
2.821769952774048


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


Re: proving two formula are same each other!

2011-11-01 Thread Dave Angel

On 11/01/2011 08:03 AM, pyman wrote:

hello, I need some idea to prove two formula is same. if N = 3, these
formula are same each other. each formula has 3 input . To prove this,
drawing shape or anything would be possible. how can I do this? please
give me your idea!

for example:
N = 1 : formula1 has a, b, c input value, formula2 has d, e, f input
value and each formula's output are different.
N = 2 : formula1 has a, b, c input value, formula2 has d, e, f input
value and each formula's output are different.
N = 3 : formula1 has a, b, c input value, formula2 has d, e, f input
value and each formula's output are SAME.

Wonjun, Choi
Python doesn't have formulae, it has functions and methods.  So you have 
to describe more completely what kind of formula you have, math, 
physics, chemistry?  And how is one different than the next?  And how 
can a formula with 3 input use four values, N, a,. b, and c ?


Please be more specific, and maybe somebody can help.

--

DaveA

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


Re: proving two formula are same each other!

2011-11-01 Thread Dave Angel
(You forgot to do a REPLY-ALL, so that your message didn't get sent to 
the list)





  Python doesn't have formulae, it has functions and methods.  So you have

to describe more completely


what kind of formula you have, math, physics, chemistry?

the formula is related to math.



  And how is one different than the next?



these formula are completely different each other  and it is custom
formula.
for example, when I put 3 input into A formula, it outputs 1 result.
and when I put 3 input into B formula, it outputs 1 result
so each formula have 3 input for example

A formula : f(x,y,z)=3x+4y+2z+3
B formula : f(k,j,t)=2k+3j+2t+1

this formula is different each other which has 3 input.
and have only 1 result

and if I loop this formula from 0 to N(for example : N = 3)
if N=1, the result will be different each other. and N=2 too.
but when N=3, the result will be same each other.


Since N isn't a parameter to either function, the results can never change.


so I wanted to prove this. by drawing shape or something so that children
can be understand easily.








I'm still trying to help you clarify your problem, but you are getting 
much closer.  Those two formulae take three arguments (although you 
should use the same name for the arguments if the comparison is to mean 
anything).  N doesn't come into it at all.


Perhaps by N you mean tuples like  (2,1,1) and (4,2,1), and you want to 
know for which tuples the result will be the same.


That could be represented by some 4 dimensional graph, but I don't know 
any graphing package that could show it, in python or otherwise.



--

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


Support for Galois/Counter Mode (GCM) ?

2011-11-01 Thread Roland Hedberg
Hi !

Is there a crypto library for Python that has support for GCM ??

-- Roland



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


sending more then 2 messages to SocketServer fasils

2011-11-01 Thread MrSmile
Hi people!
I have asked myself why I am not capable sending 2 messages a time to a
Socketserver. Why is that?!


Here the Server:

import SocketServer
from ast import literal_eval

class MKTest(object):
DSX = []
MKTestInst = None

def __init__(self,Daten):
MKTest.DSX.append(Daten)

def getObj(Daten):
if MKTest.MKTestInst == None:
MKTest.MKTestInst = MKTest(Daten)
return MKTest.MKTestInst

getObj = staticmethod(getObj)

class MySockX(SocketServer.BaseRequestHandler):
def handle(self):
data = self.request.recv(1024)
data = literal_eval(data)
#MKTest.getObj(data[0])
#MKObj = MKTest(data[0])
MKObj = MKTest.getObj(data[0])
data = MKTest.DSX
data = '%s' % data
self.request.send(data)

if __name__ == __main__:
HOST, PORT = localhost, 
server = SocketServer.TCPServer((HOST,PORT),MySockX)
server.serve_forever()



and the client:

import socket

data = [100]
received = [None,None]
HOST,PORT = localhost,
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((HOST, PORT))
sock.send('%s' % data)
received[0] = sock.recv(1024)
sock.send('%s' % data)
received[1] = sock.recv(1024)
sock.close()

print received



The result is:

['[100]', '']



who can help me solving this problem



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


Assign values from list to list of instances

2011-11-01 Thread Gnarlodious
I want to assign a list of variables:
locus=[-2, 21, -10, 2, 12, -11, 0, 3]

updating a list of objects each value to its respective instance:

for order in range(len(Orders)):
Orders[order].locus=locus[order]

This works, even though it reads like doggerel. Is there a more
pythonesque way using map or comprehension?

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


sending more then 2 messages at a time to a SocketServer fails

2011-11-01 Thread MrSmile
Hi people!
I have asked myself why I am not capable sending 2 messages a time to a
Socketserver. Why is that?!


Here the Server:

import SocketServer
from ast import literal_eval

class MKTest(object):
DSX = []
MKTestInst = None

def __init__(self,Daten):
MKTest.DSX.append(Daten)

def getObj(Daten):
if MKTest.MKTestInst == None:
MKTest.MKTestInst = MKTest(Daten)
return MKTest.MKTestInst

getObj = staticmethod(getObj)

class MySockX(SocketServer.BaseRequestHandler):
def handle(self):
data = self.request.recv(1024)
data = literal_eval(data)
#MKTest.getObj(data[0])
#MKObj = MKTest(data[0])
MKObj = MKTest.getObj(data[0])
data = MKTest.DSX
data = '%s' % data
self.request.send(data)

if __name__ == __main__:
HOST, PORT = localhost, 
server = SocketServer.TCPServer((HOST,PORT),MySockX)
server.serve_forever()



and the client:

import socket

data = [100]
received = [None,None]
HOST,PORT = localhost,
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((HOST, PORT))
sock.send('%s' % data)
received[0] = sock.recv(1024)
sock.send('%s' % data)
received[1] = sock.recv(1024)
sock.close()

print received



The result is:

['[100]', '']



who can help me solving this problem



Tamer

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


Re: Assign values from list to list of instances

2011-11-01 Thread Peter Otten
Gnarlodious wrote:

 I want to assign a list of variables:
 locus=[-2, 21, -10, 2, 12, -11, 0, 3]
 
 updating a list of objects each value to its respective instance:
 
 for order in range(len(Orders)):
 Orders[order].locus=locus[order]
 
 This works, even though it reads like doggerel. Is there a more
 pythonesque way using map or comprehension?

for order, place in zip(Orders, locus):
order.locus = place


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


Re: Assign values from list to list of instances

2011-11-01 Thread Dave Angel

On 11/01/2011 11:05 AM, Gnarlodious wrote:

I want to assign a list of variables:
locus=[-2, 21, -10, 2, 12, -11, 0, 3]

updating a list of objects each value to its respective instance:

for order in range(len(Orders)):
Orders[order].locus=locus[order]

This works, even though it reads like doggerel. Is there a more
pythonesque way using map or comprehension?

-- Gnarlie



You can do that with the enumerate function, or with zip
 for index, instance in enumerate(Orders):
   instance.locus = locus[index]

 for instance, place  in zip(Orders, locus):
   instance.locus = locus[index]

It would be clearer if you used singular for individual items, and 
plural for the collections,


loci  [-2, 21, 
orders = [list of order objects ...]

for order, locus in zip(orders, loci):
  order.locus = locus


--

DaveA

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


Re: Assign values from list to list of instances

2011-11-01 Thread duncan smith

On 01/11/11 15:05, Gnarlodious wrote:

I want to assign a list of variables:
locus=[-2, 21, -10, 2, 12, -11, 0, 3]

updating a list of objects each value to its respective instance:

for order in range(len(Orders)):
Orders[order].locus=locus[order]

This works, even though it reads like doggerel. Is there a more
pythonesque way using map or comprehension?



for obj, val in zip(Orders, locus):
 obj.locus = val


I'm not sure how worthwhile it is converting the above to a list 
comprehension (when the list would just be thrown away). Having said 
that the call to zip creates an unnecessary list. You could use izip or 
maybe,


for i, val in enumerate(locus):
Orders[i].locus = val

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


modified legend appears out of view! It didn't used to. MWE included.

2011-11-01 Thread cpbl
I seem to be using
Python 2.7.2+
(latest update of Ubuntu). The following code used to work nicely, but
now gives me an unreadable legend. The legend is showing up mostly out
of view below and to the left of the figure. Does that happen for you?
Is there a regression bug, or am I doing something wrong?
The MWE below is adapted from a function I wrote to allow addition of
extra comments within a legend box below the normal legend details.
Thanks for any help!
Chris

!/usr/bin/python

import pylab as plt

from matplotlib.offsetbox import TextArea, VPacker
comments='foodlefish'
plt.figure(1)
plt.plot([1,2],[3,4], label='test')
lh=plt.legend(fancybox=True,shadow=False,title='Foodle',loc='best')
if lh:
lh.get_frame().set_alpha(0.5)
fontsize=lh.get_texts()[0].get_fontsize()
legendcomment=TextArea('\n'.join(comments),
textprops=dict(size=fontsize))
lh._legend_box = VPacker(pad=5,
 sep=0,
 children=[lh._legend_box,legendcomment],
 align=right)  # Or should it be centre?
lh._legend_box.set_figure(plt.gcf())

plt.show()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C API: Making a context manager

2011-11-01 Thread Stefan Behnel

Chris Kaynor, 31.10.2011 19:34:

I am currently rewritting a class using the Python C API to improve
performance of it, however I have not been able to find any
documentation about how to make a context manager using the C API.


You should take a look at Cython. It makes these things *so* much easier.



The code I am working to produce is the following (its a method of a class):

@contextlib.contextmanager
def connected(self, *args, **kwargs):
connection = self.connect(*args, **kwargs)
try:
yield
finally:
connection.disconnect()


You can use the above in Cython code unmodified, and it's likely going to 
be good enough (depending on what kind of connection we are talking about 
here).


In case that's also performance critical, however, it's likely faster to 
spell it out as a class, i.e.


...
def connected(self, *args, **kwargs):
return ConnectionManager(self, args, kwargs)


cdef class ConnectionManager:
cdef object args, kwargs, connection, connect

def __init__(self, connector, args, kwargs):
self.args, self.kwargs = args, kwargs
self.connect = connector.connect
def __enter__(self):
self.connection = self.connect(*self.args, **self.kwargs)
def __exit__(self, *exc):
self.connection.disconnect()
return True # or False? I always forget which means what

Not that much longer either.

Stefan

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


Re: sending more then 2 messages at a time to a SocketServer fails

2011-11-01 Thread Miki Tebeka
MKTest.getObj(data[0]) will return the same object on every call(with the same 
data that was initialized 1'st time). Any Daten parameter after the 1'st call 
is ignored.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Assign values from list to list of instances

2011-11-01 Thread Ulrich Eckhardt

Am 01.11.2011 16:05, schrieb Gnarlodious:

I want to assign a list of variables:
locus=[-2, 21, -10, 2, 12, -11, 0, 3]

updating a list of objects each value to its respective instance:

for order in range(len(Orders)):
Orders[order].locus=locus[order]

This works, even though it reads like doggerel. Is there a more
pythonesque way using map or comprehension?


Use enumerate:

for object, index in enumerate(Orders):
object.locus = locus[index]


I'm not 100% I understood your description though, but it looks like 
this would do what you want and be descriptive at the same time.


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


Re: C API: Making a context manager

2011-11-01 Thread Chris Kaynor
On Tue, Nov 1, 2011 at 8:57 AM, Stefan Behnel stefan...@behnel.de wrote:
 Chris Kaynor, 31.10.2011 19:34:

 I am currently rewritting a class using the Python C API to improve
 performance of it, however I have not been able to find any
 documentation about how to make a context manager using the C API.

 You should take a look at Cython. It makes these things *so* much easier.

Unfortunately, all of the code has to be fully compatible with CPython
2.6 - it needs to function inside of Maya, which has CPython 2.6
embedded, and to which we do not have the source code.

While not all parts of our code base are used inside of Maya, most of
the performance-critical items are to some degree or another.

In this particular case, the connected context manager is not heavily
used (outside of unittests) and itself is not performance critical,
but the much of the rest of the package (and thus the class) it is
part of is.

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


Does anyone use Python Tools for visual studio?

2011-11-01 Thread Wei
I got several buggy things going on.
First, the view of class tree stops expanding after creating more than
two classes.
Second, after 800 lines of code the classes and methods can't be
folded. (meaning the + sign is gone)
P.S. there is no warning or errors in my code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C API: Making a context manager

2011-11-01 Thread Stefan Behnel

Chris Kaynor, 01.11.2011 17:19:

On Tue, Nov 1, 2011 at 8:57 AM, Stefan Behnel wrote:

Chris Kaynor, 31.10.2011 19:34:

I am currently rewritting a class using the Python C API to improve
performance of it, however I have not been able to find any
documentation about how to make a context manager using the C API.


You should take a look at Cython. It makes these things *so* much easier.


Unfortunately, all of the code has to be fully compatible with CPython
2.6 - it needs to function inside of Maya, which has CPython 2.6
embedded, and to which we do not have the source code.


This sounds like you're misunderstanding what Cython is. Cython compiles 
(and optimises) your Python code into fast C code that uses the C-API (and 
that can happily call into external C code etc.). So you get basically the 
same (and sometimes better) speed, but without all the C-level hassle and 
maintenance issues. The C code that Cython generates is fully compatible 
with CPython 2.4 up to the latest 3.3, and that includes 2.6.




While not all parts of our code base are used inside of Maya, most of
the performance-critical items are to some degree or another.

In this particular case, the connected context manager is not heavily
used (outside of unittests) and itself is not performance critical,
but the much of the rest of the package (and thus the class) it is
part of is.


In that case, I advise you to leave the context manager code as is, and 
just compile the module that you are trying to speed up (and which, IIUC is 
currently written in Python) with Cython, then optimise the parts of it 
that need more speed by injecting static typing. Here's a quick howto:


http://docs.cython.org/src/quickstart/cythonize.html

Stefan

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


Re: Does anyone use Python Tools for visual studio?

2011-11-01 Thread Wei
On Nov 1, 12:57 pm, Wei chen.1...@gmail.com wrote:
 I got several buggy things going on.
 First, the view of class tree stops expanding after creating more than
 two classes.
 Second, after 800 lines of code the classes and methods can't be
 folded. (meaning the + sign is gone)
 P.S. there is no warning or errors in my code.

Also, I am using 64 bit win7 professional.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Module for Python and SGE interaction

2011-11-01 Thread Abhishek Pratap
Hey Guys

Pushing this one again just in case it was missed last night.

Best,
-Abhi

On Mon, Oct 31, 2011 at 10:31 PM, Abhishek Pratap abhishek@gmail.comwrote:

 Hey Guys

 I shud mention I am relative new to the language. Could you please let me
 know based on your experience which module could help me with farm out jobs
 to our existing clusters(we use SGE here) using python.

 Ideally I would like to do the following.

 1. Submit #N jobs to cluster
 2. monitor their progress
 3. When all #N finishes, push another set of jobs

 Thanks!
 -Abhi

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


Re: sending more then 2 messages at a time to a SocketServer fails

2011-11-01 Thread MRAB

On 01/11/2011 15:07, MrSmile wrote:

Hi people!
I have asked myself why I am not capable sending 2 messages a time to a
Socketserver. Why is that?!


Here the Server:

import SocketServer
from ast import literal_eval

class MKTest(object):
 DSX = []
 MKTestInst = None

 def __init__(self,Daten):
 MKTest.DSX.append(Daten)

 def getObj(Daten):
 if MKTest.MKTestInst == None:
 MKTest.MKTestInst = MKTest(Daten)
 return MKTest.MKTestInst

 getObj = staticmethod(getObj)

class MySockX(SocketServer.BaseRequestHandler):
 def handle(self):
 data = self.request.recv(1024)
 data = literal_eval(data)
 #MKTest.getObj(data[0])
 #MKObj = MKTest(data[0])
 MKObj = MKTest.getObj(data[0])
 data = MKTest.DSX
 data = '%s' % data
 self.request.send(data)

if __name__ == __main__:
 HOST, PORT = localhost, 
 server = SocketServer.TCPServer((HOST,PORT),MySockX)
 server.serve_forever()


[snip]

I think that in the 'handle' function you should be putting the code in
a 'while' loop:

 def handle(self):
 # The client has opened a socket to the server.
 while True:
 data = self.request.recv(1024)
 if not data:
 # The client has closed the socket to the server.
 break
 ...
--
http://mail.python.org/mailman/listinfo/python-list


Sort items in wxListCtrl

2011-11-01 Thread Ric

I am trying to create a small application in wxPython and would like
to ask for some help.

I am trying to display folders and  files in ListCtrl but sorted first
folders followed by files (like in a file manager style) but not sure
how to do this? Would I need to do this in code somehow or ListCtrl
would help me?

I am trying to do this and learn at the same time.

Would appreciate any advice. Thank you. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient, built-in way to determine if string has non-ASCII chars outside ASCII 32-127, CRLF, Tab?

2011-11-01 Thread Duncan Booth
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:

 LEGAL = ''.join(chr(n) for n in range(32, 128)) + '\n\r\t\f'
 MASK = ''.join('\01' if chr(n) in LEGAL else '\0' for n in range(128))
 
 # Untested
 def is_ascii_text(text):
 for c in text:
 n = ord(c)
 if n = len(MASK) or MASK[n] == '\0': return False
 return True
 
 
 Optimizing it is left as an exercise :)
 

#untested
LEGAL = ''.join(chr(n) for n in range(32, 128)) + '\n\r\t\f'
MASK = [True if chr(n) in LEGAL else False for n in range(128)]

# Untested
def is_ascii_text(text):
  try:
return all(MASK[ord(c)] for c in text)
  except IndexError:
return False


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


Re: sending more then 2 messages at a time to a SocketServer fails

2011-11-01 Thread Tamer Higazi
Am 01.11.2011 17:13, schrieb Miki Tebeka:
 MKTest.getObj(data[0]) will return the same object on every call(with the 
 same data that was initialized 1'st time). Any Daten parameter after the 1'st 
 call is ignored.


Not true!
The singleton object has nothing todo. Here one more example for you:

Client:

import socket

data = ['Tamer']
received = [None,None]
HOST,PORT = localhost,
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((HOST, PORT))
sock.send('%s' % data)
received[0] = sock.recv(1024)
sock.send('%s' % data)
received[1] = sock.recv(1024)
sock.close()

print received


Server:

import SocketServer
from ast import literal_eval

class MySockX(SocketServer.BaseRequestHandler):
def handle(self):
data = self.request.recv(1024)
data = literal_eval(data)
data = '%s' % data[0]
self.request.send('%s %s' % ('Halloaaa',data))

if __name__ == __main__:
HOST, PORT = localhost, 
server = SocketServer.TCPServer((HOST,PORT),MySockX)
server.serve_forever()



with it's result:

['Halloaaa Tamer', '']



the 2nd argument from the list is EMPTY. Now tell me why?!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does anyone use Python Tools for visual studio?

2011-11-01 Thread Tamer Higazi
buy wingIDE or use PyDEV

If you tell me that you are using IronPython then buy wingIDE, there you
can make use of the .net classes in python too.


Tamer


Am 01.11.2011 18:01, schrieb Wei:
 On Nov 1, 12:57 pm, Wei chen.1...@gmail.com wrote:
 I got several buggy things going on.
 First, the view of class tree stops expanding after creating more than
 two classes.
 Second, after 800 lines of code the classes and methods can't be
 folded. (meaning the + sign is gone)
 P.S. there is no warning or errors in my code.
 
 Also, I am using 64 bit win7 professional.

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


Re: Efficient, built-in way to determine if string has non-ASCII chars outside ASCII 32-127, CRLF, Tab?

2011-11-01 Thread Ian Kelly
On Mon, Oct 31, 2011 at 6:32 PM, Patrick Maupin pmau...@gmail.com wrote:
 On Oct 31, 5:52 pm, Ian Kelly ian.g.ke...@gmail.com wrote:
 For instance, split() will split on vertical tab,
 which is not one of the characters the OP wanted.

 That's just the default behavior.  You can explicitly specify the
 separator to split on.  But it's probably more efficient to just use
 translate with deletechars.

As I understood it, the point of using the default behavior was to
merge whitespace, which cannot be done when the separator is
explicitly specified.  For example:

  .split()
[]
  .split( )
['', '', '', '', '', '']

It is easy to check that the first is empty.  The second is a bit more
annoying and is O(n).  Your point about deletechars is good, though,
definitely better than a regular expression.
-- 
http://mail.python.org/mailman/listinfo/python-list


understand program used to create file

2011-11-01 Thread pacopyc
Hi, I have about 1 files .doc and I want know the program used to
create them: writer? word? abiword? else? I'd like develop a script
python to do this. Is there a module to do it? Can you help me?

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


Re: getting columns attributes in declarative style with sqlalchemy

2011-11-01 Thread tres . bailey
Sorry for the repost, if it does in fact repost.

I'm no SQLAlchemy expert, but I have used the Table and Column attribute 
objects from the model object to solve a similar problem in the past.  You can 
use the following syntax to do it:

[col.name for col in Country.__table__.columns._all_cols]

which should return you a list of ['cancelled', 'description'].  You can find 
more information on the attributes you are using here:
http://www.sqlalchemy.org/docs/core/schema.html?highlight=schema.column#sqlalchemy.schema.Column

and 
http://www.sqlalchemy.org/docs/core/schema.html?highlight=schema.table#sqlalchemy.schema.Table
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient, built-in way to determine if string has non-ASCII chars outside ASCII 32-127, CRLF, Tab?

2011-11-01 Thread MRAB

On 01/11/2011 18:54, Duncan Booth wrote:

Steven D'Apranosteve+comp.lang.pyt...@pearwood.info  wrote:


LEGAL = ''.join(chr(n) for n in range(32, 128)) + '\n\r\t\f'
MASK = ''.join('\01' if chr(n) in LEGAL else '\0' for n in range(128))

# Untested
def is_ascii_text(text):
 for c in text:
 n = ord(c)
 if n= len(MASK) or MASK[n] == '\0': return False
 return True


Optimizing it is left as an exercise :)



#untested
LEGAL = ''.join(chr(n) for n in range(32, 128)) + '\n\r\t\f'
MASK = [True if chr(n) in LEGAL else False for n in range(128)]


Instead of:

True if chr(n) in LEGAL else False

why not:

if chr(n) in LEGAL


# Untested
def is_ascii_text(text):
   try:
 return all(MASK[ord(c)] for c in text)
   except IndexError:
 return False


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


Re: getting columns attributes in declarative style with sqlalchemy

2011-11-01 Thread tres . bailey
Hi Gabriele,

I'm not an Alchemy expert, but I have used the ColumnProperty of the 
model/column objects to solve this problem in the past.  So to get the column 
name for the description column in your example above, you would use the 
following syntax:

Country.description.property.columns[0].name

And this would avoid having to use additional objects than the one you're 
working on.  The ColumnProperty object (and the Column object attribute it 
contains) will provide you with information such as column name, type, default 
vals, primary_key, and nullable.  You could also get more generic by iterating 
through your model object's __table__ attribute and grab each column:

[col.name for col in Country.__table__.columns._all_cols]


More information can be found here:
http://www.sqlalchemy.org/docs/core/schema.html?highlight=schema.column#sqlalchemy.schema.Column
and
http://www.sqlalchemy.org/docs/orm/internals.html?highlight=columnproperty#sqlalchemy.orm.properties.ColumnProperty

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


Re: Efficient, built-in way to determine if string has non-ASCII chars outside ASCII 32-127, CRLF, Tab?

2011-11-01 Thread Stefan Behnel

pyt...@bdurham.com, 31.10.2011 20:54:

Wondering if there's a fast/efficient built-in way to determine
if a string has non-ASCII chars outside the range ASCII 32-127,
CR, LF, or Tab?

I know I can look at the chars of a string individually and
compare them against a set of legal chars using standard Python
code (and this works fine), but I will be working with some very
large files in the 100's Gb to several Tb size range so I'd
thought I'd check to see if there was a built-in in C that might
handle this type of check more efficiently.

Does this sound like a use case for cython or pypy?


Cython. For data of that size, likely read from a fast local RAID drive I 
guess, you certainly don't want to read (part of) the file into a memory 
buffer, then copy that memory buffer into a Python bytes string, and then 
search it character by character, copying each of the characters into a new 
string object just to compare them.


Instead, you'd want to use low-level I/O to read a not-so-small part of the 
file into a memory buffer, run through it looking for unwanted characters, 
and then read the next chunk, without any further copying. The comparison 
loop could look like this, for example:


cdef unsigned char current_byte
cdef unsigned char* byte_buffer = libc.stdlib.malloc(BUFFER_SIZE)

# while read chunk ...
for current_byte in byte_buffer[:BUFFER_SIZE]:
if current_byte  32 or current_byte  127:
if current_byte not in b'\t\r\n':
raise ValueError()

What kind of I/O API you use is up to you. You may want to use the 
functions declared in libc.stdio (ships with Cython).


Stefan

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


Re: understand program used to create file

2011-11-01 Thread Dave Angel

On 11/01/2011 03:27 PM, pacopyc wrote:

Hi, I have about 1 files .doc and I want know the program used to
create them: writer? word? abiword? else? I'd like develop a script
python to do this. Is there a module to do it? Can you help me?

Thanks
If you're on Linux, just use the process module to invoke file and 
examine the results.


If you're not, then be more specific about the environment.

--

DaveA

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


Re: When I use Python under Windows. I found some file handles are not closed,

2011-11-01 Thread Gabriel Genellina
En Mon, 31 Oct 2011 12:57:15 -0300, 罗勇刚(Yonggang Luo)   
luoyonggang-re5jqeeqqe8avxtiumw...@public.gmane.org escribió:


How did detecting where those handlers are created to tracing it and  
close

it.
Mainly because I was using C binding library(subvertpy) and file is not
closed.


A better place to ask is python-list@python.org

Please include the Python version you're using. Also, a small, complete,  
runnable code example showing the problem would be very valuable. Usually,  
in building such example, you may well find out where your problem is.


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


Re: Efficient, built-in way to determine if string has non-ASCII chars outside ASCII 32-127, CRLF, Tab?

2011-11-01 Thread Duncan Booth
MRAB pyt...@mrabarnett.plus.com wrote:

 On 01/11/2011 18:54, Duncan Booth wrote:
 Steven D'Apranosteve+comp.lang.pyt...@pearwood.info  wrote:

 LEGAL = ''.join(chr(n) for n in range(32, 128)) + '\n\r\t\f'
 MASK = ''.join('\01' if chr(n) in LEGAL else '\0' for n in range
(128))

 # Untested
 def is_ascii_text(text):
  for c in text:
  n = ord(c)
  if n= len(MASK) or MASK[n] == '\0': return False
  return True


 Optimizing it is left as an exercise :)


 #untested
 LEGAL = ''.join(chr(n) for n in range(32, 128)) + '\n\r\t\f'
 MASK = [True if chr(n) in LEGAL else False for n in range(128)]

 Instead of:
 
  True if chr(n) in LEGAL else False
 
 why not:
 
  if chr(n) in LEGAL
 
I think you meant to drop the 'if' also.

MASK = [chr(n) in LEGAL for n in range(128)]

But yes, I was concentrating on the function body rather than the 
initialisation.

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


Re: understand program used to create file

2011-11-01 Thread Chris Angelico
On Wed, Nov 2, 2011 at 6:27 AM, pacopyc paco...@gmail.com wrote:
 Hi, I have about 1 files .doc and I want know the program used to
 create them: writer? word? abiword? else? I'd like develop a script
 python to do this. Is there a module to do it? Can you help me?


Technically, you can't find out just from the file what it was that
created it. But if you mean figure out what type of file each one is
(eg recognize an ODF, a PDF, a DOC, etc), then the easiest way is to
read in the first few bytes of the file and look for well-known magic
numbers[1]. As Dave says, Linux comes with a command that does exactly
that (and a bit more), called 'file'.

ChrisA
[1] http://en.wikipedia.org/wiki/Magic_number_(programming)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: understand program used to create file

2011-11-01 Thread Jon Clements
On Nov 1, 7:27 pm, pacopyc paco...@gmail.com wrote:
 Hi, I have about 1 files .doc and I want know the program used to
 create them: writer? word? abiword? else? I'd like develop a script
 python to do this. Is there a module to do it? Can you help me?

 Thanks

My suggestion would be the same as DaveA's.

This gives you the format it was *written* in.
(Saved a blank OO document as 95/97/XP Word DOC under Linux)

jon@forseti:~/filetest$ file *
saved-by-OO.doc: CDF V2 Document, Little Endian, Os: Windows, Version
1.0, Code page: -535, Author: jon , Revision Number: 0, Create Time/
Date: Mon Oct 31 20:47:30 2011

I'd be impressed if you could discover the program that did *write*
it; I'd imagine you'd need something that understood some meta-data in
the format (if the format has a kind of 'created_by' field, for
instance), or depend on nuisances which give away that a certain
program wrote data in another's native format.

Assuming the former, what might be possible:

1) Grab a magic number lookup list
2) Grab 8 (I think that should be all that's needed, but hey ummm..)
bytes from the start of each file
3) Look it up in the magic number list
4) If you got something great, if not compare 7, 6, 5, 4 bytes...
etc... until you get a hit or bail out

(Or just find a Windows port of 'file')

HTH

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


Re: Does anyone use Python Tools for visual studio?

2011-11-01 Thread Brian Curtin
On Tue, Nov 1, 2011 at 11:57, Wei chen.1...@gmail.com wrote:
 I got several buggy things going on.
 First, the view of class tree stops expanding after creating more than
 two classes.
 Second, after 800 lines of code the classes and methods can't be
 folded. (meaning the + sign is gone)
 P.S. there is no warning or errors in my code.
 --
 http://mail.python.org/mailman/listinfo/python-list


Yes, I use it. If you're having issues with it, you should report them
at http://pytools.codeplex.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Assign values from list to list of instances

2011-11-01 Thread Terry Reedy

On 11/1/2011 11:37 AM, duncan smith wrote:

On 01/11/11 15:05, Gnarlodious wrote:

I want to assign a list of variables:
locus=[-2, 21, -10, 2, 12, -11, 0, 3]

updating a list of objects each value to its respective instance:

for order in range(len(Orders)):
Orders[order].locus=locus[order]

This works, even though it reads like doggerel. Is there a more
pythonesque way using map or comprehension?



for obj, val in zip(Orders, locus):
obj.locus = val


I'm not sure how worthwhile it is converting the above to a list
comprehension (when the list would just be thrown away). Having said
that the call to zip creates an unnecessary list.


Not in Py 3

--
Terry Jan Reedy

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


parsing text from ethtool command

2011-11-01 Thread extraspecialbitter
I'm still trying to write that seemingly simple Python script to print
out network interfaces (as found in the ifconfig -a command) and
their speed (ethtool interface).  The idea is to loop for each
interface and
print out its speed.  I'm looping correctly, but have some issues
parsing the output for all interfaces except for the pan0
interface.  I'm running on eth1, and the ifconfig -a command also
shows an eth0, and of course lo.  My script is trying to match on the
string Speed, but I never seem to successfully enter the if
clause.

First, here is the output of ethtool eth1:

=

Settings for eth1:
Supported ports: [ TP ]
Supported link modes:   10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Supports auto-negotiation: Yes
Advertised link modes:  10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
MDI-X: off
Supports Wake-on: pumbag
Wake-on: g
Current message level: 0x0001 (1)
Link detected: yes

=

The script *should* match on the string Speed and then assign 100Mb/
s to a variable, but is never getting past the second if statement
below:

=

#!/usr/bin/python

# Quick and dirty script to print out available interfaces and their
speed

# Initializations

output =  Interface: %s Speed: %s
noinfo = (Speed Unknown)
speed  = noinfo

import os, socket, types, subprocess

fp = os.popen(ifconfig -a)
dat=fp.read()
dat=dat.split('\n')
for line in dat:
if line[10:20] == Link encap:
   interface=line[:9]
   cmd = ethtool  + interface
   gp = os.popen(cmd)
   fat=gp.read()
   fat=fat.split('\n')
   for line in fat:
   if line[0:6] == Speed:
   try:
   speed=line[8:]
   except:
   speed=noinfo
print output % (interface, speed)

=

Again, I appreciate everyone's patience, as I'm obviously I'm a python
newbie.  Thanks in advance!
-- 
http://mail.python.org/mailman/listinfo/python-list


Chaco for real-time plot of PySerial data

2011-11-01 Thread Jack Keegan
Hi there,

I asked this question on the enthought chaco mailing list some time last by
have yet to receive a reply. Thought I'd ask here to see if anyone could
shed some light on things for me. I have been considering using chaco /
traits for close to a year now and am finally biting the bullet so to
speak. What I would really like to do to begin with is to make a real-time
plotting application which gets its data from the serial port. Can anyone
please point me in the right direction for doing this?

Since I didn't get a reply on the chaco list I'm now thinking it might be a
dangerous route to go down since it will be difficult to get help. Any
recommendations?

Thanks very much,

Jack

-- 
The earth is a very small stage in a vast cosmic arena. Think of the rivers
of blood spilled by all those generals and emperors so that in glory and in
triumph they could become the momentary masters of a fraction of a dot.
- Carl Sagan [Pale Blue Dot]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sort items in wxListCtrl

2011-11-01 Thread Miki Tebeka
Why not use the build in wx.FileDialog?

Also, have a look at the demo that comes with wxPython. It has an example with 
a sortable list control.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parsing text from ethtool command

2011-11-01 Thread Miki Tebeka
In my box, there are some spaces (tabs?) before Speed. IMO re.search(Speed, 
line) will be a more robust.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: proving two formula are same each other!

2011-11-01 Thread Steven D'Aprano
On Tue, 01 Nov 2011 05:03:17 -0700, pyman wrote:

 hello, I need some idea to prove two formula is same.

Impossible. As you explained further on, they are different formula. If 
they are different, they aren't the same. This has nothing to do with 
Python.

In another message, you tell us:

these formula are completely different each other

and give the formula:

A formula : f(x,y,z)=3x+4y+2z+3
B formula : f(k,j,t)=2k+3j+2t+1

Perhaps what you mean is that you want to solve for when the two formula 
give equal results? Here's a simpler example:

f(x) = 2x + 1
g(x) = 3x - 2

Solving for x:

f(x) = g(x)
2x + 1 = 3x - 2
1 = 3x - 2 - 2x
1 + 2 = 3x - 2x
3 = x

so the solution is x = 3, f(3) = 7 = g(3).

This is also not easy, since you have SIX variables (x, y, z, k, j, t) 
and only two equations. This is known as an under-determined system, and 
means that there is no exact solution. Perhaps something like Mathematica 
could do something useful with it?

Is there some way you can use the same variables in each formula? For 
example, if x=t, y=j, z=k (or some other combination), then you have a 
simpler three-dimensional problem:

f(x,y,z) = 3x + 4y + 2z + 3
g(x,y,z) = 2z + 3y + 2x + 1

which is still under-determined, but not as badly (now you have three 
variables and only two equations).

In any case, you *might* be able to solve this using numpy. 

http://numpy.scipy.org/


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


Re: Efficient, built-in way to determine if string has non-ASCII chars outside ASCII 32-127, CRLF, Tab?

2011-11-01 Thread Terry Reedy

On 11/1/2011 2:56 AM, Steven D'Aprano wrote:

On Mon, 31 Oct 2011 20:44:45 -0400, Terry Reedy wrote:

[...]

def is_ascii_text(text):
  for c in text:
  if c not in LEGAL:
  return False
  return True


If text is 3.x bytes, this does not work ;-). OP did not specify bytes
or unicode or Python version.


The OP specified *string*.


A. People sometimes use 'string' loosely, to include text stored in bytes.

B. We are solving slightly different problems. The OP specified 
terabytes of ascii text on disk that he wants to check for 
contamination. For that purpose, using 3.x, it is sensible to read the 
data in binary mode into bytes objects rather than decoding into 
unicode. (The exception would be if the text uses some 7 bit encoding 
like UTF-7. But that is relatively unlikely for disk storage.)


It is irrelevant to that specified purpose whether one calls the 
internal implementation type a 'string' or not. While my 3.2 bytes 
version was only slightly faster, given data in memory, adding decoding 
time for your string version and any other extra overhead for text mode 
reading would make the bytes version look even better.


I am pretty sure the best disk reading speed would come from reading 
blocks of 4k*N, for some N, in binary mode. If the Python code were 
compliled (with Cython, for instance), the process might be input bound, 
depending on the system.



'c in legal' has to get hash(c) and look
that up in the hash table, possible skipping around a bit if t If text
is byte string rather than unicode, a simple lookup 'mask[c]', where
mask is a 0-1 byte array, should be faster (see my other post).


Oooh, clever! I like! It's not necessary to assume bytes, nor is it
necessary to create a bitmask the size of the entire Unicode range.


You are right; I had been thinking it would be.


Here's a version for strings (bytes or unicode in Python 2, unicode in
Python 3):

LEGAL = ''.join(chr(n) for n in range(32, 128)) + '\n\r\t\f'
MASK = ''.join('\01' if chr(n) in LEGAL else '\0' for n in range(128))

# Untested
def is_ascii_text(text):
 for c in text:
 n = ord(c)
 if n= len(MASK) or MASK[n] == '\0': return False
 return True



Optimizing it is left as an exercise :)


The test for n = len() can be accomplished with try:..except IndexError 
around the loop construct. Then the explicit loop can be replaced with 
any(), as before.



I *suspect*, even with any optimizations, that this will be slower than
the version using a set.


If you suspect that because of the need with true 'strings' for 
MASK[ord(c)] instead of MASK[c], you are right. Redoing the test runs 
with unicode strings instead of bytes, the set lookup time is about the 
same (9.2 seconds) whereas the 100 000 000 ord() calls add over 4 
seconds to the MASK lookups, raising them up to 13.1 seconds.


--
Terry Jan Reedy

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


Re: parsing text from ethtool command

2011-11-01 Thread Ian Kelly
On Tue, Nov 1, 2011 at 5:19 PM, Miki Tebeka miki.teb...@gmail.com wrote:
 In my box, there are some spaces (tabs?) before Speed. IMO 
 re.search(Speed, line) will be a more robust.

Or simply:

if Speed in line:

There is no need for a regular expression here.  This would also work
and be a bit more discriminating:

if line.strip().startswith(Speed)

BTW, to the OP, note that your condition (line[0:6] == Speed) cannot
match, since line[0:6] is a 6-character slice, while Speed is a
5-character string.

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


Re: Module for Python and SGE interaction

2011-11-01 Thread Terry Reedy

On 11/1/2011 1:31 PM, Abhishek Pratap wrote:


On Mon, Oct 31, 2011 at 10:31 PM, Abhishek Pratap
abhishek@gmail.com mailto:abhishek@gmail.com wrote:

Hey Guys

I shud mention I am relative new to the language. Could you please
let me know based on your experience which module could help me with
farm out jobs to our existing clusters(we use SGE here) using python.

Ideally I would like to do the following.

1. Submit #N jobs to cluster
2. monitor their progress
3. When all #N finishes, push another set of jobs


Have you searched with Google? on pypi.python.org? with what keywords?

--
Terry Jan Reedy

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


Re: Sort items in wxListCtrl

2011-11-01 Thread Ric
On Tue, 1 Nov 2011 16:14:50 -0700 (PDT), Miki Tebeka
miki.teb...@gmail.com wrote:

Why not use the build in wx.FileDialog?

Also, have a look at the demo that comes with wxPython. It has an example with 
a sortable list control.

Thanks for responding, How would wx.FileDialog help me in this case? I
am trying to display files and directories in the ListCtrl in sorted
way. Folders first followed by files. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sending more then 2 messages to SocketServer fasils

2011-11-01 Thread Roy Smith
In article 4eb00a7a$0$6560$9b4e6...@newsspool4.arcor-online.net,
 MrSmile n...@mail.de wrote:

 Hi people!
 I have asked myself why I am not capable sending 2 messages a time to a
 Socketserver. Why is that?!

There's a lot of confusing code here.  It would help when asking these 
kinds of questions to reduce it down to the smallest possible example 
that demonstrates your problem.  I'm not sure what this MTTest class is 
all about, but I'm guessing it's not essential to demonstrate what's 
going wrong.  Why not just send strings back and forth?

Also, it would help to have names that made more sense.  I have no idea 
what a MKTest is, or what DSX means.  Names like that make it more 
difficult to read your code and understand what you probably intended.

In any case, I think the problem is a basic misunderstanding of how 
stream sockets work.  You're sending hunks of data with send() calls and 
expecting that the recv() calls will get the same data.  That works with 
UDP (datagram sockets), but not TCP.

There are no record boundaries in TCP.  The system could buffer up the 
data from multiple send() calls and deliver them in a single recv().  Or 
break up one send() into multiple recv() calls.  Or any combination.  In 
any particular situation, the system will probably do whatever is most 
inconvenient, confusing, and damaging to your program :-)

My recommendation is to strip out all the test gunk and get it down to 
the bare network calls.  Send some strings back and forth, and print out 
what each send() call is sending and what each recv() call receives.  
Hopefully, things will start to make more sense then.


 
 
 Here the Server:
 
 import SocketServer
 from ast import literal_eval
 
 class MKTest(object):
 DSX = []
 MKTestInst = None
 
 def __init__(self,Daten):
 MKTest.DSX.append(Daten)
 
 def getObj(Daten):
 if MKTest.MKTestInst == None:
 MKTest.MKTestInst = MKTest(Daten)
 return MKTest.MKTestInst
 
 getObj = staticmethod(getObj)
 
 class MySockX(SocketServer.BaseRequestHandler):
 def handle(self):
 data = self.request.recv(1024)
 data = literal_eval(data)
 #MKTest.getObj(data[0])
 #MKObj = MKTest(data[0])
 MKObj = MKTest.getObj(data[0])
 data = MKTest.DSX
 data = '%s' % data
 self.request.send(data)
 
 if __name__ == __main__:
 HOST, PORT = localhost, 
 server = SocketServer.TCPServer((HOST,PORT),MySockX)
 server.serve_forever()
 
 
 
 and the client:
 
 import socket
 
 data = [100]
 received = [None,None]
 HOST,PORT = localhost,
 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 sock.connect((HOST, PORT))
 sock.send('%s' % data)
 received[0] = sock.recv(1024)
 sock.send('%s' % data)
 received[1] = sock.recv(1024)
 sock.close()
 
 print received
 
 
 
 The result is:
 
 ['[100]', '']
 
 
 
 who can help me solving this problem
 
 
 
 Tamer
-- 
http://mail.python.org/mailman/listinfo/python-list


How filecmp walk into subdirectories?

2011-11-01 Thread Muddy Coder
Hi Folks,


I tried to compare two directories, each with hundreds of files in
multiple level subdirectories, to find out the different files. I used
filecmp module to the job as:


comp=filecmp.dircmp(adir, bdir)
comp.report()

It worked, and printed out the identical and different files. However,
it did not go through the directory trees, just did the job in the
first level. I wonder somebody can help? Thanks in advance!


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


Re: How filecmp walk into subdirectories?

2011-11-01 Thread John Gordon
In d0c0b3f4-ce8b-489f-9334-2b5d807f6...@es7g2000vbb.googlegroups.com Muddy 
Coder cosmo_gene...@yahoo.com writes:

 I tried to compare two directories, each with hundreds of files in
 multiple level subdirectories, to find out the different files. I used
 filecmp module to the job as:

 comp=filecmp.dircmp(adir, bdir)
 comp.report()

 It worked, and printed out the identical and different files. However,
 it did not go through the directory trees, just did the job in the
 first level. I wonder somebody can help? Thanks in advance!

report() only prints information on the first-level contents of the two
directores, as you saw.  It doesn't do subdirectories.

If you want subdirectories, use report_full_closure().

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, The Gashlycrumb Tinies

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


Re: understand program used to create file

2011-11-01 Thread alex23
On Nov 2, 5:27 am, pacopyc paco...@gmail.com wrote:
 Hi, I have about 1 files .doc and I want know the program used to
 create them: writer? word? abiword? else? I'd like develop a script
 python to do this. Is there a module to do it? Can you help me?

Word documents store metadata inside of them, one field of which is
the program used to create them. This shows you how to use pywin32 to
access them:

http://www.galalaly.me/index.php/2011/09/use-python-to-parse-microsoft-word-documents-using-pywin32-library/

This won't be a foolproof solution, unfortunately. A random
examination of doc files shows that not all of them have the required
field set.
-- 
http://mail.python.org/mailman/listinfo/python-list


Question about metaclass

2011-11-01 Thread Makoto Kuwata
Hi,

I want to define a special class which groups functions, like:

class Greepting(FuncGroup):
def hello():  # no self, no @staticmethod!
print(Hello!)
def goodbye():# no self, no @staticmethod!
print(Good Bye!)

Geeting.hello():#= Hello!
Geeting.goodbye():  #= Good Bye!


I tried the following code which converts instance mthods into
static method automatically, but I don't get result what I want.
(python 2.5.5)

import sys
from types import FunctionType

class MetaClass(type):
def __init__(cls, name, bases, dct):
## converts instance methods to static methods automatically
for k in dct.keys():
v = dct[k]
if isinstance(v, FunctionType):
dct[k] = staticmethod(v)
print(*** debug: dct[%r] = %r % (k, dct[k]))
#= staticmethod object at 0x100378d38

class FuncGroup(object):
__metaclass__ = MetaClass

class Greeting(FuncGroup):
def hello():
print(Hello!)
def goodbye():
print(Good Bye!)

print(*** type(Greeting.hello)=%r % type(Greeting.hello)
#= type 'instancemthod'
print(*** type(Greeting.goodbye)=%r % type(Greeting.goodbye)
#= type 'instancemthod'


Could you give me advice?

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


Re: Question about metaclass

2011-11-01 Thread Ian Kelly
On Tue, Nov 1, 2011 at 10:02 PM, Makoto Kuwata k...@kuwata-lab.com wrote:
 I tried the following code which converts instance mthods into
 static method automatically, but I don't get result what I want.
 (python 2.5.5)

    import sys
    from types import FunctionType

    class MetaClass(type):
        def __init__(cls, name, bases, dct):
            ## converts instance methods to static methods automatically
            for k in dct.keys():
                v = dct[k]
                if isinstance(v, FunctionType):
                    dct[k] = staticmethod(v)
                    print(*** debug: dct[%r] = %r % (k, dct[k]))

If you want to customize the dict you need to do it in __new__, not
__init__.  By the time __init__ is called, the class has already been
created.

class MetaClass(type):
def __new__(mcs, name, bases, dict):
for k, v in dict.items():
if isinstance(v, FunctionType):
dict[k] = staticmethod(v)
return type.__new__(mcs, name, bases, dict)

If you were using a more recent Python version, I would suggest using
a class decorator instead of a metaclass.  You can still do this in
Python 2.5, but the syntax will be more awkward.

# Python 2.6+
def FuncGroup(class_):
for k, v in class_.__dict__.items():
if isinstance(v, FunctionType):
setattr(class_, k, staticmethod(v))
return class_

@FuncGroup
class Greeting(object):
def hello():
print(Hello!)

# Python 2.5
class Greeting(object):
def hello():
print(Hello!)
Greeting = FuncGroup(Greeting)

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


Re: Question about metaclass

2011-11-01 Thread Patrick Maupin
On Nov 1, 11:02 pm, Makoto Kuwata k...@kuwata-lab.com wrote:
 Hi,

 I want to define a special class which groups functions, like:

     class Greepting(FuncGroup):
         def hello():          # no self, no @staticmethod!
             print(Hello!)
         def goodbye():        # no self, no @staticmethod!
             print(Good Bye!)

     Geeting.hello():    #= Hello!
     Geeting.goodbye():  #= Good Bye!

 I tried the following code which converts instance mthods into
 static method automatically, but I don't get result what I want.
 (python 2.5.5)

     import sys
     from types import FunctionType

     class MetaClass(type):
         def __init__(cls, name, bases, dct):
             ## converts instance methods to static methods automatically
             for k in dct.keys():
                 v = dct[k]
                 if isinstance(v, FunctionType):
                     dct[k] = staticmethod(v)
                     print(*** debug: dct[%r] = %r % (k, dct[k]))
 #= staticmethod object at 0x100378d38

     class FuncGroup(object):
         __metaclass__ = MetaClass

     class Greeting(FuncGroup):
         def hello():
             print(Hello!)
         def goodbye():
             print(Good Bye!)

     print(*** type(Greeting.hello)=%r % type(Greeting.hello)
 #= type 'instancemthod'
     print(*** type(Greeting.goodbye)=%r % type(Greeting.goodbye)
 #= type 'instancemthod'

 Could you give me advice?

 --
 regards,
 makoto kuwata

I think you need to unwrap the instance methods first:

 class foo(object):
... def bar():
... print Hi there
...
 foo.bar2 = staticmethod(foo.bar.im_func)

 foo.bar2()
Hi there


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


Re: Question about metaclass

2011-11-01 Thread Makoto Kuwata
On Wed, Nov 2, 2011 at 1:40 PM, Ian Kelly ian.g.ke...@gmail.com wrote:

 If you want to customize the dict you need to do it in __new__, not
 __init__.  By the time __init__ is called, the class has already been
 created.

 class MetaClass(type):
    def __new__(mcs, name, bases, dict):
        for k, v in dict.items():
            if isinstance(v, FunctionType):
                dict[k] = staticmethod(v)
        return type.__new__(mcs, name, bases, dict)

Great! It works perfectly!


 If you were using a more recent Python version, I would suggest using
 a class decorator instead of a metaclass.  You can still do this in
 Python 2.5, but the syntax will be more awkward.

 # Python 2.6+
 def FuncGroup(class_):
    for k, v in class_.__dict__.items():
        if isinstance(v, FunctionType):
            setattr(class_, k, staticmethod(v))
    return class_

 @FuncGroup
 class Greeting(object):
    def hello():
        print(Hello!)

 # Python 2.5
 class Greeting(object):
    def hello():
        print(Hello!)
 Greeting = FuncGroup(Greeting)

This is so good method.
Thank you, Ian.

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


Re: Assign values from list to list of instances

2011-11-01 Thread Gnarlodious
On Nov 1, 3:33 pm, Terry Reedy wrote:

  for obj, val in zip(Orders, locus):
  obj.locus = val

  I'm not sure how worthwhile it is converting the above to a list
  comprehension (when the list would just be thrown away). Having said
  that the call to zip creates an unnecessary list.

 Not in Py 3

Thanks for that tip, this works well in Py3.

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


Re: How to mix-in __getattr__ after the fact?

2011-11-01 Thread DevPlayer
On Oct 31, 8:01 am, dhyams dhy...@gmail.com wrote:
 Thanks for all of the responses; everyone was exactly correct, and
 obeying the binding rules for special methods did work in the example
 above.  Unfortunately, I only have read-only access to the class
 itself (it was a VTK class wrapped with SWIG), so I had to find
 another way to accomplish what I was after.

Please share what you found as the other way.
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue13279] Add memcmp into unicode_compare for optimizing comparisons

2011-11-01 Thread Martin v . Löwis

Martin v. Löwis mar...@v.loewis.de added the comment:

Ok, closing the issue.

--

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



[issue13279] Add memcmp into unicode_compare for optimizing comparisons

2011-11-01 Thread Martin v . Löwis

Changes by Martin v. Löwis mar...@v.loewis.de:


--
resolution:  - wont fix
status: open - closed

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



[issue12105] open() does not able to set flags, such as O_CLOEXEC

2011-11-01 Thread Charles-François Natali

Charles-François Natali neolo...@free.fr added the comment:

 Why it is closed as duplicate? nothing said about CLOEXEC in issue12797

See http://bugs.python.org/issue12760#msg146686

--

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



[issue12105] open() does not able to set flags, such as O_CLOEXEC

2011-11-01 Thread Amaury Forgeot d'Arc

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

And to be explicit, you can now write:

def open_cloexex(filename, mode='r'):
  return open(filename, mode,
  opener=lambda path, mod: os.open(path, mod|os.O_CLOEXEC))

--

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



[issue13308] fix test_httpservers failures when run as root

2011-11-01 Thread Charles-François Natali

New submission from Charles-François Natali neolo...@free.fr:

Here's a patch fixing test_httpservers failures when run as root (a couple 
buildbots are consistently failing on this, e.g. 
http://python.org/dev/buildbot/all/builders/x86 FreeBSD 7.2 
3.x/builds/2282/steps/test/logs/stdio).
The test is failing for two reasons:
1) test_get does a chmod(0) on a directory, and checks that the server returns 
an error when requesting a file under this directory: unfortunately, filesystem 
permissions are ignored by root
2) CGI tests fail because they try to execute CGI scripts, created in a 
temporary directory: unfortunately, the temp directory is created as root with 
mkdtemp() (mode == 0700), and the http server changes to user nobody before 
running the scripts = EACCES

--
components: Tests
files: test_httpserver_root.diff
keywords: needs review, patch
messages: 146762
nosy: haypo, neologix, pitrou
priority: normal
severity: normal
stage: patch review
status: open
title: fix test_httpservers failures when run as root
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3
Added file: http://bugs.python.org/file23578/test_httpserver_root.diff

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



[issue13308] fix test_httpservers failures when run as root

2011-11-01 Thread Petri Lehtinen

Petri Lehtinen pe...@digip.org added the comment:

You should change issue # with the real issue number now that there's an 
issue for this :)

--
nosy: +petri.lehtinen

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



[issue13152] textwrap: support custom tabsize

2011-11-01 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

Two comments:

* The new parameter to __init__ should be added at the end of the parameter 
list.

* A documentation update would be nice.

--

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



[issue13305] datetime.strftime(%Y) not consistent for years 1000

2011-11-01 Thread STINNER Victor

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

Le 01/11/2011 00:07, Roundup Robot a écrit :

 Roundup Robotdevn...@psf.upfronthosting.co.za  added the comment:

 New changeset 3f025427f02b by Florent Xicluna in branch 'default':
 Fix regression due to changeset 2096158376e5 (issue #13305).
 http://hg.python.org/cpython/rev/3f025427f02b

I don't like this hack. If there is a bug in time.strftime(), we need to 
fix time.strftime(), not xmlrpclib.

Is there a test for the hack?

--

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



[issue12105] open() does not able to set flags, such as O_CLOEXEC

2011-11-01 Thread Марк Коренберг

Марк Коренберг socketp...@gmail.com added the comment:

Well, I understand. So why not to add 'e' (and 'N', which is the same meaning) 
character, which:

* use O_CLOEXEC in modern Linux
* generate Exception if O_CLOEXEC is not supported (or does not work) on 
platform. 

Also, implement O_CLOEXEC for open() in Windows using appropriate 
securityattributes with CreateFile()

?

--

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



[issue13305] datetime.strftime(%Y) not consistent for years 1000

2011-11-01 Thread Roundup Robot

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

New changeset 230f0956aaa3 by Florent Xicluna in branch 'default':
Strengthen the tests for format '%Y', in relation with issue #13305.
http://hg.python.org/cpython/rev/230f0956aaa3

--

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



[issue12105] open() does not able to set flags, such as O_CLOEXEC

2011-11-01 Thread Amaury Forgeot d'Arc

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

 So why not to add 'e' character
You said it: because it can't be written consistently on all platforms.
For example, python does not use CreateFile on Windows, see #12939.

--

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



[issue12939] Add new io.FileIO using the native Windows API

2011-11-01 Thread Antoine Pitrou

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

Instead of rewriting your own RawIO implementation, why not use _open_osfhandle?
This should be simple now with the opener argument.
http://msdn.microsoft.com/en-us/library/bdts1c9x.aspx

--
nosy: +pitrou

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



[issue670664] HTMLParser.py - more robust SCRIPT tag parsing

2011-11-01 Thread Roundup Robot

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

New changeset 0a5eb57d5876 by Ezio Melotti in branch '2.7':
#670664: Fix HTMLParser to correctly handle the content of 
``script.../script`` and ``style.../style``.
http://hg.python.org/cpython/rev/0a5eb57d5876

New changeset a6f2244b251f by Ezio Melotti in branch '3.2':
#670664: Fix HTMLParser to correctly handle the content of 
``script.../script`` and ``style.../style``.
http://hg.python.org/cpython/rev/a6f2244b251f

New changeset b40752e227fa by Ezio Melotti in branch 'default':
#670664: merge with 3.2.
http://hg.python.org/cpython/rev/b40752e227fa

--
nosy: +python-dev

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



[issue670664] HTMLParser.py - more robust SCRIPT tag parsing

2011-11-01 Thread Ezio Melotti

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

Fixed, thanks to everyone who contributed to this over the years!

--
resolution:  - fixed
stage: commit review - committed/rejected
status: open - closed

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



[issue12008] HtmlParser non-strict goes wrong with unquoted attributes

2011-11-01 Thread Roundup Robot

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

New changeset 6107a84e3c44 by Ezio Melotti in branch '3.2':
#12008: add a test.
http://hg.python.org/cpython/rev/6107a84e3c44

New changeset 495b31a8b280 by Ezio Melotti in branch 'default':
#12008: merge with 3.2.
http://hg.python.org/cpython/rev/495b31a8b280

--
nosy: +python-dev

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



[issue12008] HtmlParser non-strict goes wrong with unquoted attributes

2011-11-01 Thread Ezio Melotti

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

This seems to be already fixed in 3.2/3.3, so I extracted the test from your 
script and added to the test suite.  If you can find a way to break the parser 
let me know.

--
assignee:  - ezio.melotti
nosy: +ezio.melotti
resolution:  - out of date
stage:  - committed/rejected
status: open - closed

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



[issue12629] HTMLParser silently stops parsing with malformed attributes

2011-11-01 Thread Ezio Melotti

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

I think xy z=o //x should be parser as xy z= //x, and the o 
should be ignored.
xy z= //x should be parser as xy z= //x, and the last two  
should be ignored.  This is what Firefox seems to do.

Currently the parser doesn't seem to handle extraneous data in the start tag 
too well, because the locatestarttagend_tolerant regex looks for (more or less) 
well-formed attributes.
Attached a patch for test_htmlparser with the two examples provided by Kevin.

--
keywords: +patch
nosy: +ezio.melotti
stage:  - needs patch
Added file: http://bugs.python.org/file23579/issue12629.diff

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



[issue12578] Erratic socket.gaierror: [Errno 11004] when using smtplib

2011-11-01 Thread Charles-François Natali

Charles-François Natali neolo...@free.fr added the comment:

Please provide more information, because this looks really strange...

--
nosy: +neologix
stage:  - test needed
status: open - pending

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



[issue13303] Sporadic importlib failures: FileNotFoundError on os.rename()

2011-11-01 Thread Charles-François Natali

Changes by Charles-François Natali neolo...@free.fr:


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

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



[issue13309] test_time fails: time data 'LMT' does not match format '%Z'

2011-11-01 Thread Florent Xicluna

New submission from Florent Xicluna florent.xicl...@gmail.com:

After changeset 55a3b563f0db the Gentoo buildbot is complaining.


==
FAIL: test_strptime (test.test_time.TimeTestCase)
--
Traceback (most recent call last):
  File 
/home/buildbot/buildarea/3.x.ochtman-gentoo-amd64/build/Lib/test/test_time.py,
 line 159, in test_strptime
time.strptime(strf_output, format)
ValueError: time data 'LMT' does not match format '%Z'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File 
/home/buildbot/buildarea/3.x.ochtman-gentoo-amd64/build/Lib/test/test_time.py,
 line 162, in test_strptime
(format, strf_output))
AssertionError: conversion specifier '%Z' failed with 'LMT' input.

--

--
components: Tests
keywords: buildbot
messages: 146776
nosy: flox
priority: normal
severity: normal
stage: test needed
status: open
title: test_time fails: time data 'LMT' does not match format '%Z'
type: behavior
versions: Python 3.3

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



[issue13302] Clarification needed in C API arg parsing

2011-11-01 Thread Antoine Pitrou

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

It's already in the 3.x docs (but not 2.x):

“Strings and buffers

These formats allow to access an object as a contiguous chunk of memory. You 
don’t have to provide raw storage for the returned unicode or bytes area. Also, 
you won’t have to release any memory yourself, except with the es, es#, et and 
et# formats.”

http://docs.python.org/dev/c-api/arg.html#strings-and-buffers

--
nosy: +pitrou

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



[issue13309] test_time fails: time data 'LMT' does not match format '%Z'

2011-11-01 Thread Roundup Robot

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

New changeset 2771f7e96a52 by Florent Xicluna in branch 'default':
Add temporary tests to troubleshoot issue #13309 on Gentoo buildbot.
http://hg.python.org/cpython/rev/2771f7e96a52

--
nosy: +python-dev

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



[issue9897] multiprocessing problems

2011-11-01 Thread Charles-François Natali

Charles-François Natali neolo...@free.fr added the comment:

The first problem is a duplicate of issue #6056.

As for the second problem, no, it doesn't limit the number of concurrent 
connections. Server.serve_forever() creates a new thread for each new incoming 
connection.

Closing as duplicate.

--
nosy: +neologix
resolution:  - duplicate
status: open - closed
superseder:  - socket.setdefaulttimeout affecting multiprocessing Manager

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



[issue13309] test_time fails: time data 'LMT' does not match format '%Z'

2011-11-01 Thread Roundup Robot

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

New changeset bb0ae7df08f8 by Florent Xicluna in branch 'default':
Troubleshoot issue #13309 on Gentoo buildbot.
http://hg.python.org/cpython/rev/bb0ae7df08f8

--

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



[issue13287] urllib.request exposes too many names

2011-11-01 Thread Roundup Robot

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

New changeset 70dedd8ce8f3 by Senthil Kumaran in branch 'default':
issue13287 - Define __all__ for urllib.request and urllib.error and expose only
http://hg.python.org/cpython/rev/70dedd8ce8f3

--
nosy: +python-dev

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



[issue13287] urllib.request exposes too many names

2011-11-01 Thread Senthil Kumaran

Senthil Kumaran sent...@uthcode.com added the comment:

Thanks flox for the patch.

Just the News item is added. I don't think, this requires any Docs update. One 
change I had to make in the patch is to remote HTTPSHandler from __all__ 
because that is only conditionally available when http.client supports 
HTTPSConnection.  Neither might this require a docs update because Handlers may 
be used only within urllib.request namespace and not standalone.

--
resolution:  - fixed
status: open - closed

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



[issue1745761] Bad attributes/data handling in SGMLib

2011-11-01 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
nosy: +ezio.melotti

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



[issue13309] test_time fails: time data 'LMT' does not match format '%Z'

2011-11-01 Thread Roundup Robot

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

New changeset 5b1e1967ea9d by Florent Xicluna in branch 'default':
Replace temporary tests with the real test case for issue #13309 on Gentoo.
http://hg.python.org/cpython/rev/5b1e1967ea9d

--

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



[issue13310] asyncore handling of out-of-band data fails

2011-11-01 Thread Xavier de Gaye

New submission from Xavier de Gaye xdeg...@gmail.com:

Add the following lines to test_handle_expt (this makes sense, a
dispatcher instance is supposed to implement handle_read and call recv
in order to detect that the remote end has closed the socket):

--- a/Lib/test/test_asyncore.py
+++ b/Lib/test/test_asyncore.py
@@ -677,6 +677,9 @@
 def handle_expt(self):
 self.flag = True
 
+def handle_read(self):
+self.recv(1)
+
 class TestHandler(BaseTestHandler):
 def __init__(self, conn):
 BaseTestHandler.__init__(self, conn)

With these lines added, the test now fails on linux with Python 3.3,
see the following backtrace: select (an poll) returns a read event and
an exceptional condition for the socket, but there is no normal data
to read, only out-of-band data.

The attached patch fixes the problem.


==
ERROR: test_handle_expt (test.test_asyncore.TestAPI_UseIPv4Poll)
--
Traceback (most recent call last):
  File /path_to/src/cpython/cpython-hg-default/Lib/test/test_asyncore.py, 
line 690, in test_handle_expt
self.loop_waiting_for_flag(client)
  File /path_to/src/cpython/cpython-hg-default/Lib/test/test_asyncore.py, 
line 523, in loop_waiting_for_flag
asyncore.loop(timeout=0.01, count=1, use_poll=self.use_poll)
  File /path_to/src/cpython/cpython-hg-default/Lib/asyncore.py, line 215, in 
loop
poll_fun(timeout, map)
  File /path_to/src/cpython/cpython-hg-default/Lib/asyncore.py, line 196, in 
poll2
readwrite(obj, flags)
  File /path_to/src/cpython/cpython-hg-default/Lib/asyncore.py, line 117, in 
readwrite
obj.handle_error()
  File /path_to/src/cpython/cpython-hg-default/Lib/asyncore.py, line 108, in 
readwrite
obj.handle_read_event()
  File /path_to/src/cpython/cpython-hg-default/Lib/asyncore.py, line 439, in 
handle_read_event
self.handle_read()
  File /path_to/src/cpython/cpython-hg-default/Lib/test/test_asyncore.py, 
line 681, in handle_read
self.recv(1)
  File /path_to/src/cpython/cpython-hg-default/Lib/asyncore.py, line 379, in 
recv
data = self.socket.recv(buffer_size)
BlockingIOError: [Errno 11] Resource temporarily unavailable

--
components: Library (Lib)
files: handle_expt.diff
keywords: patch
messages: 146783
nosy: xdegaye
priority: normal
severity: normal
status: open
title: asyncore handling of out-of-band data fails
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3
Added file: http://bugs.python.org/file23580/handle_expt.diff

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



[issue13311] asyncore handle_read should call recv

2011-11-01 Thread Xavier de Gaye

New submission from Xavier de Gaye xdeg...@gmail.com:

When the remote end disconnects, handle_close is only called if recv
is called (from handle_read). The default implementation of
handle_read does not call recv.

Not having the default implementation of handle_read call recv, has
the following drawbacks:

an implementation of a subclass of dispatcher that only sends
data, a logger for example, may believe that it does not have to
implement handle_read since it does not expect any data and since
there is no hint in the code or in the documentation that it
should

test_handle_expt currently succeeds when it should fail since the
current handling of out-of-band data is broken (see issue 13310),
but if the default implementation of handle_read had called recv,
then test_handle_expt would have failed, allowing to detect the
problem

The attached patch adds a call to recv in handle_read, updates the
documentation and adds a test case.

Note that when this patch is applied, test_handle_expt fails
as expected, issue 13310 should be fixed first.

--
components: Library (Lib)
files: handle_read.diff
keywords: patch
messages: 146785
nosy: xdegaye
priority: normal
severity: normal
status: open
title: asyncore handle_read should call recv
type: behavior
versions: Python 2.7, Python 3.3
Added file: http://bugs.python.org/file23581/handle_read.diff

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



[issue755670] improve HTMLParser attribute processing regexps

2011-11-01 Thread Ezio Melotti

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

Attached patch includes the tests in diff.txt.  On Python 3, with strict=False, 
the first test (adjacent attributes) passes, but the other two still fail.
See also #12629.

--
nosy: +ezio.melotti -BreamoreBoy
type: feature request - behavior
versions: +Python 3.3
Added file: http://bugs.python.org/file23582/issue755670.diff

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



[issue13309] test_time fails: time data 'LMT' does not match format '%Z'

2011-11-01 Thread Ross Lagerwall

Ross Lagerwall rosslagerw...@gmail.com added the comment:


import time
import sys

t = time.gmtime(time.time())
s = time.strftime('%Z', t)
print(s)

time.mktime((-1, 1, 1, 0, 0, 0, -1, -1, -1))

t = time.gmtime(time.time())
s = time.strftime('%Z', t)
print(s)

outputs:
SAST
LMT

on my Gentoo box. I'm still figuring out why...

--
nosy: +rosslagerwall

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



[issue12939] Add new io.FileIO using the native Windows API

2011-11-01 Thread Марк Коренберг

Марк Коренберг socketp...@gmail.com added the comment:

why not use _open_osfhandle?

Because it is wrapper for other CRT functions for Windows, like close(). In 
other words it is an emulation. I think Python should not create wrapper around 
wrapper around wrapper...

For example, in Python3, open() implemented using open() and not using fopen(). 
Why we should use another wrapper on Windows platform?

--

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



[issue12939] Add new io.FileIO using the native Windows API

2011-11-01 Thread Antoine Pitrou

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

 why not use _open_osfhandle?
 
 Because it is wrapper for other CRT functions for Windows, like
 close(). In other words it is an emulation. I think Python should not
 create wrapper around wrapper around wrapper...

Why do you think it makes a difference?

--

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



[issue13309] test_time fails: time data 'LMT' does not match format '%Z'

2011-11-01 Thread Florent Xicluna

Florent Xicluna florent.xicl...@gmail.com added the comment:

It seems that mktime is buggy on Gentoo.
You can try to reset its state in some way before to retry strftime:


t = time.gmtime(time.time())
s = time.strftime('%Z', t)
print(s)

time.mktime((-1, 1, 1, 0, 0, 0, -1, -1, -1))
s = time.strftime('%Z', t)
print(s)

time.mktime((1, 1, 1, 0, 0, 0, 0, 0, -1))
s = time.strftime('%Z', t)
print(s)


I guess it could output:
SAST
LMT
SAST

--

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



[issue13309] test_time fails: time data 'LMT' does not match format '%Z'

2011-11-01 Thread Ross Lagerwall

Ross Lagerwall rosslagerw...@gmail.com added the comment:

It outputs:
SAST
LMT
LMT

An equivalent C program to the first test:

#include time.h
#include stdlib.h
#include stdio.h

int main() {

time_t t;
struct tm *tmp;

t = time(NULL);
tmp = localtime(t);

char str[200];
strftime(str, sizeof(str), %Z, tmp);

puts(str);

struct tm tmp2;
tmp2.tm_sec = 0;
tmp2.tm_min = 0;
tmp2.tm_hour = 0;
tmp2.tm_mday = 1;
tmp2.tm_mon = 1;
tmp2.tm_year = -1;
tmp2.tm_wday = -1;
tmp2.tm_yday = -1;
tmp2.tm_isdst = -1;
mktime(tmp2);

t = time(NULL);
tmp = localtime(t);

strftime(str, sizeof(str), %Z, tmp);

puts(str);

return 0;
}


Outputs (as expected):
SAST
SAST

Perhaps it's not mktime?

--

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



[issue12939] Add new io.FileIO using the native Windows API

2011-11-01 Thread Amaury Forgeot d'Arc

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

An implementation of RawIO with the win32 API can be useful (and I'd be 
interested to compare the performance)
But maybe not for all usages: some Python interfaces are defined in terms of 
file descriptors, imp.load_module(), and PyTokenizer_FindEncoding for example.

--

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



[issue13312] test_time fails: strftime('%Y', y) for negative year

2011-11-01 Thread Florent Xicluna

New submission from Florent Xicluna florent.xicl...@gmail.com:

On builder AMD64 FreeBSD 8.2 3.x for the TIME_MINYEAR:


==
FAIL: test_negative (test.test_time.TestStrftime4dyear)
--
Traceback (most recent call last):
  File 
/usr/home/buildbot/buildarea/3.x.krah-freebsd/build/Lib/test/test_time.py, 
line 397, in test_negative
return super().test_negative()
  File 
/usr/home/buildbot/buildarea/3.x.krah-freebsd/build/Lib/test/test_time.py, 
line 425, in test_negative
self.assertEqual(self.yearstr(TIME_MINYEAR), str(TIME_MINYEAR))
AssertionError: '2147483648' != '-2147483648'
- 2147483648
+ -2147483648
? +

--
components: Library (Lib)
keywords: buildbot
messages: 146793
nosy: belopolsky, flox
priority: normal
severity: normal
stage: needs patch
status: open
title: test_time fails: strftime('%Y', y) for negative year
type: behavior
versions: Python 3.3

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



[issue12939] Add new io.FileIO using the native Windows API

2011-11-01 Thread Марк Коренберг

Марк Коренберг socketp...@gmail.com added the comment:

 Why do you think it makes a difference?
Because adding one more dependency on unneeded libraries add the pain. Also it 
limit us on very restricted API of that wrapper. Windows native API is stable. 
So it's OK to rely on it's documented imlementation.

Suppose, we receive file-descriptor from _open_osfhandle For example it is 
a socket. It still unusable for stdin. Many standard functions does not work 
with such handle. The list of available functions : 
http://msdn.microsoft.com/en-us/library/kdfaxaay.aspx . As we see it is very 
narrow and function names are not POSIX-compatible (_chsize vs ftruncate). 
Documentation is very poor. For example, _close() is documented only here: 
http://msdn.microsoft.com/en-US/library/40bbyw78(v=VS.80).aspx .

--

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



[issue13313] test_time fails: tzset() do not change timezone

2011-11-01 Thread Florent Xicluna

New submission from Florent Xicluna florent.xicl...@gmail.com:

On builder x86 FreeBSD 7.2 3.x :

==
FAIL: test_tzset (test.test_time.TimeTestCase)
--
Traceback (most recent call last):
  File 
/usr/home/db3l/buildarea/3.x.bolen-freebsd7/build/Lib/test/test_time.py, line 
246, in test_tzset
self.assertTrue(time.tzname[0] == 'AEST', str(time.tzname[0]))
AssertionError: False is not true : EST


(See also issue #13309 for tzname on Gentoo)

--
components: Library (Lib)
keywords: buildbot
messages: 146794
nosy: belopolsky, flox
priority: normal
severity: normal
stage: test needed
status: open
title: test_time fails: tzset() do not change timezone
type: behavior
versions: Python 3.3

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



  1   2   >