Re: Reg secure python environment with web terminal emulator

2013-08-08 Thread dieter
Lakshmipathi.G lakshmipath...@gmail.com writes:
 Could you please share more info about creating raw binary executable
 and its potential
 problem.

In an earlier message, you reported to have banned gcc to
avoid C level exploits. A raw binary executable would allow
the same exploits. Think of a binary generated elsewhere (where
gcc is available) and put into your environment.

I am convinced that 100 % security is impossible - and correspondingly
would use a pragmatic approach: I would rely on OS level
constraints (user with very restricted rights, process running
in an isolated box) - and ensure the OS is kept up to date
to reduce the risk of exploits of OS security weaknesses.

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


Re: beginner question (True False help)

2013-08-08 Thread wxjmfauth
Le mercredi 7 août 2013 10:17:21 UTC+2, eschne...@comcast.net a écrit :
 I'm trying to create an option for the program to repeat if the user types 
 'y' or 'yes', using true and false values, or otherwise end the program. If 
 anyone could explain to me how to get this code working, I'd appreciate it.
 
 
 
 letters='abcdefghijklmn'
 
 batman=True
 
 def thingy():
 
 print('type letter from a to n')
 
 typedletter=input()
 
 if typedletter in letters:
 
 print('yes')
 
 else:
 
 print('no')
 
 def repeat():
 
 print('go again?')
 
 goagain=input()
 
 if goagain in ('y', 'yes'):
 
 print('ok')
 
 else:
 
 print('goodbye')
 
 batman=False
 
 while batman==True:
 
 thingy()
 
 repeat()
 
 print('this is the end')

---

Your loop is not very well organized. It should be
at the same time the loop and the condition tester.
Compare your code with this and note the missing and
unnecessary batman:


 def z():
... letters = 'abc'
... c = input('letter: ')
... while c in letters:
... print('do stuff')
... c = input('letter: ')
... print('end, fin, Schluss')
... 
 z()
letter: a
do stuff
letter: b
do stuff
letter: b
do stuff
letter: c
do stuff
letter: n
end, fin, Schluss
 
 z()
letter: q
end, fin, Schluss


Variant
It is common to use a infinite loop and to break it
in order to end the job.


 def z2():
... letters = 'abc'
... while True:
... c = input('letter: ')
... if c not in letters:
... print('end, fin, Schluss')
... break
... else:
... print('do stuff')
... 
 z2()
letter: a
do stuff
letter: b
do stuff
letter: a
do stuff
letter: q
end, fin, Schluss


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


Is it possible to make a unittest decorator to rename a method from x to testx?

2013-08-08 Thread adam . preble
We were coming into Python's unittest module from backgrounds in nunit, where 
they use a decorate to identify tests.  So I was hoping to avoid the convention 
of prepending test to the TestClass methods that are to be actually run.  I'm 
sure this comes up all the time, but I mean not to have to do:

class Test(unittest.TestCase):
def testBlablabla(self):
self.assertEqual(True, True)

But instead:
class Test(unittest.TestCase):
@test
def Blablabla(self):
self.assertEqual(True, True)

This is admittedly a petty thing.  I have just about given up trying to 
actually deploy a decorator, but I haven't necessarily given up on trying to do 
it for the sake of knowing if it's possible.

Superficially, you'd think changing a function's __name__ should do the trick, 
but it looks like test discovery happens without looking at the transformed 
function.  I tried a decorator like this:

def prepend_test(func):
print running prepend_test
func.__name__ = test + func.__name__

def decorator(*args, **kwargs):
return func(args, kwargs)

return decorator

When running unit tests, I'll see running prepend_test show up, but a dir on 
the class being tested doesn't show a renamed function.  I assume it only works 
with instances.  Are there any other tricks I could consider?
-- 
http://mail.python.org/mailman/listinfo/python-list


Issues with if and elif statements in 3.3

2013-08-08 Thread krismesenbrink
def town():
print (You stand in the middle of Coffeington while you descide what
 to do next, you have herd rumor of the Coffeington Caves that run
under the city, would you like to check them out?)
answer = input()
if answer == (yes) or (Yes) or (y):
print(You set out for the Coffeington Caves)
elif answer == (no) or (No) or (n):
print(Oh...well im sure you can find something else to do)
else:
print(You just stand  there)
town()



i don't know why the elif or else part of the if statment wont trigger. 
what ends up happening is that regardless of what answer you put in input it 
will always print out you set out for the Coffeington Caves. whats supposed 
to happen is if you say no it should just end? i think anway.
-- 
http://mail.python.org/mailman/listinfo/python-list


Paramiko Help. Execute command to Interactive Shell which is opened by SSHClient()

2013-08-08 Thread sagar varule
Hi All,

Im using Paramiko for my SSH automation. Im using method that is shown in 
demo_simple.py example which comes with Paramiko. Below is code from 
demo_simple.py.

As you can make out, below code opens SSH connection and opens Interactie 
Shell, and then wait for the command from user.
I want to submit the command to this Interactive Shell using code.

try:
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
print '*** Connecting...'
client.connect(hostname, port, username, password)
chan = client.invoke_shell()
print repr(client.get_transport())
print '*** Here we go!'
print
interactive.interactive_shell(chan)
chan.close()
client.close()

Well Another approach I tried is instead of opening interactive_shell, directly 
issue command using;

 stdin, stdout, stderr = client.exec_command(bv_cmd)
for line in stderr.readlines():
print line
for line in stdout.readlines():
print line
But problem here is client.exec_command(bv_cmd) waits for command to execute 
completely and then it returns to stdout,stderr. And I want to see the ouput 
from the command during its execution. Because my command takes long time for 
execution.

Big Picture in My Mind: Big Picture I that want to achieve is, Opening 
different SSH connection to different host, and it will issue commands to all 
host, wait for execution. All execution should happen parallel.(just wanted to 
share my thought, and wanted to hear opinions from you all. Is this 
possible??). I am not big programmer, just 2 years experience with asp.net C# 
2.0 so i would appreciate if discussion happens in simple english.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reg secure python environment with web terminal emulator

2013-08-08 Thread Lakshmipathi.G
 the same exploits. Think of a binary generated elsewhere (where
 gcc is available) and put into your environment.

That's pretty bad news :(


 I am convinced that 100 % security is impossible - and correspondingly
 would use a pragmatic approach: I would rely on OS level
 constraints (user with very restricted rights, process running
 in an isolated box) - and ensure the OS is kept up to date
 to reduce the risk of exploits of OS security weaknesses.


Yes,agree 100% security will never be possible. I'll explore about running
process as an isolated box. Thanks for the suggestions and inputs.



-- 

Cheers,
Lakshmipathi.G
FOSS Programmer.
www.giis.co.in
-- 
http://mail.python.org/mailman/listinfo/python-list


Thinking Unicode

2013-08-08 Thread wxjmfauth
I wrote many times on this list, the ascii (generic name for
byte string) world and the unicode world are two incompatible
worlds. There are bridges, basically there are incompatible,
they requires to think differently.

There is an interesting case on the dev list:
http://mail.python.org/pipermail/python-dev/2013-July/127420.html


There is nothing wrong in polishing the documentation, but
interestingly the discussion turned out about the
usage of -- and --- instead of real en-dashes and
em-dashes, understand use ascii and not unicode.

It has been argued TeX uses -- and ---. True for
the pre-unicode engines. It's no more the case.

Steven proposed the usage of \N{EM DASH}, ...
Good point, a real step towards unicode, but why
using ascii when one can use directly –, —?
Is it not the purpose to use unicode in an utf-8
file, many recommand?
If utf-8 is (and has been created to be) compatible with ascii,
it seems today the usage is to make utf-8 compatible with ascii!

The .rst files have been touched and in my last check,
1-2 days ago, the - has been replaced by
-. No trace of real en-dashes, em-dashes
in diff's.

What happen if confusion is reappearing? Simple,
reopen a discussion and continue to not solve
problems.



-

Somebody wrote:
... (and nobody really wants to type three hyphens except
for a handful of typographical nuts)...

Completely out of phase. Beyond that comment (or kind of comment),
(I'm spying the misc. lists since years), not a suprise that Python
and Unicode never work.


jmf



PS

 '–—'.encode('cp1252')
b'\x96\x97'
 '–—'.encode('mac-roman')
b'\xd0\xd1'
 '–—'.encode('latin-1')
Traceback (most recent call last):
  File eta last command, line 1, in module
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-1:
ordinal not in range(256)

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


Re: Is it possible to make a unittest decorator to rename a method from x to testx?

2013-08-08 Thread Terry Reedy

On 8/8/2013 2:32 AM, adam.pre...@gmail.com wrote:

We were coming into Python's unittest module from backgrounds in nunit, where they use a 
decorate to identify tests.  So I was hoping to avoid the convention of prepending 
test to the TestClass methods that are to be actually run.  I'm sure this 
comes up all the time, but I mean not to have to do:

class Test(unittest.TestCase):
 def testBlablabla(self):
 self.assertEqual(True, True)

But instead:
class Test(unittest.TestCase):
 @test
 def Blablabla(self):
 self.assertEqual(True, True)


I cannot help but note that this is *more* typing. But anyhow, something 
like this might work.


def test(f):
f.__class__.__dict__['test_'+f.__name__]

might work. Or maybe for the body just
   setattr(f.__class__, 'test_'+f.__name__)



Superficially, you'd think changing a function's __name__ should do the trick, 
but it looks like test discovery happens without looking at the transformed 
function.


I am guessing that unittest discovery for each class is something like

if isinstance (cls, unittest.TestCase):
  for name, f in cls.__dict__.items():
if name.startswith('test'):
  yield f

You were thinking it would be
...
  for f in cls.__dict__.values():
if f.__name__.startwith('test'):
  yield f

Not ridiculous, but you seem to have disproven it. I believe you can 
take 'name' in the docs to be bound or namespace name rather than 
definition or attribute name.


--
Terry Jan Reedy

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


Re: Is it possible to make a unittest decorator to rename a method from x to testx?

2013-08-08 Thread Peter Otten
adam.pre...@gmail.com wrote:

 We were coming into Python's unittest module from backgrounds in nunit,
 where they use a decorate to identify tests.  So I was hoping to avoid the
 convention of prepending test to the TestClass methods that are to be
 actually run.  I'm sure this comes up all the time, but I mean not to have
 to do:
 
 class Test(unittest.TestCase):
 def testBlablabla(self):
 self.assertEqual(True, True)
 
 But instead:
 class Test(unittest.TestCase):
 @test
 def Blablabla(self):
 self.assertEqual(True, True)
 
 This is admittedly a petty thing.  I have just about given up trying to
 actually deploy a decorator, but I haven't necessarily given up on trying
 to do it for the sake of knowing if it's possible.
 
 Superficially, you'd think changing a function's __name__ should do the
 trick, but it looks like test discovery happens without looking at the
 transformed function.  I tried a decorator like this:
 
 def prepend_test(func):
 print running prepend_test
 func.__name__ = test + func.__name__
 
 def decorator(*args, **kwargs):
 return func(args, kwargs)
 
 return decorator
 
 When running unit tests, I'll see running prepend_test show up, but a
 dir on the class being tested doesn't show a renamed function.  I assume
 it only works with instances.  Are there any other tricks I could
 consider?

I think you are misunderstanding what a decorator does. You can think of

def f(...): ...

as syntactic sugar for an assignment

f = make_function(...)

A decorator intercepts that

f = decorator(make_function(...))

and therefore can modify or replace the function object, but has no 
influence on the name binding.

For unittest to allow methods bound to a name not starting with test you 
have to write a custom test loader.

import functools
import unittest.loader
import unittest

def test(method):
method.unittest_method = True
return method

class MyLoader(unittest.TestLoader):
   
def getTestCaseNames(self, testCaseClass):
def isTestMethod(attrname, testCaseClass=testCaseClass,
 prefix=self.testMethodPrefix):
attr = getattr(testCaseClass, attrname)
if getattr(attr, unittest_method, False):
return True
return attrname.startswith(prefix) and callable(attr)

testFnNames = list(filter(isTestMethod, dir(testCaseClass)))
if self.sortTestMethodsUsing:

testFnNames.sort(key=functools.cmp_to_key(self.sortTestMethodsUsing))
return testFnNames

class A(unittest.TestCase):
def test_one(self):
pass
@test
def two(self):
pass

if __name__ == __main__:
unittest.main(testLoader=MyLoader())

Alternatively you can write a metaclass that *can* intercept the name 
binding process:

$ cat mytestcase.py 
import unittest

__UNITTEST = True

PREFIX = test_

class Type(type):
def __new__(class_, name, bases, classdict):
newclassdict = {}
for name, attr in classdict.items():
if getattr(attr, test, False):
assert not name.startswith(PREFIX)
name = PREFIX + name
assert name not in newclassdict
newclassdict[name] = attr
return type.__new__(class_, name, bases, newclassdict)

class MyTestCase(unittest.TestCase, metaclass=Type):
pass

def test(method):
method.test = True
return method
$ cat mytestcase_demo.py
import unittest
from mytestcase import MyTestCase, test

class T(MyTestCase):
def test_one(self):
pass
@test
def two(self):
pass

if __name__ == __main__:
unittest.main()
$ python3 mytestcase_demo.py -v
test_one (__main__.test_two) ... ok
test_two (__main__.test_two) ... ok

--
Ran 2 tests in 0.000s

OK


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


Re: [GUI] Good frameworks for Windows/Mac?

2013-08-08 Thread sagar varule
On Tuesday, August 6, 2013 4:05:40 PM UTC+5:30, Gilles wrote:
 Hello
 
 
 
 I need to write a small GUI application that should run on Windows and
 
 Mac.
 
 
 
 What open-source framework would you recommend? I just need basic
 
 widgets (button, listbox, etc.) and would rather a solution that can
 
 get me up and running fast.
 
 
 
 I know about wxWidgets and Qt: Are there other good options I should
 
 know about?
 
 
 
 Thank you.

Pyside is also Good. It has a Designer which can be helpful.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to make a unittest decorator to rename a method from x to testx?

2013-08-08 Thread Peter Otten
Peter Otten wrote:

 $ python3 mytestcase_demo.py -v
 test_one (__main__.test_two) ... ok
 test_two (__main__.test_two) ... ok
 
 --
 Ran 2 tests in 0.000s

Oops, that's an odd class name. Fixing the name clash in Types.__new__() is 
left as an exercise...

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


To make simpleXMLRPC support multi-thread

2013-08-08 Thread Zhang JiaQiang
I try to use simpleXMLRPC and support request multithreads ,used ThreadingMixIn.

Why what I get from the console still blocking ?
 
launch the two clients at the same time,one finish, then begin the other, 
between them there is 15 sec.
 
Here is the console output on server windows:

Use Cc to exit
DEBUG:root:11 request dir the directory(/)
DEBUG:root:block 11 ...
nio102 - - [08/Aug/2013 15:35:17] POST /RPC2 HTTP/1.0 200 -
DEBUG:root:22 request dir the directory(/)
DEBUG:root:block 22 ...
nio102 - - [08/Aug/2013 15:35:32] POST /RPC2 HTTP/1.0 200 -


The following are the codes: 

## client 111 ##
import xmlrpclib
 
proxy = xmlrpclib.ServerProxy('http://xx.xx.xx.xx:9000')
print proxy.dir_contents('/', '11')
 

## client 222 ###
import xmlrpclib
 
proxy = xmlrpclib.ServerProxy('http://xx.xx.xx.xx:9000')
print proxy.dir_contents('/', '22')
 

 
## server  ###
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SocketServer import ThreadingMixIn
import logging
 
import os
import time
 

logging.basicConfig(level=logging.DEBUG)
 

def list_contents(dir_name, client):
logging.debug('%s request list the directory(%s)', client, dir_name)
logging.debug('block %s request for 15 sec...' % client)
time.sleep(15)
return os.listdir(dir_name)

class ListDirRPCServer(ThreadingMixIn, SimpleXMLRPCServer):
def __init__(self, ip, port):
self.server = SimpleXMLRPCServer((ip, port), logRequests=True)
self.server.register_function(list_contents)

def active_server(self):
try:
print Use Cc to exit
self.server.serve_forever()
except KeyboardInterrupt:
print exiting
 
if __name__ == '__main__':
ip = 'xx.xx.xx.xx'
port = 9000
list_rpc = ListDirRPCServer(ip, port)
list_rpc.active_server()
 
 
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [GUI] Good frameworks for Windows/Mac?

2013-08-08 Thread Gilles
On Thu, 8 Aug 2013 01:47:21 -0700 (PDT), sagar varule
sagar.var...@gmail.com wrote:
Pyside is also Good. It has a Designer which can be helpful.

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


Suggestion: PEP for popping slices from lists

2013-08-08 Thread Neatu Ovidiu Gabriel
The list.pop(index) returns the element represented by the index and also 
reduces the list by removing that element. So it a short one liner for doing 
both things.
But when it comes for popping a slice of the list there is nothing similar for 
doing in that simple way.

If you want to remove a slice and also reduce the list you will have something 
like this:

a_list, a_slice = a_list[:size], a_list[size:]

or even worser if you try to do the same for something in the middle.

My proposal is the extension of list.pop for accepting a way for popping slices.

When doing this:

a_list.pop(i,j)

pop will return the slice [i,j] and remove it from the list.

For popping from an index to the end:

a_list.pop(i, len(a_list))

Or even emptying the whole list:

a_list.pop(0, len(a_list))


So this is it :)
-- 
http://mail.python.org/mailman/listinfo/python-list


[ActivePython] Add Qt/PyQt and wxWidgets/wxPython?

2013-08-08 Thread Gilles
Hello

I upgraded to ActivePython 2.7.2.5, and would like to get started
learning about Qt and wxWidgets in Python.

I have a couple of question:

1. Are there obvious reasons to choose either QT/PyQt or
wxWidgets/wxPython? I have the impression that Qt is a richer GUI than
wxWidgets, but it could just be an impression.

2. Is there a no-brainer article that explains how to add Qt and
wxWidgets to ActivePython community edition, since they're only
included in the Business and Enterprise editions?

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


Re: Mock pathc question

2013-08-08 Thread Jean-Michel Pichavant
- Mail original - 

 Hi
 1) I prefer to use start/stop and not the decorator .
 2) mock_play is the name of the module where the code belongs

 Thanks

 Avishay
 Sent from my iPhone


You should not neeed to refer to the Calc class using mock_play since it is 
defined in the very same file (module).
Possibly mock_play.Calc and Calc are 2 different classes, hence you're not 
patching the good one.

Note how you patch mock_play.Calc and then instanciate using self.calc = 
Calc()

right before
my_mock = mock.patch('mock_play.Calc',create=True, new=MockCalc)

add 
print mock_play.Calc
print Calc


and verify that they are both the very same object.

Cheers,

JM


PS : Please do not top post in this list


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: PEP for popping slices from lists

2013-08-08 Thread Peter Otten
Neatu Ovidiu Gabriel wrote:

 The list.pop(index) returns the element represented by the index and also
 reduces the list by removing that element. So it a short one liner for
 doing both things. But when it comes for popping a slice of the list there
 is nothing similar for doing in that simple way.
 
 If you want to remove a slice and also reduce the list you will have
 something like this:
 
 a_list, a_slice = a_list[:size], a_list[size:]
 
 or even worser if you try to do the same for something in the middle.
 
 My proposal is the extension of list.pop for accepting a way for popping
 slices.
 
 When doing this:
 
 a_list.pop(i,j)
 
 pop will return the slice [i,j] and remove it from the list.
 
 For popping from an index to the end:
 
 a_list.pop(i, len(a_list))
 
 Or even emptying the whole list:
 
 a_list.pop(0, len(a_list))
 
 
 So this is it :)

You'd use 'del' to remove a slice from a list. So:

 def pop_slice(items, *indices):
... x = slice(*indices)
... result = items[x]
... del items[x]
... return result
... 
 items = range(10)
 pop_slice(items, 3)
[0, 1, 2]
 items
[3, 4, 5, 6, 7, 8, 9]
 pop_slice(items, 3, 4)
[6]
 items
[3, 4, 5, 7, 8, 9]
 pop_slice(items, None, None, 2)
[3, 5, 8]
 items
[4, 7, 9]

But what's your use case?
Does it occur often enough that you cannot afford a two-liner like

result = items[start:stop]
del items[start:stop]

?

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


Re: Issues with if and elif statements in 3.3

2013-08-08 Thread Dave Angel
krismesenbr...@gmail.com wrote:

 def town():
 print (You stand in the middle of Coffeington while you descide what
  to do next, you have herd rumor of the Coffeington Caves that run
 under the city, would you like to check them out?)
 answer = input()
 if answer == (yes) or (Yes) or (y):

This doesn't do what you think it does.  First it compares answer to
yes.  Then it takes the result of that and OR's it with Yes.  Then
it takes the result of that and OR's it with y.  Finally it takes the
bool of the result and decides whether to execute the if-body.  Since
those OR's will always be true, it always executes the if-body, and
never the elif or else body.

Fix the expression to what you presumably meant:

if answer == yes or answer == Yes or answer == y:

Or less typing:

if answer in (yes, Yes, y):




 print(You set out for the Coffeington Caves)
 elif answer == (no) or (No) or (n):
 print(Oh...well im sure you can find something else to do)
 else:
 print(You just stand  there)
 town()



 i don't know why the elif or else part of the if statment wont trigger. 
 what ends up happening is that regardless of what answer you put in input it 
 will always print out you set out for the Coffeington Caves. whats supposed 
 to happen is if you say no it should just end? i think anway.

-- 
DaveA


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


Re: Suggestion: PEP for popping slices from lists

2013-08-08 Thread Neatu Ovidiu
On Thursday, August 8, 2013 1:07:16 PM UTC+3, Peter Otten wrote:
 Neatu Ovidiu Gabriel wrote:
 
 
 
  The list.pop(index) returns the element represented by the index and also
 
  reduces the list by removing that element. So it a short one liner for
 
  doing both things. But when it comes for popping a slice of the list there
 
  is nothing similar for doing in that simple way.
 
  
 
  If you want to remove a slice and also reduce the list you will have
 
  something like this:
 
  
 
  a_list, a_slice = a_list[:size], a_list[size:]
 
  
 
  or even worser if you try to do the same for something in the middle.
 
  
 
  My proposal is the extension of list.pop for accepting a way for popping
 
  slices.
 
  
 
  When doing this:
 
  
 
  a_list.pop(i,j)
 
  
 
  pop will return the slice [i,j] and remove it from the list.
 
  
 
  For popping from an index to the end:
 
  
 
  a_list.pop(i, len(a_list))
 
  
 
  Or even emptying the whole list:
 
  
 
  a_list.pop(0, len(a_list))
 
  
 
  
 
  So this is it :)
 
 
 
 You'd use 'del' to remove a slice from a list. So:
 
 
 
  def pop_slice(items, *indices):
 
 ... x = slice(*indices)
 
 ... result = items[x]
 
 ... del items[x]
 
 ... return result
 
 ... 
 
  items = range(10)
 
  pop_slice(items, 3)
 
 [0, 1, 2]
 
  items
 
 [3, 4, 5, 6, 7, 8, 9]
 
  pop_slice(items, 3, 4)
 
 [6]
 
  items
 
 [3, 4, 5, 7, 8, 9]
 
  pop_slice(items, None, None, 2)
 
 [3, 5, 8]
 
  items
 
 [4, 7, 9]
 
 
 
 But what's your use case?
 
 Does it occur often enough that you cannot afford a two-liner like
 
 
 
 result = items[start:stop]
 
 del items[start:stop]
 
 
 
 ?


 But what's your use case?
 
 Does it occur often enough that you cannot afford a two-liner like
I think uses cases are plenty.
And how can I figure out how often it occurs? I don't have a hint, it remains 
an open question.

The issues I see so far with my proposal are:
  - what you said, how often it is used, if it deserves a place
  - maybe it should be a separate function like pop_slice to don't alter in 
anyway the behavior of good old pop
  - it will rise some backwards compatibility issues

I just find it's a more pythonic way to deal with this situation. One short 
line instead of two or one long line is better. This shortness of typing is the 
core feature of Python so I think my proposal it's leap towards simplicity.
-- 
http://mail.python.org/mailman/listinfo/python-list


paramiko installation problem

2013-08-08 Thread D. Xenakis
Im having problems using paramiko after installation on my Win7 64bit system.
I can see both paramiko and pycrypto being there installed via pip list:

I have tried so many different ways but in the end im always getting the same 
error when trying to import paramiko:
(i can import Crypto with no problems)

Traceback (most recent call last):
  File pyshell#0, line 1, in module
import paramiko
  File C:\Python33\lib\site-packages\paramiko\__init__.py, line 64, in 
module
from transport import SecurityOptions, Transport
ImportError: No module named 'transport'

Please can you help?
thx
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: PEP for popping slices from lists

2013-08-08 Thread Nicholas Cole
On Thu, Aug 8, 2013 at 11:38 AM, Neatu Ovidiu neatu...@gmail.com wrote:



  But what's your use case?
 
  Does it occur often enough that you cannot afford a two-liner like
 I think uses cases are plenty.


The possible cases I can think of would be better served with list
comprehensions (what you seem to want is to create lists based on other
lists) - but maybe I'm missing something.  Could we have one example?

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


Re: beginner question (True False help)

2013-08-08 Thread Chris Angelico
On Thu, Aug 8, 2013 at 7:20 AM,  wxjmfa...@gmail.com wrote:
 def z2():
 ... letters = 'abc'
 ... while True:
 ... c = input('letter: ')
 ... if c not in letters:
 ... print('end, fin, Schluss')
 ... break
 ... else:
 ... print('do stuff')


Minor quibble: I don't like having a hard exit followed by an else.
If the if branch will unconditionally quit the loop (with a break,
here, but could also be a return, a thrown exception, etc etc), I
would prefer to see the else removed and its code unindented one
level. Maybe this is just personal preference, though, learned from
assembly language programming where a block if looks something like
this:

; if x == y:
CMP x,y
JNZ .else
; Code for x == y
JMP .endif
.else:
; Code for else
.endif

Putting an unconditional departure in the x == y branch makes the
JMP .endif redundant.

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


Re: Suggestion: PEP for popping slices from lists

2013-08-08 Thread Neatu Ovidiu
On Thursday, August 8, 2013 2:12:53 PM UTC+3, Nicholas wrote:
 On Thu, Aug 8, 2013 at 11:38 AM, Neatu Ovidiu neat...@gmail.com wrote:
 
 
 
 
 
 
 
  But what's your use case?
 
 
 
  Does it occur often enough that you cannot afford a two-liner like
 
 I think uses cases are plenty.
 
 
 
 
 The possible cases I can think of would be better served with list 
 comprehensions (what you seem to want is to create lists based on other 
 lists) - but maybe I'm missing something.  Could we have one example?
 
 
 
 N.

This can be useful for doing all kinds of basic stuff. For example if you 
wanted to take 4 items of a list at at a time, do something with them and then 
update the list.

jobs = ['job1', 'job2', 'job3', 'job5', 'job6', 'job7', 'job8', 'job9', 'job10']
while jobs:
print jobs.pop_slice(0,4)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: PEP for popping slices from lists

2013-08-08 Thread Neatu Ovidiu
On Thursday, August 8, 2013 2:12:53 PM UTC+3, Nicholas wrote:
 On Thu, Aug 8, 2013 at 11:38 AM, Neatu Ovidiu neat...@gmail.com wrote:
 
 
 
 
 
 
 
  But what's your use case?
 
 
 
  Does it occur often enough that you cannot afford a two-liner like
 
 I think uses cases are plenty.
 
 
 
 
 The possible cases I can think of would be better served with list 
 comprehensions (what you seem to want is to create lists based on other 
 lists) - but maybe I'm missing something.  Could we have one example?
 
 
 
 N.

This can be useful for doing all kinds of basic stuff. For example if you 
wanted to take 4 items of a list at at a time, do something with them and then 
update the list.

jobs = ['job1', 'job2', 'job3', 'job4', 'job5', 'job6', 'job7', 'job8', 'job9', 
'job10'] 
while jobs: 
print(jobs.pop_slice(0,4))

should output

'job1', 'job2', 'job3', 'job4'
'job5', 'job6', 'job7', 'job8'
'job9', 'job10'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: PEP for popping slices from lists

2013-08-08 Thread Neatu Ovidiu
On Thursday, August 8, 2013 2:44:05 PM UTC+3, Neatu Ovidiu wrote:
 On Thursday, August 8, 2013 2:12:53 PM UTC+3, Nicholas wrote:
 
  On Thu, Aug 8, 2013 at 11:38 AM, Neatu Ovidiu neat...@gmail.com wrote:
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
   But what's your use case?
 
  
 
  
 
  
 
   Does it occur often enough that you cannot afford a two-liner like
 
  
 
  I think uses cases are plenty.
 
  
 
  
 
  
 
  
 
  The possible cases I can think of would be better served with list 
  comprehensions (what you seem to want is to create lists based on other 
  lists) - but maybe I'm missing something.  Could we have one example?
 
  
 
  
 
  
 
  N.
 
 
 
 This can be useful for doing all kinds of basic stuff. For example if you 
 wanted to take 4 items of a list at at a time, do something with them and 
 then update the list.
 
 
 
 jobs = ['job1', 'job2', 'job3', 'job4', 'job5', 'job6', 'job7', 'job8', 
 'job9', 'job10'] 
 
 while jobs: 
 
 print(jobs.pop_slice(0,4))
 
 
 
 should output
 
 
 
 'job1', 'job2', 'job3', 'job4'
 
 'job5', 'job6', 'job7', 'job8'
 
 'job9', 'job10'

The idea popped in my mind while thinking about this question.
http://stackoverflow.com/questions/18121416/right-split-a-string-into-groups-of-3/18122084
I founded the list comprehensions solutions kind of cumbersome and thought that 
there should be a simple way to do this kind of stuff.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: outputting time in microseconds or milliseconds

2013-08-08 Thread Skip Montanaro
 i did:

from time import strftime, time
from datetime import datetime

now = datetime.now()

self.logfile.write('%s\t'%(strftime(%Y-%m-%d,)))
self.logfile.write('%s\t'%(now.strftime(%H:%M:%S.%f,)))

Note that you don't need the time module here.  Datetime objects have
what you need all by themselves:

from datetime import datetime
now = datetime.now()
self.logfile.write('%s\t%s\n' % (now.strftime(%Y-%m-%d),
 now.strftime(%H:%M:%S.%f)))

The time module was historically the way Python did time, but it
wasn't at all object-oriented and provided no direct support for date
arithmetic.  When Tim Peters wrote datetime, the world became a better
place.  Cozy up to the datetime documentation and put the time module
aside.

Skip

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


Re: Suggestion: PEP for popping slices from lists

2013-08-08 Thread Nicholas Cole
On Thu, Aug 8, 2013 at 12:50 PM, Neatu Ovidiu neatu...@gmail.com wrote:

 On Thursday, August 8, 2013 2:44:05 PM UTC+3, Neatu Ovidiu wrote:
  On Thursday, August 8, 2013 2:12:53 PM UTC+3, Nicholas wrote:
 
   On Thu, Aug 8, 2013 at 11:38 AM, Neatu Ovidiu neat...@gmail.com
 wrote:
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
But what's your use case?
 
  
 
   
 
  
 
Does it occur often enough that you cannot afford a two-liner like
 
  
 
   I think uses cases are plenty.
 
  
 
  
 
  
 
  
 
   The possible cases I can think of would be better served with list
 comprehensions (what you seem to want is to create lists based on other
 lists) - but maybe I'm missing something.  Could we have one example?
 
  
 
  
 
  
 
   N.
 
 
 
  This can be useful for doing all kinds of basic stuff. For example if
 you wanted to take 4 items of a list at at a time, do something with them
 and then update the list.
 
 
 
  jobs = ['job1', 'job2', 'job3', 'job4', 'job5', 'job6', 'job7', 'job8',
 'job9', 'job10']
 
  while jobs:
 
  print(jobs.pop_slice(0,4))
 
 
 
  should output
 
 
 
  'job1', 'job2', 'job3', 'job4'
 
  'job5', 'job6', 'job7', 'job8'
 
  'job9', 'job10'

 The idea popped in my mind while thinking about this question.

 http://stackoverflow.com/questions/18121416/right-split-a-string-into-groups-of-3/18122084
 I founded the list comprehensions solutions kind of cumbersome and thought
 that there should be a simple way to do this kind of stuff.
 --
 http://mail.python.org/mailman/listinfo/python-list



Still seems a bit like a solution looking for a problem to me.

Why would you want to take four items at a time for a job from an arbitrary
part of a list?  I agree splitting a string into groups of three looks a
bit cumbersome in the example you've given, but a generator could be
written quite easily, and would almost certainly be quicker than trying to
alter the list in place.

Best wishes,

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


Re: outputting time in microseconds or milliseconds

2013-08-08 Thread Roy Smith
In article mailman.349.1375963829.1251.python-l...@python.org,
 Skip Montanaro s...@pobox.com wrote:

 When Tim Peters wrote datetime, the world became a better
 place.  

Lots of languages and databases have things called datetimes.  It's easy 
to be lulled into thinking that they're all the same, but they're not.  
They all have slightly different ranges and precisions.

Just something to be aware of.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: PEP for popping slices from lists

2013-08-08 Thread Neatu Ovidiu
On Thursday, August 8, 2013 4:08:13 PM UTC+3, Nicholas wrote:
 On Thu, Aug 8, 2013 at 12:50 PM, Neatu Ovidiu neat...@gmail.com wrote:
 
 
 
 
 On Thursday, August 8, 2013 2:44:05 PM UTC+3, Neatu Ovidiu wrote:
 
  On Thursday, August 8, 2013 2:12:53 PM UTC+3, Nicholas wrote:
 
 
 
   On Thu, Aug 8, 2013 at 11:38 AM, Neatu Ovidiu neat...@gmail.com wrote:
 
 
 
  
 
 
 
  
 
 
 
  
 
 
 
  
 
 
 
  
 
 
 
  
 
 
 
  
 
 
 
But what's your use case?
 
 
 
  
 
 
 
   
 
 
 
  
 
 
 
Does it occur often enough that you cannot afford a two-liner like
 
 
 
  
 
 
 
   I think uses cases are plenty.
 
 
 
  
 
 
 
  
 
 
 
  
 
 
 
  
 
 
 
   The possible cases I can think of would be better served with list 
   comprehensions (what you seem to want is to create lists based on other 
   lists) - but maybe I'm missing something.  Could we have one example?
 
 
 
 
  
 
 
 
  
 
 
 
  
 
 
 
   N.
 
 
 
 
 
 
 
  This can be useful for doing all kinds of basic stuff. For example if you 
  wanted to take 4 items of a list at at a time, do something with them and 
  then update the list.
 
 
 
 
 
 
 
  jobs = ['job1', 'job2', 'job3', 'job4', 'job5', 'job6', 'job7', 'job8', 
  'job9', 'job10']
 
 
 
  while jobs:
 
 
 
      print(jobs.pop_slice(0,4))
 
 
 
 
 
 
 
  should output
 
 
 
 
 
 
 
  'job1', 'job2', 'job3', 'job4'
 
 
 
  'job5', 'job6', 'job7', 'job8'
 
 
 
  'job9', 'job10'
 
 
 
 The idea popped in my mind while thinking about this question.
 
 http://stackoverflow.com/questions/18121416/right-split-a-string-into-groups-of-3/18122084
 
 I founded the list comprehensions solutions kind of cumbersome and thought 
 that there should be a simple way to do this kind of stuff.
 
 --
 
 http://mail.python.org/mailman/listinfo/python-list
 
 
 
 
 
 Still seems a bit like a solution looking for a problem to me.
 
 
 
 Why would you want to take four items at a time for a job from an arbitrary 
 part of a list?  I agree splitting a string into groups of three looks a bit 
 cumbersome in the example you've given, but a generator could be written 
 quite easily, and would almost certainly be quicker than trying to alter the 
 list in place.
 
 
 
 Best wishes,
 
 
 N.

You are perfectly right. But I looked at it more like an improvement in the 
style of writing solutions and also a natural option because slices are highly 
present all over in python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: PEP for popping slices from lists

2013-08-08 Thread Nicholas Cole
On Thu, Aug 8, 2013 at 2:32 PM, Neatu Ovidiu neatu...@gmail.com wrote:

 On Thursday, August 8, 2013 4:08:13 PM UTC+3, Nicholas wrote:
  On Thu, Aug 8, 2013 at 12:50 PM, Neatu Ovidiu neat...@gmail.com wrote:
 
 
 
 
  On Thursday, August 8, 2013 2:44:05 PM UTC+3, Neatu Ovidiu wrote:
 
   On Thursday, August 8, 2013 2:12:53 PM UTC+3, Nicholas wrote:
 
  
 
On Thu, Aug 8, 2013 at 11:38 AM, Neatu Ovidiu neat...@gmail.com
 wrote:
 
  
 
   
 
  
 
   
 
  
 
   
 
  
 
   
 
  
 
   
 
  
 
   
 
  
 
   
 
  
 
 But what's your use case?
 
  
 
   
 
  
 

 
  
 
   
 
  
 
 Does it occur often enough that you cannot afford a two-liner like
 
  
 
   
 
  
 
I think uses cases are plenty.
 
  
 
   
 
  
 
   
 
  
 
   
 
  
 
   
 
  
 
The possible cases I can think of would be better served with list
 comprehensions (what you seem to want is to create lists based on other
 lists) - but maybe I'm missing something.  Could we have one example?
 
 
  
 
   
 
  
 
   
 
  
 
   
 
  
 
N.
 
  
 
  
 
  
 
   This can be useful for doing all kinds of basic stuff. For example if
 you wanted to take 4 items of a list at at a time, do something with them
 and then update the list.
 
  
 
  
 
  
 
   jobs = ['job1', 'job2', 'job3', 'job4', 'job5', 'job6', 'job7',
 'job8', 'job9', 'job10']
 
  
 
   while jobs:
 
  
 
   print(jobs.pop_slice(0,4))
 
  
 
  
 
  
 
   should output
 
  
 
  
 
  
 
   'job1', 'job2', 'job3', 'job4'
 
  
 
   'job5', 'job6', 'job7', 'job8'
 
  
 
   'job9', 'job10'
 
 
 
  The idea popped in my mind while thinking about this question.
 
 
 http://stackoverflow.com/questions/18121416/right-split-a-string-into-groups-of-3/18122084
 
  I founded the list comprehensions solutions kind of cumbersome and
 thought that there should be a simple way to do this kind of stuff.
 
  --
 
  http://mail.python.org/mailman/listinfo/python-list
 
 
 
 
 
  Still seems a bit like a solution looking for a problem to me.
 
 
 
  Why would you want to take four items at a time for a job from an
 arbitrary part of a list?  I agree splitting a string into groups of three
 looks a bit cumbersome in the example you've given, but a generator could
 be written quite easily, and would almost certainly be quicker than trying
 to alter the list in place.
 
 
 
  Best wishes,
 
 
  N.

 You are perfectly right. But I looked at it more like an improvement in
 the style of writing solutions and also a natural option because slices are
 highly present all over in python.



I wasn't knocking it.  I was just trying to think it through.
-- 
http://mail.python.org/mailman/listinfo/python-list


right adjusted strings containing umlauts

2013-08-08 Thread Kurt Mueller
I'd like to print strings right adjusted.
( Python 2.7.3, Linux 3.4.47-2.38-desktop )

from __future__ import print_function
print( '{0:3}'.format( 'a' ) )
  a

But if the string contains an Umlaut:
print( '{0:3}'.format( 'ä' ) )
 ä

Same with % notation:
print( '%3s' % ( 'a' ) )
  a
print( '%3s' % ( 'ä' ) )
 ä

For a string with no Umlaut it uses 3 characters, but for an Umlaut
it uses only 2 characters.

I guess it has to to with unicode.
How do I get it right?


TIA
-- 
Kurt Mueller

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


Re: right adjusted strings containing umlauts

2013-08-08 Thread Neil Cerutti
On 2013-08-08, Kurt Mueller kurt.alfred.muel...@gmail.com wrote:
 I'd like to print strings right adjusted.
 ( Python 2.7.3, Linux 3.4.47-2.38-desktop )

 from __future__ import print_function
 print( '{0:3}'.format( 'a' ) )
  a

 But if the string contains an Umlaut:
 print( '{0:3}'.format( '??' ) )
 ??

 Same with % notation:
 print( '%3s' % ( 'a' ) )
  a
 print( '%3s' % ( '??' ) )
 ??

 For a string with no Umlaut it uses 3 characters, but for an
 Umlaut it uses only 2 characters.

 I guess it has to to with unicode.
 How do I get it right?

You guessed it!

Use unicode strings instead of byte strings, e.g., u

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


Re: right adjusted strings containing umlauts

2013-08-08 Thread jfharden
On Thursday, 8 August 2013 15:23:46 UTC+1, Kurt Mueller  wrote:
 I'd like to print strings right adjusted.
 
 print( '{0:3}'.format( 'ä' ) )
 

Make both strings unicode

print( u'{0:3}'.format( u'ä' ) )

Why not use rjust for it though?

u'ä'.rjust(3)

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


Re: Suggestion: PEP for popping slices from lists

2013-08-08 Thread Skip Montanaro
On Thu, Aug 8, 2013 at 6:40 AM, Neatu Ovidiu neatu...@gmail.com wrote:
 This can be useful for doing all kinds of basic stuff. For example if you 
 wanted to take 4 items of a list at at a time, do something with them and 
 then update the list.

 jobs = ['job1', 'job2', 'job3', 'job5', 'job6', 'job7', 'job8', 'job9', 
 'job10']
 while jobs:
 print jobs.pop_slice(0,4)

My initial reaction to this is that you want to infer structure where
none exists, so why not make the structure explicit?  In any case,
couldn't you subclass the list type and add a pop_slice method to do
what you want?  I'm not an iterator maven, but this also seems like
something you could mix up from something in the itertools module.

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


Re: right adjusted strings containing umlauts

2013-08-08 Thread MRAB

On 08/08/2013 15:40, Neil Cerutti wrote:

On 2013-08-08, Kurt Mueller kurt.alfred.muel...@gmail.com wrote:

I'd like to print strings right adjusted.
( Python 2.7.3, Linux 3.4.47-2.38-desktop )

from __future__ import print_function
print( '{0:3}'.format( 'a' ) )

 a


But if the string contains an Umlaut:
print( '{0:3}'.format( '??' ) )

??


Same with % notation:
print( '%3s' % ( 'a' ) )

 a

print( '%3s' % ( '??' ) )

??


For a string with no Umlaut it uses 3 characters, but for an
Umlaut it uses only 2 characters.

I guess it has to to with unicode.
How do I get it right?


You guessed it!

Use unicode strings instead of byte strings, e.g., u


It also matters which actual codepoints you're using in the Unicode
string.

You could have u'ä', which is one codepoint (u'\xE4' or u'\N{LATIN
SMALL LETTER A WITH DIAERESIS}'), or u'ä', which two codepoints
(u'a\u0308' or u'\N{LATIN SMALL LETTER A}\N{COMBINING DIAERESIS}').

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


Re: right adjusted strings containing umlauts

2013-08-08 Thread Kurt Mueller
Am 08.08.2013 16:43, schrieb jfhar...@gmail.com:
 On Thursday, 8 August 2013 15:23:46 UTC+1, Kurt Mueller  wrote:
 I'd like to print strings right adjusted.
 print( '{0:3}'.format( 'ä' ) )
 
 Make both strings unicode
 print( u'{0:3}'.format( u'ä' ) )
 Why not use rjust for it though?
 u'ä'.rjust(3)

In real life there is a list of strings in output_list from a command like:
output_list = shlex.split( input_string, bool_cmnt, bool_posi, )
input_string is from a file, bool_* are either True or False
repr( output_list )
['\xc3\xb6', '\xc3\xbc', 'i', 's', 'f']
which should be printed right aligned.
using:
print( u'{0:3} {1:3} {2:3} {3:3} {4:3}'.format( *output_list ) )
( In real life, the alignement and the width is variable )

How do I prepare output_list the pythonic way to be unicode strings?
What do I do, when input_strings/output_list has other codings like iso-8859-1?

TIA
-- 
Kurt Mueller

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


Re: right adjusted strings containing umlauts

2013-08-08 Thread Peter Otten
Kurt Mueller wrote:

 Am 08.08.2013 16:43, schrieb jfhar...@gmail.com:
 On Thursday, 8 August 2013 15:23:46 UTC+1, Kurt Mueller  wrote:
 I'd like to print strings right adjusted.
 print( '{0:3}'.format( 'ä' ) )
 
 Make both strings unicode
 print( u'{0:3}'.format( u'ä' ) )
 Why not use rjust for it though?
 u'ä'.rjust(3)
 
 In real life there is a list of strings in output_list from a command
 like: output_list = shlex.split( input_string, bool_cmnt, bool_posi, )
 input_string is from a file, bool_* are either True or False
 repr( output_list )
 ['\xc3\xb6', '\xc3\xbc', 'i', 's', 'f']
 which should be printed right aligned.
 using:
 print( u'{0:3} {1:3} {2:3} {3:3} {4:3}'.format( *output_list ) )
 ( In real life, the alignement and the width is variable )
 
 How do I prepare output_list the pythonic way to be unicode strings?
 What do I do, when input_strings/output_list has other codings like
 iso-8859-1?

You have to know the actual encoding. With that information it's easy:

 output_list
['\xc3\xb6', '\xc3\xbc', 'i', 's', 'f']
 encoding = utf-8
 output_list = [s.decode(encoding) for s in output_list]
 print output_list
[u'\xf6', u'\xfc', u'i', u's', u'f']

Don't worry that there are still escape codes -- when you print the 
individual list items the caracters will show up as expected:

 print , .join(output_list)
ö, ü, i, s, f


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


Re: right adjusted strings containing umlauts

2013-08-08 Thread Dave Angel
Kurt Mueller wrote:

 Am 08.08.2013 16:43, schrieb jfhar...@gmail.com:
 On Thursday, 8 August 2013 15:23:46 UTC+1, Kurt Mueller  wrote:
 I'd like to print strings right adjusted.
 print( '{0:3}'.format( 'ä' ) )
 
 Make both strings unicode
 print( u'{0:3}'.format( u'ä' ) )
 Why not use rjust for it though?
 u'ä'.rjust(3)

 In real life there is a list of strings in output_list from a command like:
 output_list = shlex.split( input_string, bool_cmnt, bool_posi, )
 input_string is from a file, bool_* are either True or False
 repr( output_list )
 ['\xc3\xb6', '\xc3\xbc', 'i', 's', 'f']
 which should be printed right aligned.
 using:
 print( u'{0:3} {1:3} {2:3} {3:3} {4:3}'.format( *output_list ) )
 ( In real life, the alignement and the width is variable )

 How do I prepare output_list the pythonic way to be unicode strings?
 What do I do, when input_strings/output_list has other codings like 
 iso-8859-1?


In general, when reading from an outside device like a file, convert to
unicode immediately, while you still know the encoding used in that
particular file.  Then after all processing, worry about alignment only
when you're about to output the string.  And at that point, you're
subject to the quirks of the font as well as the quirks of the
encoding of the terminal.

As MRAB has pointed out, sometimes two code points are used to represent
 a single character which will end up taking a single column.  Likewise
sometimes a single code point will take more than one column to
display.  Ideograms are one example, but a font which is not fixed pitch
 is another.

If you're going to a standard terminal, all you can do is get close. 
This is why there are special functions for gui's to help with
alignment.



-- 
DaveA


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


Re: right adjusted strings containing umlauts

2013-08-08 Thread Kurt Mueller
Am 08.08.2013 17:44, schrieb Peter Otten:
 Kurt Mueller wrote:
 What do I do, when input_strings/output_list has other codings like
 iso-8859-1?
 
 You have to know the actual encoding. With that information it's easy:
 output_list
 ['\xc3\xb6', '\xc3\xbc', 'i', 's', 'f']
 encoding = utf-8
 output_list = [s.decode(encoding) for s in output_list]
 print output_list
 [u'\xf6', u'\xfc', u'i', u's', u'f']

How do I get to know the actual encoding?
I read from stdin. There can be different encondings.
Usually utf8 but also iso-8859-1/latin9 are to be expected.
But sys.stdin.encoding sais always 'None'.


TIA
-- 
Kurt Mueller
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mock pathc question

2013-08-08 Thread balderman
On Thursday, August 8, 2013 12:04:38 PM UTC+2, Jean-Michel Pichavant wrote:
 - Mail original - 
 
  Hi
  1) I prefer to use start/stop and not the decorator .
  2) mock_play is the name of the module where the code belongs
 
  Thanks
 
  Avishay
  Sent from my iPhone
 
 
 You should not neeed to refer to the Calc class using mock_play since it is 
 defined in the very same file (module).
 Possibly mock_play.Calc and Calc are 2 different classes, hence you're not 
 patching the good one.
 
 Note how you patch mock_play.Calc and then instanciate using self.calc = 
 Calc()
 
 right before
 my_mock = mock.patch('mock_play.Calc',create=True, new=MockCalc)
 
 add 
 print mock_play.Calc
 print Calc
 
 
 and verify that they are both the very same object.
 
 Cheers,
 
 JM
 
 
 PS : Please do not top post in this list
 
 
 -- IMPORTANT NOTICE: 
 
 The contents of this email and any attachments are confidential and may also 
 be privileged. If you are not the intended recipient, please notify the 
 sender immediately and do not disclose the contents to any other person, use 
 it for any purpose, or store or copy the information in any medium. Thank you.

Hi
Here is a working solution: 
http://stackoverflow.com/questions/18121084/mock-patch-does-not-work-properly

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


Re: Is it possible to make a unittest decorator to rename a method from x to testx?

2013-08-08 Thread adam . preble
On Thursday, August 8, 2013 3:50:47 AM UTC-5, Peter Otten wrote:
 Peter Otten wrote:
 Oops, that's an odd class name. Fixing the name clash in Types.__new__() is 
 
 left as an exercise...

I will do some experiments with a custom test loader since I wasn't aware of 
that as a viable alternative.  I am grateful for the responses.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: right adjusted strings containing umlauts

2013-08-08 Thread Kurt Mueller
Now I have this small example:
--
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :

from __future__ import print_function
import sys, shlex

print( repr( sys.stdin.encoding ) )

strg_form = u'{0:3} {1:3} {2:3} {3:3} {4:3}'
for inpt_line in sys.stdin:
proc_line = shlex.split( inpt_line, False, True, )
encoding = utf-8
proc_line = [ strg.decode( encoding ) for strg in proc_line ]
print( strg_form.format( *proc_line ) )
--

$ echo -e a b c d e\na ö u 1 2 | file -
/dev/stdin: UTF-8 Unicode text
$ echo -e a b c d e\na ö u 1 2 | ./align_compact.py
None
  a   b   c   d   e
  a   ö   u   1   2
$ echo -e a b c d e\na ö u 1 2 | recode utf8..latin9 | file -
/dev/stdin: ISO-8859 text
$ echo -e a b c d e\na ö u 1 2 | recode utf8..latin9 | ./align_compact.py
None
  a   b   c   d   e
Traceback (most recent call last):
  File ./align_compact.py, line 13, in module
proc_line = [ strg.decode( encoding ) for strg in proc_line ]
  File /usr/lib64/python2.7/encodings/utf_8.py, line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xf6 in position 0: invalid 
start byte
muk@mcp20:/sw/prog/scripts/text_manip

How do I handle this two inputs?


TIA
-- 
Kurt Mueller

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


Re: Is it possible to make a unittest decorator to rename a method from x to testx?

2013-08-08 Thread adam . preble
On Thursday, August 8, 2013 3:04:30 AM UTC-5, Terry Reedy wrote:
 I cannot help but note that this is *more* typing. But anyhow, something 

It wasn't so much about the typing so much as having test in front of 
everything.  It's a problem particular to me since I'm writing code that, well, 
runs experiments.  So the word test is already all over the place.  I would 
even prefer if I could do away with assuming everything starting with test is 
a unittest, but I didn't think I could; it looks like Peter Otten got me in the 
right direction.

 like this might work.
 

 def test(f):
 
  f.__class__.__dict__['test_'+f.__name__]
 
 
 
 might work. Or maybe for the body just
 
 setattr(f.__class__, 'test_'+f.__name__)
 

Just for giggles I can mess around with those exact lines, but I did get 
spanked trying to do something similar.  I couldn't reference __class__ for 
some reason (Python 2.7 problem?).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: right adjusted strings containing umlauts

2013-08-08 Thread Peter Otten
Kurt Mueller wrote:

 Am 08.08.2013 17:44, schrieb Peter Otten:
 Kurt Mueller wrote:
 What do I do, when input_strings/output_list has other codings like
 iso-8859-1?
 
 You have to know the actual encoding. With that information it's easy:
 output_list
 ['\xc3\xb6', '\xc3\xbc', 'i', 's', 'f']
 encoding = utf-8
 output_list = [s.decode(encoding) for s in output_list]
 print output_list
 [u'\xf6', u'\xfc', u'i', u's', u'f']
 
 How do I get to know the actual encoding?
 I read from stdin. There can be different encondings.
 Usually utf8 but also iso-8859-1/latin9 are to be expected.
 But sys.stdin.encoding sais always 'None'.

Even with

$ cat funny_pic.jpg | ./mypythonscript.py

you could successfully (i. e. no errors) decode stdin using iso-8859-1.
So unfortunately you have to guess. 

A simple strategy is to try utf-8 and fall back to iso-8859-1 if that fails 
with a UnicodeDecodeError. There's also

https://pypi.python.org/pypi/chardet


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


Re: right adjusted strings containing umlauts

2013-08-08 Thread Chris Angelico
On Thu, Aug 8, 2013 at 5:16 PM, Kurt Mueller
kurt.alfred.muel...@gmail.com wrote:
 Am 08.08.2013 17:44, schrieb Peter Otten:
 Kurt Mueller wrote:
 What do I do, when input_strings/output_list has other codings like
 iso-8859-1?

 You have to know the actual encoding. With that information it's easy:
 output_list
 ['\xc3\xb6', '\xc3\xbc', 'i', 's', 'f']
 encoding = utf-8
 output_list = [s.decode(encoding) for s in output_list]
 print output_list
 [u'\xf6', u'\xfc', u'i', u's', u'f']

 How do I get to know the actual encoding?
 I read from stdin. There can be different encondings.
 Usually utf8 but also iso-8859-1/latin9 are to be expected.
 But sys.stdin.encoding sais always 'None'.

If you can switch to Python 3, life becomes a LOT easier. The Python 3
input() function (which does the same job as raw_input() from Python
2) returns a Unicode string, meaning that it takes care of encodings
for you.

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


RE: Newbie: static typing?

2013-08-08 Thread Prasad, Ramit
Rui Maciel wrote:
 Chris Angelico wrote:
 
  On Tue, Aug 6, 2013 at 10:01 AM, Rui Maciel rui.mac...@gmail.com wrote:
  It would be nice if some functions threw an error if they were passed a
  type
  they don't support or weren't designed to handle.  That would avoid
  having to deal with some bugs which otherwise would never happen.
 
  To avoid this sort of error, I've been testing arguments passed to some
  functions based on their type, and raising TypeError when necessariy, but
  surely there must be a better, more pythonic way to handle this issue.
 
  def add_three_values(x,y,z):
  return x+y+z
 
  Do you want to test these values for compatibility? Remember, you
  could take a mixture of types, as most of the numeric types can safely
  be added. You can also add strings, or lists, but you can't mix them.
  And look! It already raises TypeError if it's given something
  unsuitable:
 
 If the type problems aren't caught right away when the invalid types are
 passed to a function then the problem may only manifest itself in some far
 away point in the code, making this bug needlessly harder to spot and fix,
 and making the whole ordeal needlessly too time consuming.
 
 
 Rui Maciel

This can be true, but in personal experience does not happen 
often. I will say that dynamic typing ends up usually
being more future proof as I can later create a similar object
(but not in the same inheritance hierarchy) that will work
with older functions because the functions don't look for
certain types but rather just rely on duck typing.

I find this especially useful when testing or mocking. I can
create a test object and attach methods/attributes to the
test object to duck type as I desire to test the my desired code. 

I think the following reads are very interesting
for people new to Python from other languages (not just Java).
http://dirtsimple.org/2004/12/python-is-not-java.html
(and the flip side) http://dirtsimple.org/2004/12/java-is-not-python-either.html


~Ramit



This email is confidential and subject to important disclaimers and conditions 
including on offers for the purchase or sale of securities, accuracy and 
completeness of information, viruses, confidentiality, legal privilege, and 
legal entity disclaimers, available at 
http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to make a unittest decorator to rename a method from x to testx?

2013-08-08 Thread Ned Batchelder

On 8/8/13 12:17 PM, adam.pre...@gmail.com wrote:

On Thursday, August 8, 2013 3:50:47 AM UTC-5, Peter Otten wrote:

Peter Otten wrote:
Oops, that's an odd class name. Fixing the name clash in Types.__new__() is

left as an exercise...

I will do some experiments with a custom test loader since I wasn't aware of 
that as a viable alternative.  I am grateful for the responses.
If you can use another test runner, they often have more flexible and 
powerful ways to do everything.  nosetests will let you use a __test__ 
attribute, for example, to mark tests.  Your decorator could simply 
assign that attribute on the test methods.


You'd still write your tests using the unittest base classes, but run 
them with nose.


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


Re: right adjusted strings containing umlauts

2013-08-08 Thread Dave Angel
Kurt Mueller wrote:

 Now I have this small example:
 --
 #!/usr/bin/env python
 # vim: set fileencoding=utf-8 :

 from __future__ import print_function
 import sys, shlex

 print( repr( sys.stdin.encoding ) )

 strg_form = u'{0:3} {1:3} {2:3} {3:3} {4:3}'
 for inpt_line in sys.stdin:
 proc_line = shlex.split( inpt_line, False, True, )
 encoding = utf-8
 proc_line = [ strg.decode( encoding ) for strg in proc_line ]
 print( strg_form.format( *proc_line ) )
 --

 $ echo -e a b c d e\na ö u 1 2 | file -
 /dev/stdin: UTF-8 Unicode text
 $ echo -e a b c d e\na ö u 1 2 | ./align_compact.py
 None
   a   b   c   d   e
   a   ö   u   1   2
 $ echo -e a b c d e\na ö u 1 2 | recode utf8..latin9 | file -
 /dev/stdin: ISO-8859 text
 $ echo -e a b c d e\na ö u 1 2 | recode utf8..latin9 | ./align_compact.py
 None
   a   b   c   d   e
 Traceback (most recent call last):
   File ./align_compact.py, line 13, in module
 proc_line = [ strg.decode( encoding ) for strg in proc_line ]
   File /usr/lib64/python2.7/encodings/utf_8.py, line 16, in decode
 return codecs.utf_8_decode(input, errors, True)
 UnicodeDecodeError: 'utf8' codec can't decode byte 0xf6 in position 0: 
 invalid start byte
 muk@mcp20:/sw/prog/scripts/text_manip

 How do I handle this two inputs?


Once you're using pipes, you've given up any hope that the terminal will
report a useful encoding, so I'm not surprised you're getting None for
sys.stdin.encoding()

So you can either do as others have suggested, and guess, or you can get
the information explicitly, say from argv.  In any case you'll need a
different way to assign   encoding = 


-- 
DaveA

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


Re: paramiko installation problem

2013-08-08 Thread D. Xenakis
 import sys
 print (sys.path)

returns:

['C:\\Python33\\Lib\\idlelib', 
'C:\\Python33\\lib\\site-packages\\pip-1.4-py3.3.egg', 
'C:\\Windows\\system32\\python33.zip', 'C:\\Python33\\DLLs', 
'C:\\Python33\\lib', 'C:\\Python33', 'C:\\Python33\\lib\\site-packages']

then if i type:
 sys.path.append('C:\\Python33\\Lib\\site-packages\\paramiko')

and then again..
 print (sys.path)

returns:

['C:\\Python33\\Lib\\idlelib', 
'C:\\Python33\\lib\\site-packages\\pip-1.4-py3.3.egg', 
'C:\\Windows\\system32\\python33.zip', 'C:\\Python33\\DLLs', 
'C:\\Python33\\lib', 'C:\\Python33', 'C:\\Python33\\lib\\site-packages', 
'C:\\Python33\\Lib\\site-packages\\paramiko']

then if i type:
 import paramiko

i get this:

Traceback (most recent call last):
  File pyshell#3, line 1, in module
import paramiko
  File C:\Python33\lib\site-packages\paramiko\__init__.py, line 64, in 
module
from transport import SecurityOptions, Transport
  File C:\Python33\Lib\site-packages\paramiko\transport.py, line 296
except socket.error, e:
   ^
SyntaxError: invalid syntax

--
when i close and reopen IDLE, then 'C:\\Python33\\Lib\\site-packages\\paramiko' 
is getting deleted.

If my problem from the first post above has to do something with the path, then 
what exactly should i do?

I would also like to ask here something extra.. :)

in system enviroment variables my path contains the following things:

C:\Python33\Lib\site-packages\PyQt5;C:\Python33\Scripts\;C:\Python33\;C:\Program
 Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Common 
Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common 
Files\Microsoft Shared\Windows 
Live;C:\Python33\Lib\site-packages\paramiko;C:\Program Files (x86)\Intel\iCLS 
Client\;C:\Program Files\Intel\iCLS 
Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program
 Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program 
Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files 
(x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files 
(x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files 
(x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL 
SDK\2.0\bin\x64;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program 
Files\NEST;C:\Program Files (x86)\Windows Live\Shared

so what exactly is the difference between this path and the above.?

A huge THANKS for the one who will find the courage to answer to this newbie !
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: paramiko installation problem

2013-08-08 Thread MRAB

On 08/08/2013 19:04, D. Xenakis wrote:

import sys
print (sys.path)


returns:

['C:\\Python33\\Lib\\idlelib', 
'C:\\Python33\\lib\\site-packages\\pip-1.4-py3.3.egg', 
'C:\\Windows\\system32\\python33.zip', 'C:\\Python33\\DLLs', 
'C:\\Python33\\lib', 'C:\\Python33', 'C:\\Python33\\lib\\site-packages']

then if i type:

sys.path.append('C:\\Python33\\Lib\\site-packages\\paramiko')


and then again..

print (sys.path)


returns:

['C:\\Python33\\Lib\\idlelib', 
'C:\\Python33\\lib\\site-packages\\pip-1.4-py3.3.egg', 
'C:\\Windows\\system32\\python33.zip', 'C:\\Python33\\DLLs', 
'C:\\Python33\\lib', 'C:\\Python33', 'C:\\Python33\\lib\\site-packages', 
'C:\\Python33\\Lib\\site-packages\\paramiko']

then if i type:

import paramiko


i get this:

Traceback (most recent call last):
   File pyshell#3, line 1, in module
 import paramiko
   File C:\Python33\lib\site-packages\paramiko\__init__.py, line 64, in 
module
 from transport import SecurityOptions, Transport
   File C:\Python33\Lib\site-packages\paramiko\transport.py, line 296
 except socket.error, e:
^
SyntaxError: invalid syntax


[snip]

That syntax is supported in Python 2. In Python 3 it would be:

except socket.error as e:

I don't think that paramiko supports Python 3 (yet?).

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


How Do I get my Python script to attach multiple files and send as a single email

2013-08-08 Thread wachkama
I have a dilemma I cant figure out how to send multiple files as an attachment 
to my email using this script. I can only send a single file attachment . 
Help!!!  Here is my script.
All filename's are txt files.


fo = with open(filename,'rb')
fo1 = open(filename2,'rb')
fo2= open(filename3, 'rb')
fo3= open(filename4,'rb')
fo4=open(filename5, rb)
filecontent = fo.read()
filecontent1 = fo1.read()
filecontent2 = fo2.read()
filecontent3 = fo3.read()
filecontent4= fo4.read()
encodedcontent = base64.b64encode(filecontent)  # base64
encodedcontent1 = base64.b64encode(filecontent1)  # base64
encodedcontent2 = base64.b64encode(filecontent2)  # base64
encodedcontent3 = base64.b64encode(filecontent3)  # base64
encodedcontent4 = base64.b64encode(filecontent4)  # base64

sender = 'm...@mysite.com'
reciever = 'm...@mymail.com'

marker = AUNIQUEMARKER

body =
Hi 
This is Sam, I have a some files containing some tickets for you.
Good day 
:)

# Define the main headers.
part1 = From:  Master Tickets ams...@mysite.com
To: To Samuel Kamau m...@myemail.com
Subject: Sending Attachement
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=%s
--%s
 % (marker, marker)

# Define the message action
part2 = Content-Type: text/plain
Content-Transfer-Encoding:8bit

%s
--%s
 % (body,marker)

# Define the attachment section
part3 = Content-Type: multipart/mixed; name=\%s\
Content-Transfer-Encoding:base64
Content-Disposition: attachment; filename=%s

%s
--%s--
 %(filename, filename, encodedcontent, marker)
message = part1 + part2 + part3


try:
   smtpObj = smtplib.SMTP('mx.usa.net')
   smtpObj.sendmail(sender, reciever, message,)
   print Successfully sent email
except Exception:
   print Error: unable to send email

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


Re: Is it possible to make a unittest decorator to rename a method from x to testx?

2013-08-08 Thread Terry Reedy

On 8/8/2013 12:20 PM, adam.pre...@gmail.com wrote:

On Thursday, August 8, 2013 3:04:30 AM UTC-5, Terry Reedy wrote:



def test(f):

  f.__class__.__dict__['test_'+f.__name__]


Sorry, f.__class__ is 'function', not the enclosing class. A decorator 
for a method could not get the enclosing class name until 3.3, when it 
would be part of f.__qualname__.


Use one of the other suggestions.


Just for giggles I can mess around with those exact lines, but I did get 
spanked trying to do something similar.  I couldn't reference __class__ for 
some reason (Python 2.7 problem?).


In 2.x, old-style classes and instances thereof do not have .__class__. 
All other objects do, as far as I know.


--
Terry Jan Reedy

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


Re: How Do I get my Python script to attach multiple files and send as a single email

2013-08-08 Thread Gary Herron

On 08/08/2013 12:05 PM, wachk...@gmail.com wrote:

I have a dilemma I cant figure out how to send multiple files as an attachment 
to my email using this script. I can only send a single file attachment . 
Help!!!  Here is my script.
All filename's are txt files.





There is a standard Python module named email which you should look 
at.   It can build an email with all the parts, alternates, and 
attachments you want.  Then you send the resulting message using your 
smtplib code.  The email module is large and complex, but reasonably 
easy to learn (following the documentation examples). It's far, FAR, 
easier than rolling your message, especially when attachments are needed.


Gary Herron

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


Re: paramiko installation problem

2013-08-08 Thread D. Xenakis
Wow thats bad news. Any workaround?

What im trying to succeed here is create one SSH tunnel, so that i can connect 
from a python script running on my pc, to a remote MySQL database running on my 
Host and id like to stick with Python 3.3 .
Any thoughts?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How Do I get my Python script to attach multiple files and send as a single email

2013-08-08 Thread Ian Kelly
On Thu, Aug 8, 2013 at 1:05 PM,  wachk...@gmail.com wrote:
 I have a dilemma I cant figure out how to send multiple files as an 
 attachment to my email using this script. I can only send a single file 
 attachment . Help!!!  Here is my script.

You just need to repeat part3 for each attachment.  Also the content
type in part3 should be the content type of the attachment, not
multipart/mixed.

You might also want to take a look at the email package in the
standard library which will do a lot of this stuff for you.

http://docs.python.org/3/library/email.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How Do I get my Python script to attach multiple files and send as a single email

2013-08-08 Thread Joel Goldstick
On Thu, Aug 8, 2013 at 3:19 PM, Gary Herron
gary.her...@islandtraining.com wrote:
 On 08/08/2013 12:05 PM, wachk...@gmail.com wrote:

 I have a dilemma I cant figure out how to send multiple files as an
 attachment to my email using this script. I can only send a single file
 attachment . Help!!!  Here is my script.
 All filename's are txt files.




 There is a standard Python module named email which you should look at.
 It can build an email with all the parts, alternates, and attachments you
 want.  Then you send the resulting message using your smtplib code.  The
 email module is large and complex, but reasonably easy to learn (following
 the documentation examples). It's far, FAR, easier than rolling your
 message, especially when attachments are needed.

 Gary Herron

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

Here is a good example:

http://stackoverflow.com/questions/3362600/how-to-send-email-attachments-with-python

I found it using the following google search: python send email using
smtp with multiple attachment

It was the second result.

Google is your friend ;)

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


Python 3 and SSH Tunnel

2013-08-08 Thread D. Xenakis
HOWTO anyone?

What im trying to succeed here is create one SSH tunnel, so that i can connect 
from a python script running on my pc, to a remote MySQL database running on my 
Host and id like to stick with Python 3.3 .

I contacted my host and he informed me that this is the only way.

I tried pycrypto + paramiko but from what i have noticed, paramiko is not 
Python 3.3 ready.
Any thoughts?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: PEP for popping slices from lists

2013-08-08 Thread Terry Reedy

On 8/8/2013 7:44 AM, Neatu Ovidiu wrote:

Objection 1. People usually want to chunk sequences, not lists 
specifically. We now try to add new features that work with iterators 
and iterables generally, not just lists.



This can be useful for doing all kinds of basic stuff. For example if you 
wanted to take 4 items of a list at at a time, do something with them and then 
update the list.

jobs = ['job1', 'job2', 'job3', 'job4', 'job5', 'job6', 'job7', 'job8', 'job9', 
'job10']
while jobs:
 print(jobs.pop_slice(0,4))

should output

'job1', 'job2', 'job3', 'job4'
'job5', 'job6', 'job7', 'job8'
'job9', 'job10'


Objection 2. Usually when one wants to do this sort of thing, one wants 
the list either be intact or empty at the end. Emptying it chunk by 
chunk is worse than useless because it turns an O(n) process into an 
O(n*n) process.


The same is true of destructively iterating through a list with .pop(0). 
When I proposed the addition of .pop(), I meant it as the inverses of 
.append and did not include the (optional) index parameter. It is seldom 
used and usually only once, to remove a single leading item. The 
addition of iterators, which occurred *after* the addition of .pop, 
replaced some uses of .pop(0). For instance


first = mylist.pop(0)  # O(N) operation
for item in mylist:
  process(first, item)
del mylist

can, since 2.2, be written as

it = iter(mylist)
first = next(it)  #  O(1) operation
for item in it:
  process(first, item)
del mylist

If .pop were being added today, I would argue against including the 
index parameter.


--
Terry Jan Reedy

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


Re: Python 3 and SSH Tunnel

2013-08-08 Thread Skip Montanaro
On Thu, Aug 8, 2013 at 2:30 PM, D. Xenakis gouzouna...@hotmail.com wrote:
 HOWTO anyone?

 What im trying to succeed here is create one SSH tunnel, so that i can 
 connect from a python script running on my pc, to a remote MySQL database 
 running on my Host and id like to stick with Python 3.3 .

http://lmgtfy.com/?q=python3+ssh+tunnel

First hit:

http://zeromq.github.io/pyzmq/ssh.html

which says, in part: pexpect has no Python3 support at this time, so
Python 3 users should get Thomas Kluyver’s pexpect-u fork.

Also, search PyPI for tunnel.  There might well be something useful there.

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


Re: beginner question (True False help)

2013-08-08 Thread Terry Reedy

On 8/8/2013 7:41 AM, Chris Angelico wrote:

On Thu, Aug 8, 2013 at 7:20 AM,  wxjmfa...@gmail.com wrote:

def z2():

... letters = 'abc'
... while True:
... c = input('letter: ')
... if c not in letters:
... print('end, fin, Schluss')
... break
... else:
... print('do stuff')



Minor quibble: I don't like having a hard exit followed by an else.


Whereas I tend to prefer to have the two alternatives cleanly marked as 
alternatives by both being indented the same.


Many alternatives are not so trivial as the above. I remember reading 
one snippet in the CPython codebase where the 'else' was omitted and the 
if clause subdivided into about three paths. It took at least a minute 
to determine that all paths terminated in such a way that there really 
was an inplied else. How much easier it would have been to read the code 
if the author had explicitly types the 'else'.



If the if branch will unconditionally quit the loop (with a break,
here, but could also be a return, a thrown exception, etc etc), I
would prefer to see the else removed and its code unindented one
level. Maybe this is just personal preference, though, learned from
assembly language programming where a block if looks something like
this:

; if x == y:
CMP x,y
JNZ .else
; Code for x == y
JMP .endif
.else:
; Code for else
.endif

Putting an unconditional departure in the x == y branch makes the
JMP .endif redundant.


Python is not assembly ;-). 3.3 effectively ignores the extraneous 
'else:'. Either way, if the condition is false, control jumps to the 
second print. For what little it matters, the bytecode is the same length.


def f():
  while True:
if a:
  b = 1
  break
else:
  b = 2

 dis(f)
  2   0 SETUP_LOOP  25 (to 28)

  3 3 LOAD_GLOBAL  0 (a)
  6 POP_JUMP_IF_FALSE   19

  4   9 LOAD_CONST   1 (1)
 12 STORE_FAST   0 (b)

  5  15 BREAK_LOOP
 16 JUMP_ABSOLUTE3

  719 LOAD_CONST   2 (2)
 22 STORE_FAST   0 (b)
 25 JUMP_ABSOLUTE3
   28 LOAD_CONST   0 (None)
 31 RETURN_VALUE

def f():
  while True:
if a:
  b = 1
  break
b = 2

 dis(f)
  2   0 SETUP_LOOP  25 (to 28)

  3 3 LOAD_GLOBAL  0 (a)
  6 POP_JUMP_IF_FALSE   19

  4   9 LOAD_CONST   1 (1)
 12 STORE_FAST   0 (b)

  5  15 BREAK_LOOP
 16 JUMP_FORWARD 0 (to 19)

  619 LOAD_CONST   2 (2)
 22 STORE_FAST   0 (b)
 25 JUMP_ABSOLUTE3
   28 LOAD_CONST   0 (None)
 31 RETURN_VALUE

--
Terry Jan Reedy

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


Re: right adjusted strings containing umlauts

2013-08-08 Thread Terry Reedy

On 8/8/2013 11:24 AM, Kurt Mueller wrote:


print( u'{0:3} {1:3} {2:3} {3:3} {4:3}'.format( *output_list ) )


Using autonumbering feature, same as

print( u'{:3} {:3} {:3} {:3} {:3}'.format( *output_list ) )
print( (u' '.join([u'{:3}']*5)).format(*output_list) )
print( (u' '.join([u'{:3}']*len(output_list))).format(*output_list) )
--
Terry Jan Reedy

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


Re: Suggestion: PEP for popping slices from lists

2013-08-08 Thread Joshua Landau
On 8 August 2013 21:03, Terry Reedy tjre...@udel.edu wrote:
 If .pop were being added today, I would argue against including the index
 parameter.

GASP! That's no fair!

1) When using pop you normally want to keep the mutability available,
so iter(mylist) is a no-go.
2) When using the index, it's often somewhere in the middle that
you're popping from
3) There's always deque for deques

That said you can always use blist which has O(log n) time complexity
for these pops. It's a hassle it's not stdlib :/.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: PEP for popping slices from lists

2013-08-08 Thread Tim Chase
On 2013-08-08 22:32, Joshua Landau wrote:
 On 8 August 2013 21:03, Terry Reedy tjre...@udel.edu wrote:
  If .pop were being added today, I would argue against including
  the index parameter.
 
 3) There's always deque for deques

Unless you have pre-2.4 code, in which case I'm glad .pop() was
included (but in this hypothetical world, we'd have a deque in
pre-2.4 too :-D

-tkc



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


Re: Suggestion: PEP for popping slices from lists

2013-08-08 Thread Terry Reedy

On 8/8/2013 5:32 PM, Joshua Landau wrote:

On 8 August 2013 21:03, Terry Reedy tjre...@udel.edu wrote:

If .pop were being added today, I would argue against including the index
parameter.


GASP! That's no fair!

1) When using pop you normally want to keep the mutability available,
so iter(mylist) is a no-go.
2) When using the index, it's often somewhere in the middle that
you're popping from


I have never done that and I do not believe I have ever seen that. It 
certainly is extremely rare in my experience. Removing an item *after* 
looking at it is something different.


for i in range(len(mylist), -1, -1):
  if pred(mylist[i]): del mylist[i]

--
Terry Jan Reedy

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


Re: Issues with if and elif statements in 3.3

2013-08-08 Thread Kris Mesenbrink
WOW as if it was something as easy as that,i had been looking for  awhile on 
what i was doing wrong. as it seems i just don't know my way around if 
statements at all, thank a bunch for this. makes everything else i have been 
code work

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


Re: Python 3 and SSH Tunnel

2013-08-08 Thread Chris Angelico
On Thu, Aug 8, 2013 at 8:30 PM, D. Xenakis gouzouna...@hotmail.com wrote:
 HOWTO anyone?

 What im trying to succeed here is create one SSH tunnel, so that i can 
 connect from a python script running on my pc, to a remote MySQL database 
 running on my Host and id like to stick with Python 3.3 .

 I contacted my host and he informed me that this is the only way.

 I tried pycrypto + paramiko but from what i have noticed, paramiko is not 
 Python 3.3 ready.

I'm not sure what exactly is going on here, but why not simply
establish a tunnel using ssh(1) and then invoke your Python script
separately? You simply point your script at a database on localhost,
after establishing a tunnel from local 3306 to remote localhost:3306.
No need to play with Python crypto.

Alternatively, can you use PostgreSQL instead? :)

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


Re: Python 3 and SSH Tunnel

2013-08-08 Thread D. Xenakis

  HOWTO anyone?
 
 
 
  What im trying to succeed here is create one SSH tunnel, so that i can 
  connect from a python script running on my pc, to a remote MySQL database 
  running on my Host and id like to stick with Python 3.3 .
 
 
 
  I contacted my host and he informed me that this is the only way.
 
 
 
  I tried pycrypto + paramiko but from what i have noticed, paramiko is not 
  Python 3.3 ready.
 
 
 
 I'm not sure what exactly is going on here, but why not simply
 
 establish a tunnel using ssh(1) and then invoke your Python script
 
 separately? You simply point your script at a database on localhost,
 
 after establishing a tunnel from local 3306 to remote localhost:3306.
 
 No need to play with Python crypto.
 
 
 
 Alternatively, can you use PostgreSQL instead? :)
 
 
 
 ChrisA

Yes you are right.
I've played with putty to achieve this but to be honest i'd like something more 
efficient. Opening putty everytime and making all the connection settings etc, 
and then running the programm, is kinda messy. Id like this to be done in an 
automatic way from the program so that things roll easy.
I thought maybe i should find a way how to call and run a batch file from 
inside my python program or a powershell command, but i do not know even if 
that could work for the ssh tunneling.

any ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3 and SSH Tunnel

2013-08-08 Thread D. Xenakis
 Alternatively, can you use PostgreSQL instead? :)

Yes there is such an option to be honest.
Would that be helpfull instead of MySQL?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3 and SSH Tunnel

2013-08-08 Thread Chris Angelico
On Fri, Aug 9, 2013 at 1:46 AM, D. Xenakis gouzouna...@hotmail.com wrote:
 I've played with putty to achieve this but to be honest i'd like something 
 more efficient. Opening putty everytime and making all the connection 
 settings etc, and then running the programm, is kinda messy. Id like this to 
 be done in an automatic way from the program so that things roll easy.
 I thought maybe i should find a way how to call and run a batch file from 
 inside my python program or a powershell command, but i do not know even if 
 that could work for the ssh tunneling.

You should at very least be able to save PuTTY's settings under some
name. Once you've done that, check PuTTY's docs for a way to invoke it
with particular saved settings. I'm pretty sure there's a way to do
that. The program can then invoke that as a background process, then
go on to do whatever you need.

Be aware, though, that you'll need to set up passwordless access (with
a keypair) if you're to fully automate the process. But you may have
already done that.

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


Re: Python 3 and SSH Tunnel

2013-08-08 Thread Chris Angelico
On Fri, Aug 9, 2013 at 1:50 AM, D. Xenakis gouzouna...@hotmail.com wrote:
 Alternatively, can you use PostgreSQL instead? :)

 Yes there is such an option to be honest.
 Would that be helpfull instead of MySQL?

It would, mainly because it's simply a better database engine.
Everything to do with tunneling is going to be the same, save that you
use port 5432 instead of 3306. But check if you can configure remote
access directly on PostgreSQL.

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


Using sudo to write to a file as root from a script

2013-08-08 Thread Adam Mercer
Hi

I'm trying to write a script that writes some content to a file root
through sudo, but it's not working at all. I am using:

  channel = 'stable'
  config_file = '/opt/ldg/etc/channel.conf'
  command = ['echo', '-n', channel, '|', 'sudo', 'tee', config_file]
  p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  out, _ = p.communicate()

But it seems as if this isn't doing anything.

I just want to write the contents of the variable channel to the file
/opt/ldg/etc/channel.conf. But whatever I try just doesn't work. Can
anyone offer any pointers?

Cheers

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


Re: [tkinter] trouble running imported modules in main program

2013-08-08 Thread snakeinmyboot
On Thursday, August 8, 2013 1:13:48 AM UTC-4, David wrote:
 On 8 August 2013 14:06, snakeinmyboot mikelha...@gmail.com wrote:
 
 
 
  for REAL you guys...wtf does this even mean lol. what is a boilerplate test 
  code?
 
 
 
 Did you try at all to find the answer to this yourself?
 
 
 
 I ask because it took me only a few seconds to go to wikipedia and
 
 search for boilerplate find this for you:
 
 http://en.wikipedia.org/wiki/Boilerplate_code
 
 
 
 Tip: To successfully use forums like this one (where a lot of very
 
 smart people read), the more care/effort/thought you demonstrate that
 
 you tried to solve your issue before asking, the more likely you are
 
 to receive a response.


I did read that article but I couldnt really figure out how to apply it to the 
code he was giving as an example of making it conditional.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using sudo to write to a file as root from a script

2013-08-08 Thread Denis McMahon
On Thu, 08 Aug 2013 23:11:09 -0500, Adam Mercer wrote:

 Hi
 
 I'm trying to write a script that writes some content to a file root
 through sudo, but it's not working at all. I am using:
 
   channel = 'stable'
   config_file = '/opt/ldg/etc/channel.conf'
   command = ['echo', '-n', channel, '|', 'sudo', 'tee', config_file]
   p = subprocess.Popen(command, stdout=subprocess.PIPE,
   stderr=subprocess.PIPE)
   out, _ = p.communicate()
 
 But it seems as if this isn't doing anything.
 
 I just want to write the contents of the variable channel to the file
 /opt/ldg/etc/channel.conf. But whatever I try just doesn't work. Can
 anyone offer any pointers?

Do you find anything with:

$ grep sudo /var/log/auth.log

(you may need to specify a different log)

Is the process that's trying to use the sudo command allowed to do so 
without a password?

man sudoers

Note - after editing /etc/sudoers you must set the permissions back to 440

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


Re: Using sudo to write to a file as root from a script

2013-08-08 Thread David
On 9 August 2013 14:11, Adam Mercer ramer...@gmail.com wrote:

 I'm trying to write a script that writes some content to a file root
 through sudo, but it's not working at all. I am using:

[...]

At a quick glance, I have a couple of suggestions.

   command = ['echo', '-n', channel, '|', 'sudo', 'tee', config_file]

sudo doesn't work like this. It doesn't read from standard input. You
need to supply the command as an argument to sudo. Get the sudo syntax
correct by learning to use it in a shell (eg terminal running bash )
before trying to use it from python code.

Also, I think that passing the pipe character '|' as an argument to
Popen is not the correct way to use pipes.

So, if you figure out how to use sudo without '|' you will solve both
these issues.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [tkinter] trouble running imported modules in main program

2013-08-08 Thread David
On 9 August 2013 14:28, snakeinmyboot mikelha...@gmail.com wrote:
 On Thursday, August 8, 2013 1:13:48 AM UTC-4, David wrote:
 On 8 August 2013 14:06, snakeinmyboot mikelha...@gmail.com wrote:

 Did you try at all to find the answer to this yourself?

 I ask because it took me only a few seconds to go to wikipedia and
 search for boilerplate find this for you:

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

 Tip: To successfully use forums like this one (where a lot of very
 smart people read), the more care/effort/thought you demonstrate that
 you tried to solve your issue before asking, the more likely you are
 to receive a response.

 I did read that article but I couldnt really figure out how to apply it to 
 the code he was giving as an example of making it conditional.

Did you try the research method I gave you in my previous answer?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to make a unittest decorator to rename a method from x to testx?

2013-08-08 Thread adam . preble
On Thursday, August 8, 2013 3:50:47 AM UTC-5, Peter Otten wrote:
 Peter Otten wrote:
 Oops, that's an odd class name. Fixing the name clash in Types.__new__() is 
 
 left as an exercise...

Interesting, I got __main__.T, even though I pretty much just tried your code 
wholesale.  For what it's worth, I'm using Python 2.7.  I'm glad to see that 
code since I learned a lot of tricks from it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Resolving import errors reported by PyLint in modules using Python.NET

2013-08-08 Thread adam . preble
PyLint can't figure out imports of .NET code being referenced in my Python 
scripts that use Python.NET.  I can kind of see why; you have to evaluate some 
clr.AddReference calls for the imports to even succeed.  I wonder if I have any 
recourse.  Generally, to import a DLL you have to do a few things.  I guess for 
an example I'll import a .NET string:


import clr# Python .NET common-language runtime module, the important part 
of it all

clr.AddReference(System)
from System import String   # .NET System.String

can = String(Spam)


PyLint is not amused:
F:  4, 0: Unable to import 'System' (import-error)

I wondered if there were any tricks to make it work.  I don't want to just 
ignore import-error, either by explicitly telling pylint to ignore them, or be 
getting complacent in seeing them all the time.  I am also kind of curious if 
PyLint will expose new problems if it's able to figure out more things after 
successfully  passing the imports.  I wouldn't really know.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Resolving import errors reported by PyLint in modules using Python.NET

2013-08-08 Thread Benjamin Kaplan
On Thu, Aug 8, 2013 at 10:17 PM,  adam.pre...@gmail.com wrote:
 PyLint can't figure out imports of .NET code being referenced in my Python 
 scripts that use Python.NET.  I can kind of see why; you have to evaluate 
 some clr.AddReference calls for the imports to even succeed.  I wonder if I 
 have any recourse.  Generally, to import a DLL you have to do a few things.  
 I guess for an example I'll import a .NET string:

 
 import clr# Python .NET common-language runtime module, the important 
 part of it all

 clr.AddReference(System)
 from System import String   # .NET System.String

 can = String(Spam)
 

 PyLint is not amused:
 F:  4, 0: Unable to import 'System' (import-error)

 I wondered if there were any tricks to make it work.  I don't want to just 
 ignore import-error, either by explicitly telling pylint to ignore them, or 
 be getting complacent in seeing them all the time.  I am also kind of curious 
 if PyLint will expose new problems if it's able to figure out more things 
 after successfully  passing the imports.  I wouldn't really know.

Are you using Python.NET or IronPython? IronPython is reasonably well
supported, and it looks like there's a patch you can use to get PyLint
working on it (see
http://mail.python.org/pipermail/ironpython-users/2012-June/016099.html
). Not sure what's going on with Python.NET
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue15301] os.chown: OverflowError: Python int too large to convert to C long

2013-08-08 Thread Larry Hastings

Larry Hastings added the comment:

Benjamin, do you want my elaborate fix in for 2.7?  It means adding two new 
converters, one for pid and one for gid, and switching everything that takes 
pid/gid arguments to use those.

--
nosy: +benjamin.peterson

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



[issue15301] os.chown: OverflowError: Python int too large to convert to C long

2013-08-08 Thread Larry Hastings

Larry Hastings added the comment:

Now fixed in trunk.  I am waiting to hear from Georg and the 
only-recently-pinged Benjamin to see if they want these fixes in 3.3 or 2.7.

--

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



[issue15301] os.chown: OverflowError: Python int too large to convert to C long

2013-08-08 Thread Roundup Robot

Roundup Robot added the comment:

New changeset f871f8662509 by Larry Hastings in branch 'default':
Issue #15301: Parsing fd, uid, and gid parameters for builtins
http://hg.python.org/cpython/rev/f871f8662509

--

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



[issue18290] json encoder does not support JSONP/JavaScript safe escaping

2013-08-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Embedding JSON inside script tag doesn't differ from embedding any string in 
some format (i.e. JSON in Python string, Python sources in HTML, or XML in a 
shell script). We just escape characters which have special meaning.

I propose close this issue because embedding JSON (as any other generated code) 
in inline JavaScript can be done very easily with a sequence of string 
replaces. This has no relations to the json module.

--
status: open - pending

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



[issue15301] os.chown: OverflowError: Python int too large to convert to C long

2013-08-08 Thread Benjamin Peterson

Benjamin Peterson added the comment:

I think we should leave 2.7 at rest for the moment.

--

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



[issue15301] os.chown: OverflowError: Python int too large to convert to C long

2013-08-08 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

The original issue was fixed in issue4591. Larry's patch only adds support of 
PyNumber_Index() and refactors already existing uid/gid converters.

--

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



[issue8713] multiprocessing needs option to eschew fork() under Linux

2013-08-08 Thread Ned Deily

Ned Deily added the comment:

Richard, can you say what failed on the OS X 10.4 (Tiger) buildbot?  FWIW, I 
tested b3620777f54c.diff (and commented out the darwin skip of 
test_multiprocessing_forkserver) on OS X 10.4, 10.5, and 10.8.  There were no 
failures on any of them. The only vaguely suspicious message when running with 
-v was:

./python -m test -v test_multiprocessing_forkserver
[...]
test_semaphore_tracker 
(test.test_multiprocessing_forkserver.TestSemaphoreTracker) ... 
[semaphore_tracker] '/mp18203-0': [Errno 22] Invalid argument
[semaphore_tracker] '/mp18203-1': successfully unlinked
ok
[...]
--
Ran 233 tests in 97.162s

OK (skipped=5)  # on 32-bit 'largest assignable fd number is too small'
OK (skipped=4)  # on 64-bit

1 test OK.

--

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



[issue18682] [PATCH] remove bogus codepath from pprint._safe_repr

2013-08-08 Thread Michal Vyskocil

New submission from Michal Vyskocil:

pprint._safe_repr for type str uses much slower codepath by default, which does 
not makes a sense in Python3 context. Instead of simply using repr, it check 
the existence of 'locale' in sys.modules and if found, it goes one-by-one-char 
call str.isalpha() on each and apply the quoting for non-alpha chars. This is 
extremely slow, but as locale is usually in sys.modules, it's used by default.

The point of such code was because in python2, str.isalpha() depends on locale, 
so for locale-aware Python builds, there was a different path needed. But this 
does not apply for Python3, where all strings are unicode, so .isaplha() is not 
locale sensitive anymore.

--
components: Library (Lib)
files: pprint-remove-bogus-code.patch
keywords: patch
messages: 194652
nosy: mvyskocil
priority: normal
severity: normal
status: open
title: [PATCH] remove bogus codepath from pprint._safe_repr
type: performance
Added file: http://bugs.python.org/file31193/pprint-remove-bogus-code.patch

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



[issue18682] [PATCH] remove bogus codepath from pprint._safe_repr

2013-08-08 Thread Michal Vyskocil

Michal Vyskocil added the comment:

This is simple code checks if .isalnum is or is not locale sensitive and a 
small measurement of how much is the repr faster, compared to old codepath.

BTW: python3 test_pprint.py on patched version have succeeded

OK (expected failures=1)

--

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



[issue18682] [PATCH] remove bogus codepath from pprint._safe_repr

2013-08-08 Thread Michal Vyskocil

Changes by Michal Vyskocil mvysko...@suse.cz:


Added file: http://bugs.python.org/file31194/check.py

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



[issue15301] os.chown: OverflowError: Python int too large to convert to C long

2013-08-08 Thread Georg Brandl

Georg Brandl added the comment:

Looks like an unnecessary change for the maintenance releases then.

--

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



[issue15301] os.chown: OverflowError: Python int too large to convert to C long

2013-08-08 Thread Larry Hastings

Larry Hastings added the comment:

Okay then, closing.

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

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



[issue8713] multiprocessing needs option to eschew fork() under Linux

2013-08-08 Thread Richard Oudkerk

Richard Oudkerk added the comment:

 Richard, can you say what failed on the OS X 10.4 (Tiger) buildbot?

There seems to be a problem which depends on the order in which you run 
the test, and it happens on Linux also.  For example if I do

   ./python -m test -v \
   test_multiprocessing_fork \
   test_multiprocessing_forkserver

Then I get lots of failures when forkserver runs.  I have tracked down 
the changeset which caused the problem, but I have not had time to look 
in to it.

  The only vaguely suspicious message when running with -v was:
  [...]
  [semaphore_tracker] '/mp18203-0': [Errno 22] Invalid argument
  [semaphore_tracker] '/mp18203-1': successfully unlinked
  [...]

That is expected and it shows the semaphore tracker is working as 
expected.  Maybe I should print a note to stderr to expect this.

--

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



[issue18677] Enhanced context managers with ContextManagerExit and None

2013-08-08 Thread Kristján Valur Jónsson

Kristján Valur Jónsson added the comment:

I've modified the patch.  The problem that nested_delayed was trying to solve 
are hybrid context managers, ones that allocate resources during __init__ and 
release them at exit.  A proper context manager should allocate resources 
during __enter__, and thus a number of them can be created upfront with 
impunity.

Added contextlib.proper to turn a hybrid context manager into a proper one by 
instantiating the hybrid in a delayed fashion.
added contextlib.opened() as a special case that does open() properly.

With this change, and the ability to nest error handling of exceptions stemming 
from __enter__(), nested now works as intended.

--
Added file: http://bugs.python.org/file31195/contextmanagerexit.patch

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



[issue18677] Enhanced context managers with ContextManagerExit and None

2013-08-08 Thread Kristján Valur Jónsson

Kristján Valur Jónsson added the comment:

Thanks, Eric.
I read that bit and I can't say that I disagree.
And I'm not necessarily advocating that skipping the body become a standard 
feature of context managers.  But it is a necessary functionality if you want 
to be able to dynamically nest one or more context managers, something I think 
Python should be able to do, for completeness, if not only for aesthetic beauty.

Having said that, optionally skipping the body is a far cry from the more 
esoteric constructs achievable with pep 340.

And python _already_ silently skips the body of managed code, if you nest two 
managers:

@contextmanager errordude:
1 // 0
yield
@contextmanager handler:
try:
yield
except ZeroDivisionError:
pass

with handler, errordude:
do_stuff()

These context managers will skip the execution of f.  It will be Python's 
internal decision to do so, of course.  But the with statement already has 
the potential to have the body silently skipped.

What I'm adding here, the ContextManagerExit, is the ability for the context 
manager itself to make the decision, so that the two context managers above can 
be coalesced into one:

with nested(handler, errordude):
do_stuff()

The fact that do_stuff can be silently skipped in the first case, where we 
explicitly have two nested calls, invalidates IMHO the argument that context 
managers should not affect control flow.  why shouldn't it also be skippable in 
the case of a single context manager?

--

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



[issue18677] Enhanced context managers with ContextManagerExit and None

2013-08-08 Thread Kristján Valur Jónsson

Kristján Valur Jónsson added the comment:

Using my latest patch, the ExitStack inline example can be rewritten:

with ExitStack() as stack:
files = [stack.enter_context(open(fname)) for fname in filenames]
# All opened files will automatically be closed at the end of
# the with statement, even if attempts to open files later
# in the list raise an exception

becomes:
with nested(opened(fname) for fname in filenames) as files:
do_stuff_with_files(files)

--

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



[issue18683] Core dumps on CentOS

2013-08-08 Thread Marc Schlaich

New submission from Marc Schlaich:

I'm running unittests on a CentOS 6.4 Virtual Box slave via Jenkins on a 
Windows host. Randomly I get core dumps for no obvious reason. I don't
use any C extension in my code and don't use ctypes. The (proprietary)
software is plain Python with a multi-threaded architecture.

There might be a threading race condition in the code but according
to http://stackoverflow.com/a/13654489/851737 this shouldn't result
in a segfault. So it might be a bug in Python.

I appended one log (I have various others if you wish to see them) with 
faulthandler enabled by https://pypi.python.org/pypi/nose-faulthandler.

--
files: crash.log
messages: 194660
nosy: schlamar
priority: normal
severity: normal
status: open
title: Core dumps on CentOS
type: crash
versions: Python 2.6
Added file: http://bugs.python.org/file31196/crash.log

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



[issue18684] Pointers point out of array bound in _sre.c

2013-08-08 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

In _sre.c pointers can point out of boundaries of array. This is an undefined 
behavior and is one of causes of a bug in issue17998 (end-ptr can be negative). 
The proposed patch change code to check if pointers will point out of 
boundaries before their changing.

--
components: Regular Expressions
files: sre_ptr_out_of_bounds.patch
keywords: patch
messages: 194661
nosy: ezio.melotti, mrabarnett, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Pointers point out of array bound in _sre.c
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file31197/sre_ptr_out_of_bounds.patch

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



[issue18683] Core dumps on CentOS

2013-08-08 Thread R. David Murray

R. David Murray added the comment:

Can you reproduce this using 2.7?  2.6 only gets security fixes.

--
nosy: +r.david.murray

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



[issue18416] Move to absolute file paths for module.__file__

2013-08-08 Thread Brett Cannon

Brett Cannon added the comment:

So this is bringing up a sticky situation that I ran across when initially 
implementing all of this: what should sys.path_importer_cache use as a key? '' 
would be what happens with Madison's option 3, and with option 1 it would be 
os.getcwd(). Now if you iterate through sys.path you won't find what '' 
connects to. Then again, it won't be accurate if you change the directory 
either.

So the question becomes should sys.path_importer_cache reflect exactly what is 
in sys.path or what should be cached for a finder based on what import should 
do (i.e. the full path and change based on the cwd)?

--

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



[issue18273] Simplify calling and discovery of json test package

2013-08-08 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 95cf8640b271 by Ezio Melotti in branch '3.3':
#18273: move the tests in Lib/test/json_tests to Lib/test/test_json and make 
them discoverable by unittest.  Patch by Zachary Ware.
http://hg.python.org/cpython/rev/95cf8640b271

New changeset f7ed301e7199 by Ezio Melotti in branch 'default':
#18273: merge with 3.3.
http://hg.python.org/cpython/rev/f7ed301e7199

--
nosy: +python-dev

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



[issue18273] Simplify calling and discovery of json test package

2013-08-08 Thread Ezio Melotti

Ezio Melotti added the comment:

Fixed, thanks for the patch!
(Thanks Ned too!)

--
assignee:  - ezio.melotti
resolution:  - fixed
stage: patch review - committed/rejected
status: open - closed

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



  1   2   >