accents in windows

2014-10-30 Thread C@rlos
i cant print any accent(á é í ó ú) or ñ in console when i use windows OS with 
python, the console showme an error or extrangers characters in some cases, i 
need help 

III Escuela Internacional de Invierno en la UCI del 17 al 28 de febrero del 
2014. Ver www.uci.cu

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


testfixtures 4.1.1 Released!

2014-10-30 Thread Chris Withers

Hi All,

I'm pleased to announce the release of testfixtures 4.1.1. This is a 
bugfix release that fixes the following:


- Fix bug that prevented logger propagation to be controlled by the
  log_capture decorator.

Thanks to John Kristensen for the fix.

It looks like I also forgot to send out the 4.1.0 release announcement, 
which was a bug and feature release containing the following:


- Fix compare() bug when dict instances with tuple keys were not equal.

- Allow logger propagation to be controlled by LogCapture.

- Enabled disabled loggers if a LogCapture is attached to them.

Thanks to Daniel Fortunov for the compare() fix.

The package is on PyPI and a full list of all the links to docs, issue 
trackers and the like can be found here:


http://www.simplistix.co.uk/software/python/testfixtures

Any questions, please do ask on the Testing in Python list or on the 
Simplistix open source mailing list...


cheers,

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk
--
https://mail.python.org/mailman/listinfo/python-list


Re: accents in windows

2014-10-30 Thread Chris Angelico
On Thu, Oct 30, 2014 at 11:03 AM, C@rlos cmfer...@estudiantes.uci.cu wrote:
 i cant print any accent(á é í ó ú) or ñ in console  when i use windows OS
 with python, the console showme an error or extrangers characters in some
 cases, i need help

What version of Python? What is your code page set to?

Windows and Unicode don't play very nicely together. You may find it
better to use Idle (which has a GUI for this kind of display), and you
will almost certainly find things easier on Linux.

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


Re: Python Style Question

2014-10-30 Thread Steven D'Aprano
Anton wrote:

 Let's say I have an incoming list of values *l*. Every element of *l* can
 be one of the following options: 
 1) an integer value 
 2) a string in form of 'int_value', e.g. '7'
 3) a string with a json serialization of an integer value, e.g. '7'
 4) something else that should be ignored
 
 I need to transform this list into another list with values from options
 1)-3) coerced to int. The code below should do this.

I don't particularly like either version. I prefer this:

def load_int(obj):
if isinstance(obj, int):
# Case 1), an int, e.g. 7
return obj
elif isinstance(obj, str):
# Case 2) and 3), a str or JSON serialised int.
# E.g. '7' or '7'.
try:
return int(obj)
except ValueError:
return int(json.loads(obj))
raise TypeError('require int or str, got %s' % type(obj).__name__)

load_int() covers the three cases you mention, and raises either ValueError
for malformed strings (e.g. 'x') or TypeError for things which aren't ints
(e.g. floats, dicts, etc.). Any other exception is probably a bug that
needs to be fixed.

Then, to cover case 4), ignoring everything else, you have a choice between
a procedural form:

values = []
for obj in l:
try:
values.append(load_int(obj))
except (ValueError, TypeError):
pass


or a functional form:

def tolerant_load_int(obj, default=None):
try:
return load_int(obj)
except (ValueError, TypeError):
return default

values = [n for n in map(tolerant_load_int, l) if n is not None]

# alternative to using map
values = [n for n in (tolerant_load_int(obj) for obj in l) if n is not None]



-- 
Steven

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


Has color Green changed from Python 33 to 34 ?

2014-10-30 Thread ast

Hi

I just updated this morning my Python from a 3.3rc to 3.4 
(Windows) and I noticed that the 'Green' color in tkinter 
GUI is not the same at all.


'Green' in 3.4 is very dark. I had to replace it with 'Lime' to
get back a nice 'Green'.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Has color Green changed from Python 33 to 34 ?

2014-10-30 Thread Peter Otten
ast wrote:

 I just updated this morning my Python from a 3.3rc to 3.4
 (Windows) and I noticed that the 'Green' color in tkinter
 GUI is not the same at all.
 
 'Green' in 3.4 is very dark. I had to replace it with 'Lime' to
 get back a nice 'Green'.

More likely the color is defined by tcl/tk rather than Python, and your 
Python installations use different versions of tcl. Searching for 'tcl/tk 
color definitions' finds http://wiki.tcl.tk/1424 with the following 
statement

From Tcl/Tk 8.6 on, Tk uses Web colours instead of X11 ones, where they 
conflict.


and according to 
http://en.wikipedia.org/wiki/X11_color_names#Clashes_between_web_and_X11_colors
 
green is indeed one of the affected colors.


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


Re: Python Style Question

2014-10-30 Thread MRAB

On 2014-10-30 11:10, Steven D'Aprano wrote:

Anton wrote:


Let's say I have an incoming list of values *l*. Every element of *l* can
be one of the following options:
1) an integer value
2) a string in form of 'int_value', e.g. '7'
3) a string with a json serialization of an integer value, e.g. '7'
4) something else that should be ignored

I need to transform this list into another list with values from options
1)-3) coerced to int. The code below should do this.


I don't particularly like either version. I prefer this:

def load_int(obj):
 if isinstance(obj, int):
 # Case 1), an int, e.g. 7
 return obj
 elif isinstance(obj, str):
 # Case 2) and 3), a str or JSON serialised int.
 # E.g. '7' or '7'.
 try:
 return int(obj)
 except ValueError:
 return int(json.loads(obj))
 raise TypeError('require int or str, got %s' % type(obj).__name__)


[snip]

How about:

int(str(obj).strip(''))

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


Re: accents in windows

2014-10-30 Thread C@rlos
thanks U, but the real problem is:

i have a path C:\Users\yanet\Desktop\áaaéeeíiiióooúuuñnn 
this path is correct, áaaéeeíiiióooúuuñnn is the name of a directory
but when i try to use os.walk() usin this path, dont work, for os this path 
dont exist, i try every things but nothing works.

some help???


- Mensaje original -
De: Chris Angelico ros...@gmail.com
CC: python-list@python.org
Enviados: Jueves, 30 de Octubre 2014 4:42:49
Asunto: Re: accents in windows

On Thu, Oct 30, 2014 at 11:03 AM, C@rlos cmfer...@estudiantes.uci.cu wrote:
 i cant print any accent(á é í ó ú) or ñ in console  when i use windows OS
 with python, the console showme an error or extrangers characters in some
 cases, i need help

What version of Python? What is your code page set to?

Windows and Unicode don't play very nicely together. You may find it
better to use Idle (which has a GUI for this kind of display), and you
will almost certainly find things easier on Linux.

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

-- 
Conserva lo que tienes...Olvida lo que te duele...Lucha por lo que quieres... 
Valora lo que posees...Perdona a los que te hieren y disfruta a los que te 
aman. Nos pasamos la vida esperando que pase algo... y lo único que pasa es la 
vida. No entendemos el valor de los momentos, hasta que se han convertido en 
recuerdos. Por eso... Haz lo que quieras hacer, antes de que se convierta en lo 
que te gustaría haber hecho.. No hagas de tu vida un borrador, tal vez no 
tengas tiempo de pasarlo en limpio !! 

.C@rlos 

III Escuela Internacional de Invierno en la UCI del 17 al 28 de febrero del 
2014. Ver www.uci.cu
-- 
https://mail.python.org/mailman/listinfo/python-list


When using a decorator exceptions raised reference the decorator not the function

2014-10-30 Thread Néstor Boscán
Hi

I'm using Python 2.7 and I'm creating a class decorator that extract
information from exceptions for logging purposes.

Everytime an exception is raised from the original function and I extract
the origin of the exception with sys.exc_info() I get a reference to the
line in the decorator where the function is called, not the line of the
original function where the exception was raised.

Any ideas?

Regards,

Néstor
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: accents in windows

2014-10-30 Thread Peter Otten
C@rlos wrote:

 thanks U, but the real problem is:
 
 i have a path C:\Users\yanet\Desktop\áaaéeeíiiióooúuuñnn
 this path is correct, áaaéeeíiiióooúuuñnn is the name of a directory
 but when i try to use os.walk() usin this path, dont work, for os this
 path dont exist, i try every things but nothing works.
 
 some help???

nothing works is not a good problem description to get help to fix a bug.

Can you post a small script that demonstrates the problem? 

Run the script and post its output including the error message and the 
traceback. Don't retype the output, use copy-and-paste.

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


Re: When using a decorator exceptions raised reference the decorator not the function

2014-10-30 Thread Peter Otten
Néstor Boscán wrote:

 I'm using Python 2.7 and I'm creating a class decorator that extract
 information from exceptions for logging purposes.
 
 Everytime an exception is raised from the original function and I extract
 the origin of the exception with sys.exc_info() I get a reference to the
 line in the decorator where the function is called, not the line of the
 original function where the exception was raised.
 
 Any ideas?

Please show us the code, preferably as a small self-contained example. Thank 
you.

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


Re: When using a decorator exceptions raised reference the decorator not the function

2014-10-30 Thread Jean-Michel Pichavant
- Original Message -
 From: Peter Otten __pete...@web.de
 To: python-list@python.org
 Sent: Thursday, 30 October, 2014 1:45:42 PM
 Subject: Re: When using a decorator exceptions raised reference the decorator 
 not the function
 
 Néstor Boscán wrote:
 
  I'm using Python 2.7 and I'm creating a class decorator that
  extract
  information from exceptions for logging purposes.
  
  Everytime an exception is raised from the original function and I
  extract
  the origin of the exception with sys.exc_info() I get a reference
  to the
  line in the decorator where the function is called, not the line of
  the
  original function where the exception was raised.
  
  Any ideas?
 
 Please show us the code, preferably as a small self-contained
 example. Thank
 you.

+1 show us your decorator.

if you did something like:

try:

except Exception, e:
  # do something
  raise e


Then replace raise e by a bare raise


JM


-- 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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Finding way around ABCs (was What for -- for? (was A bug?))

2014-10-30 Thread Rustom Mody
On Wednesday, October 29, 2014 11:49:27 AM UTC+5:30, Zachary Ware wrote:
 On Wed, Oct 29, 2014 at 1:11 AM, Rustom Mody wrote:
  On Wednesday, October 29, 2014 11:10:06 AM UTC+5:30, Zachary Ware wrote:
  Of course, that's 3 (progressively shorter) loops to get the names of
  the ABCs of a class compared to 1 (fairly short in the first place)
  loop for a map of relationships to all available ABCs, but optimizing
  such a toy as this would just be an exercise in futility :)
 
  Not so.
 
  The charm of introspection is that the introspection
  itself can be introspected.
  For that to be convincing there needs to be a good combo
  of clarity and succinctness.  In particular why not reduce
  the two functions to one?
 
  def get_abc_names(cls):
  return [abc.__name__ for abc in abcs if issubclass(cls,abc)]
 
 Well, it depends on what you actually want, the spec has been a bit fuzzy ;)

Thanks for this much -- its helpful.
Regarding ABCs -- is there a central documentation for them:

What exactly is a sequence or iterable or etc protocol?

This information seems to be strewn all over the place but systematically.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Finding way around ABCs (was What for -- for? (was A bug?))

2014-10-30 Thread Ian Kelly
On Thu, Oct 30, 2014 at 11:01 AM, Rustom Mody rustompm...@gmail.com wrote:
 On Wednesday, October 29, 2014 11:49:27 AM UTC+5:30, Zachary Ware wrote:
 On Wed, Oct 29, 2014 at 1:11 AM, Rustom Mody wrote:
  On Wednesday, October 29, 2014 11:10:06 AM UTC+5:30, Zachary Ware wrote:
  Of course, that's 3 (progressively shorter) loops to get the names of
  the ABCs of a class compared to 1 (fairly short in the first place)
  loop for a map of relationships to all available ABCs, but optimizing
  such a toy as this would just be an exercise in futility :)
 
  Not so.
 
  The charm of introspection is that the introspection
  itself can be introspected.
  For that to be convincing there needs to be a good combo
  of clarity and succinctness.  In particular why not reduce
  the two functions to one?
 
  def get_abc_names(cls):
  return [abc.__name__ for abc in abcs if issubclass(cls,abc)]

 Well, it depends on what you actually want, the spec has been a bit fuzzy ;)

 Thanks for this much -- its helpful.
 Regarding ABCs -- is there a central documentation for them:

 What exactly is a sequence or iterable or etc protocol?

 This information seems to be strewn all over the place but systematically.

Maybe the glossary?

https://docs.python.org/3/glossary.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Finding way around ABCs (was What for -- for? (was A bug?))

2014-10-30 Thread Ian Kelly
On Thu, Oct 30, 2014 at 11:09 AM, Ian Kelly ian.g.ke...@gmail.com wrote:
 On Thu, Oct 30, 2014 at 11:01 AM, Rustom Mody rustompm...@gmail.com wrote:
 On Wednesday, October 29, 2014 11:49:27 AM UTC+5:30, Zachary Ware wrote:
 On Wed, Oct 29, 2014 at 1:11 AM, Rustom Mody wrote:
  On Wednesday, October 29, 2014 11:10:06 AM UTC+5:30, Zachary Ware wrote:
  Of course, that's 3 (progressively shorter) loops to get the names of
  the ABCs of a class compared to 1 (fairly short in the first place)
  loop for a map of relationships to all available ABCs, but optimizing
  such a toy as this would just be an exercise in futility :)
 
  Not so.
 
  The charm of introspection is that the introspection
  itself can be introspected.
  For that to be convincing there needs to be a good combo
  of clarity and succinctness.  In particular why not reduce
  the two functions to one?
 
  def get_abc_names(cls):
  return [abc.__name__ for abc in abcs if issubclass(cls,abc)]

 Well, it depends on what you actually want, the spec has been a bit fuzzy ;)

 Thanks for this much -- its helpful.
 Regarding ABCs -- is there a central documentation for them:

 What exactly is a sequence or iterable or etc protocol?

 This information seems to be strewn all over the place but systematically.

 Maybe the glossary?

Also the documentation for the collections.abc and numbers modules:

https://docs.python.org/3/library/collections.abc.html
https://docs.python.org/3/library/numbers.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Finding way around ABCs (was What for -- for? (was A bug?))

2014-10-30 Thread Rustom Mody
On Thursday, October 30, 2014 10:40:42 PM UTC+5:30, Ian wrote:
 On Thu, Oct 30, 2014 at 11:01 AM, Rustom Mody wrote:
  On Wednesday, October 29, 2014 11:49:27 AM UTC+5:30, Zachary Ware wrote:
  On Wed, Oct 29, 2014 at 1:11 AM, Rustom Mody wrote:
   On Wednesday, October 29, 2014 11:10:06 AM UTC+5:30, Zachary Ware wrote:
   Of course, that's 3 (progressively shorter) loops to get the names of
   the ABCs of a class compared to 1 (fairly short in the first place)
   loop for a map of relationships to all available ABCs, but optimizing
   such a toy as this would just be an exercise in futility :)
  
   Not so.
  
   The charm of introspection is that the introspection
   itself can be introspected.
   For that to be convincing there needs to be a good combo
   of clarity and succinctness.  In particular why not reduce
   the two functions to one?
  
   def get_abc_names(cls):
   return [abc.__name__ for abc in abcs if issubclass(cls,abc)]
 
  Well, it depends on what you actually want, the spec has been a bit fuzzy 
  ;)
 
  Thanks for this much -- its helpful.
  Regarding ABCs -- is there a central documentation for them:
 
  What exactly is a sequence or iterable or etc protocol?
 
  This information seems to be strewn all over the place but systematically.
 
 Maybe the glossary?
 
 https://docs.python.org/3/glossary.html

Ummm...

I was looking for something more reference-ish, ie
More prolix for ABCs
And not containing random bits of unconnected data like
- What is CPython
- What is EAFP

Maybe there's something in the bowels of the C(Python)-code?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What for -- for? (was A bug?)

2014-10-30 Thread Joshua Landau
On 29 October 2014 03:22, Rustom Mody rustompm...@gmail.com wrote:
 Yesterday I was trying to introduce python to some senior computer scientists.

 Tried showing a comprehension-based dir-walker vs a for-loop based one:

 def dw(p):
if isfile(p):
   return [p]
else:
   return [p] + [c for f in listdir(p) for c in dw(p+'/'+f)]

...

 Comment to me : Well this is neat and compact, but it does not add
 anything fundamental (over usual index based for-loops)

 I tried to say that 'for' over general sequences is quite different
 and significantly more powerful than C/Pascal for over indexes +
 explicit indexing.

If you really want to show the generality of iteration, I suggest you
start with iterators:

def walk(path):
yield path

if isdir(path):
for name in iterdir(path):
for file in walk(path + / + name):
yield file

This is fundementally inexpressable with indexes. It also lends itself
to expressing delegation (eg. yield from walk(path + / + name)).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What for -- for? (was A bug?)

2014-10-30 Thread Rustom Mody
On Thursday, October 30, 2014 10:53:13 PM UTC+5:30, Joshua Landau wrote:
 On 29 October 2014 03:22, Rustom Mody  wrote:
  Yesterday I was trying to introduce python to some senior computer 
  scientists.
 
  Tried showing a comprehension-based dir-walker vs a for-loop based one:
 
  def dw(p):
 if isfile(p):
return [p]
 else:
return [p] + [c for f in listdir(p) for c in dw(p+'/'+f)]
 
 ...
 
  Comment to me : Well this is neat and compact, but it does not add
  anything fundamental (over usual index based for-loops)
 
  I tried to say that 'for' over general sequences is quite different
  and significantly more powerful than C/Pascal for over indexes +
  explicit indexing.
 
 If you really want to show the generality of iteration, I suggest you
 start with iterators:
 
 def walk(path):
 yield path
 
 if isdir(path):
 for name in iterdir(path):
 for file in walk(path + / + name):
 yield file

heh!
That was my next version -- almost word-for-word
[Not on that laptop now; will check later]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Has color Green changed from Python 33 to 34 ?

2014-10-30 Thread Terry Reedy

On 10/30/2014 8:20 AM, Peter Otten wrote:

ast wrote:


I just updated this morning my Python from a 3.3rc to 3.4
(Windows) and I noticed that the 'Green' color in tkinter
GUI is not the same at all.

'Green' in 3.4 is very dark. I had to replace it with 'Lime' to
get back a nice 'Green'.


More likely the color is defined by tcl/tk rather than Python, and your
Python installations use different versions of tcl.

 Searching for 'tcl/tk

color definitions' finds http://wiki.tcl.tk/1424 with the following
statement

From Tcl/Tk 8.6 on, Tk uses Web colours instead of X11 ones, where they
conflict.



3.4 switched from 8.5 to 8.6


and according to
http://en.wikipedia.org/wiki/X11_color_names#Clashes_between_web_and_X11_colors
green is indeed one of the affected colors.


--
Terry Jan Reedy

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


Re: accents in windows

2014-10-30 Thread Terry Reedy

On 10/30/2014 8:30 AM, C@rlos wrote:

thanks U, but the real problem is:

i have a path C:\Users\yanet\Desktop\áaaéeeíiiióooúuuñnn
this path is correct, áaaéeeíiiióooúuuñnn is the name of a directory
but when i try to use os.walk() usin this path, dont work, for os this

 path dont exist, i try every things but nothing works.


some help???


Using Python 3.4 should solve this problem.



- Mensaje original -
De: Chris Angelico ros...@gmail.com
CC: python-list@python.org
Enviados: Jueves, 30 de Octubre 2014 4:42:49
Asunto: Re: accents in windows

On Thu, Oct 30, 2014 at 11:03 AM, C@rlos cmfer...@estudiantes.uci.cu wrote:

i cant print any accent(á é í ó ú) or ñ in console  when i use windows OS
with python, the console showme an error or extrangers characters in some
cases, i need help


Using Idle and a font with accented chars should solve this problem.


What version of Python? What is your code page set to?

Windows and Unicode don't play very nicely together. You may find it
better to use Idle (which has a GUI for this kind of display), and you
will almost certainly find things easier on Linux.


--
Terry Jan Reedy


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


Re: When using a decorator exceptions raised reference the decorator not the function

2014-10-30 Thread Terry Reedy

On 10/30/2014 8:33 AM, Néstor Boscán wrote:


I'm using Python 2.7 and I'm creating a class decorator that extract
information from exceptions for logging purposes.

Everytime an exception is raised from the original function and I
extract the origin of the exception with sys.exc_info() I get a
reference to the line in the decorator where the function is called, not
the line of the original function where the exception was raised.


I expect that both lines should be in the traceback.  Post an example 
where you do not intercept the exception.


--
Terry Jan Reedy


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


pySerial works in miniterm but not in my app

2014-10-30 Thread Dario
Python 2.7.6 on Mint, pySerial 2.6

I'm trying to write a console app to control a certain device via a usb com 
port.

In miniterm (-p /dev/ttyUSB0 -e -b 19200), I can communicate correctly with 
this configuration:

--- Settings: /dev/ttyUSB0  19200,8,N,1
--- RTS: inactive  DTR: inactive  BREAK: inactive
--- CTS: inactive  DSR: inactive  RI: inactive  CD: inactive
--- software flow control: inactive
--- hardware flow control: inactive
--- data escaping: raw  linefeed: CR

sw o01 + --- I send this
sw o01 + Command OK --- device does what it should *and* I receive this


Now my code:


import serial

s = serial.serial_for_url(
'/dev/ttyUSB0',
19200,
bytesize = 8,
parity   = 'N',
stopbits = 1,
rtscts   = False,
dsrdtr   = False,
xonxoff  = False,
timeout  = 1 # tried without
)
s.close() # tried without
s.open()
s.write('sw o01 +\r')
s.flush() # tried without
s.close() # tried with a sleep before close


With this I don't receive anything (tried with readline etc, omitted for 
readability), and the device doesn't react. Also, if I connect again with 
miniterm and issue the command, I first receive a wrong command message, as 
if some garbage was actually sent by my app, then it works again.

Isn't my config equivalent to the one in miniterm? Anything missing?

Thanks

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


Classes

2014-10-30 Thread Seymore4Head
class pet: 
def set_age(self,age):
self.age=age
def get_age(self):
return self.age
pax=pet
pax.set_age(4)

Traceback (most recent call last):
  File C:\Functions\test.py, line 18, in module
pax.set_age(4)
TypeError: set_age() missing 1 required positional argument: 'age'

I am trying to pass 4 as the age.  Obviously I am doing it wrong.

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


Re: Classes

2014-10-30 Thread Rob Gaddi
On Thu, 30 Oct 2014 16:16:51 -0400
Seymore4Head Seymore4Head@Hotmail.invalid wrote:

 class pet: 
 def set_age(self,age):
 self.age=age
 def get_age(self):
 return self.age
 pax=pet
 pax.set_age(4)
 
 Traceback (most recent call last):
   File C:\Functions\test.py, line 18, in module
 pax.set_age(4)
 TypeError: set_age() missing 1 required positional argument: 'age'
 
 I am trying to pass 4 as the age.  Obviously I am doing it wrong.
 

The reason your call is missing the positional argument is that 4 is
being assigned to self, rather than to age, so there is no age.  This is
because you are trying to call a function of the class object, rather
than a function of an instance of the class.

pax=pet()

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Classes

2014-10-30 Thread sohcahtoa82
On Thursday, October 30, 2014 1:19:57 PM UTC-7, Seymore4Head wrote:
 class pet: 
 def set_age(self,age):
 self.age=age
 def get_age(self):
 return self.age
 pax=pet
 pax.set_age(4)
 
 Traceback (most recent call last):
   File C:\Functions\test.py, line 18, in module
 pax.set_age(4)
 TypeError: set_age() missing 1 required positional argument: 'age'
 
 I am trying to pass 4 as the age.  Obviously I am doing it wrong.

The line `pax=pet` doesn't create an instance of your pet class, it creates 
essentially a copy of the class definition.

You need `pax=pet()`

Or preferably, `pax = pet()`.  The spaces are optional, but they make it more 
readable.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Classes

2014-10-30 Thread Seymore4Head
On Thu, 30 Oct 2014 13:34:04 -0700, Rob Gaddi
rgaddi@technologyhighland.invalid wrote:

On Thu, 30 Oct 2014 16:16:51 -0400
Seymore4Head Seymore4Head@Hotmail.invalid wrote:

 class pet: 
 def set_age(self,age):
 self.age=age
 def get_age(self):
 return self.age
 pax=pet
 pax.set_age(4)
 
 Traceback (most recent call last):
   File C:\Functions\test.py, line 18, in module
 pax.set_age(4)
 TypeError: set_age() missing 1 required positional argument: 'age'
 
 I am trying to pass 4 as the age.  Obviously I am doing it wrong.
 

The reason your call is missing the positional argument is that 4 is
being assigned to self, rather than to age, so there is no age.  This is
because you are trying to call a function of the class object, rather
than a function of an instance of the class.

pax=pet()
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Classes

2014-10-30 Thread Seymore4Head
On Thu, 30 Oct 2014 13:33:01 -0700 (PDT), sohcahto...@gmail.com wrote:

On Thursday, October 30, 2014 1:19:57 PM UTC-7, Seymore4Head wrote:
 class pet: 
 def set_age(self,age):
 self.age=age
 def get_age(self):
 return self.age
 pax=pet
 pax.set_age(4)
 
 Traceback (most recent call last):
   File C:\Functions\test.py, line 18, in module
 pax.set_age(4)
 TypeError: set_age() missing 1 required positional argument: 'age'
 
 I am trying to pass 4 as the age.  Obviously I am doing it wrong.

The line `pax=pet` doesn't create an instance of your pet class, it creates 
essentially a copy of the class definition.

You need `pax=pet()`

Or preferably, `pax = pet()`.  The spaces are optional, but they make it more 
readable.

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


Re: Classes

2014-10-30 Thread Larry Hudson

On 10/30/2014 01:16 PM, Seymore4Head wrote:

class pet:
 def set_age(self,age):
 self.age=age
 def get_age(self):
 return self.age
pax=pet
pax.set_age(4)

Traceback (most recent call last):
   File C:\Functions\test.py, line 18, in module
 pax.set_age(4)
TypeError: set_age() missing 1 required positional argument: 'age'

I am trying to pass 4 as the age.  Obviously I am doing it wrong.

You have already received the answer -- pax=pet should be pax=pet(), but I have a simple 
side-comment about style.  It is common Python convention to capitalize class names, IOW make 
this class Pet instead of class pet.  This is convention not a requirement, but it does help 
distinguish class names from ordinary variable names -- especially to others reading your code 
(as well as yourself a few days later).   ;-)


 -=- Larry -=-

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


Re: Classes

2014-10-30 Thread Seymore4Head
On Thu, 30 Oct 2014 14:28:19 -0700, Larry Hudson org...@yahoo.com
wrote:

On 10/30/2014 01:16 PM, Seymore4Head wrote:
 class pet:
  def set_age(self,age):
  self.age=age
  def get_age(self):
  return self.age
 pax=pet
 pax.set_age(4)

 Traceback (most recent call last):
File C:\Functions\test.py, line 18, in module
  pax.set_age(4)
 TypeError: set_age() missing 1 required positional argument: 'age'

 I am trying to pass 4 as the age.  Obviously I am doing it wrong.

You have already received the answer -- pax=pet should be pax=pet(), but I 
have a simple 
side-comment about style.  It is common Python convention to capitalize class 
names, IOW make 
this class Pet instead of class pet.  This is convention not a requirement, 
but it does help 
distinguish class names from ordinary variable names -- especially to others 
reading your code 
(as well as yourself a few days later).   ;-)

  -=- Larry -=-

I try to take typing shortcuts and it bites me in the behind.
Good suggestion
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Saving a file in the background -- How?

2014-10-30 Thread Virgil Stokes
While running a python program I need to save some of the data that is 
being created. I would like to save the data to a file on a disk 
according to a periodical schedule  (e.g. every 10 minutes). Initially, 
the amount of data is small ( 1 MB) but after sometime the amount of 
data can be 10MB. If a problem occurs during data creation, then the 
user should be able to start over from the last successfully saved data.


For my particular application, no other file is being saved and the data 
should always replace (not be appended to) the previous data saved. It 
is important that  the data be saved without any obvious distraction to 
the user who is busy creating more data. That is, I would like to save 
the data in the background.


What is a good method to perform this task using Python 2.7.8 on a Win32 
platform?

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


Re: When using a decorator exceptions raised reference the decorator not the function

2014-10-30 Thread Néstor Boscán
Thanks Terry

Yes both lines where in the traceback using tb_next I got what I needed.

Regards,

Néstor

On Thu, Oct 30, 2014 at 1:36 PM, Terry Reedy tjre...@udel.edu wrote:

 On 10/30/2014 8:33 AM, Néstor Boscán wrote:

  I'm using Python 2.7 and I'm creating a class decorator that extract
 information from exceptions for logging purposes.

 Everytime an exception is raised from the original function and I
 extract the origin of the exception with sys.exc_info() I get a
 reference to the line in the decorator where the function is called, not
 the line of the original function where the exception was raised.


 I expect that both lines should be in the traceback.  Post an example
 where you do not intercept the exception.

 --
 Terry Jan Reedy


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

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


Re: Saving a file in the background -- How?

2014-10-30 Thread Joel Goldstick
On Thu, Oct 30, 2014 at 5:30 PM, Virgil Stokes v...@it.uu.se wrote:
 While running a python program I need to save some of the data that is being
 created. I would like to save the data to a file on a disk according to a
 periodical schedule  (e.g. every 10 minutes). Initially, the amount of data
 is small ( 1 MB) but after sometime the amount of data can be 10MB. If a
 problem occurs during data creation, then the user should be able to start
 over from the last successfully saved data.

 For my particular application, no other file is being saved and the data
 should always replace (not be appended to) the previous data saved. It is
 important that  the data be saved without any obvious distraction to the
 user who is busy creating more data. That is, I would like to save the data
 in the background.

 What is a good method to perform this task using Python 2.7.8 on a Win32
 platform?
 --
 https://mail.python.org/mailman/listinfo/python-list

I've not tried this, but stackoverflow has a solution that looks like
it could work for you:
http://stackoverflow.com/questions/16214736/write-data-to-disk-in-python-as-a-background-process

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


Re: Python Style Question

2014-10-30 Thread Steven D'Aprano
MRAB wrote:

 On 2014-10-30 11:10, Steven D'Aprano wrote:
 Anton wrote:

 Let's say I have an incoming list of values *l*. Every element of *l*
 can be one of the following options:
 1) an integer value
 2) a string in form of 'int_value', e.g. '7'
 3) a string with a json serialization of an integer value, e.g. '7'
 4) something else that should be ignored

 I need to transform this list into another list with values from options
 1)-3) coerced to int. The code below should do this.

 I don't particularly like either version. I prefer this:

 def load_int(obj):
  if isinstance(obj, int):
  # Case 1), an int, e.g. 7
  return obj
  elif isinstance(obj, str):
  # Case 2) and 3), a str or JSON serialised int.
  # E.g. '7' or '7'.
  try:
  return int(obj)
  except ValueError:
  return int(json.loads(obj))
  raise TypeError('require int or str, got %s' % type(obj).__name__)

 [snip]
 
 How about:
 
 int(str(obj).strip(''))

Absolutely not.

obj = '1\n\n\n\n'  # not valid JSON
load_int(obj)
= raises ValueError
int(str(obj).strip(''))
= wrongly returns 1


-- 
Steven

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


Re: problem with pefile

2014-10-30 Thread Cameron Simpson

On 29Oct2014 08:34, gandal...@mail.com gandal...@mail.com wrote:

OT: how can I hide my email in these posts?
Every time I try to send a post, google warns me that my email is visible and 
so I edit it out.


Why would you want to hide your email?

Cameron Simpson c...@zip.com.au
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Style Question

2014-10-30 Thread Roy Smith
In article 54521c8f$0$12982$c3e8da3$54964...@news.astraweb.com,
 Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:

 Anton wrote:
 
  Let's say I have an incoming list of values *l*. Every element of *l* can
  be one of the following options: 
  1) an integer value 
  2) a string in form of 'int_value', e.g. '7'
  3) a string with a json serialization of an integer value, e.g. '7'
  4) something else that should be ignored
  
  I need to transform this list into another list with values from options
  1)-3) coerced to int. The code below should do this.
 
 I don't particularly like either version. I prefer this:
 
 def load_int(obj):
 if isinstance(obj, int):
 # Case 1), an int, e.g. 7
 return obj
 elif isinstance(obj, str):
 # Case 2) and 3), a str or JSON serialised int.
 # E.g. '7' or '7'.
 try:
 return int(obj)
 except ValueError:
 return int(json.loads(obj))
 raise TypeError('require int or str, got %s' % type(obj).__name__)

Depending on how strictly you're trying to do input validation, the 
int(json.loads(obj)) may not be what you want.  It allows well-formed 
json encoding floats, for example.

And, of course, since

 isinstance(True, int)
True

this code accepts booleans.  Oh, but wait, that's by design :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem with pefile

2014-10-30 Thread Kiuhnm
On Friday, October 31, 2014 1:33:07 AM UTC+1, Cameron Simpson wrote:
 On 29Oct2014 08:34, gandalf23 wrote:
 OT: how can I hide my email in these posts?
 Every time I try to send a post, google warns me that my email is visible 
 and so I edit it out.
 
 Why would you want to hide your email?
 
 Cameron Simpson c...@zip.com.au

I don't want more spam.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: problem with pefile

2014-10-30 Thread Cameron Simpson

On 30Oct2014 17:58, Kiuhnm gandal...@mail.com wrote:

On Friday, October 31, 2014 1:33:07 AM UTC+1, Cameron Simpson wrote:

On 29Oct2014 08:34, gandalf23 wrote:
OT: how can I hide my email in these posts?
Every time I try to send a post, google warns me that my email is visible and 
so I edit it out.

Why would you want to hide your email?


I don't want more spam.


You just need to filter your email better.
Most of us do not hide our addresses.

I manage to filter most of my spam by filing anything which gets past all my 
rules that catch mailing lists and which do not come from addresses in my 
known group into a probably-spam folder. It is surprisingly effective.


Basicly:
  - to me (me in to/cc/bcc), from a known author == inbox
  - matches one of my mailing list rules == appropriate-folder
  - otherwise == probably-spam

That is a simplification, but it is my basic scheme. Works fairly well.

Anyway, this is off-topic for python-list so I'll shut up now.

Cheers,
Cameron Simpson c...@zip.com.au

It must be public fact, because I'm not the only one who knows about it.
- Stefan A. Werner iczer-1!s...@uunet.uu.net
--
https://mail.python.org/mailman/listinfo/python-list


set environmental variable from python

2014-10-30 Thread Artur Bercik
I have to set environmental variable in my windows PC as follows:

variable name: GISBASE

value: C:\GRASS-64

Is it possible to set it from python?

import sys

sys.path.append(C:\\GRASS-64)

But how to give variable name? I have to set both the variable name and
value.

Thanks in the advance.

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


Re: Classes

2014-10-30 Thread sohcahtoa82
On Thursday, October 30, 2014 2:37:54 PM UTC-7, Seymore4Head wrote:
 On Thu, 30 Oct 2014 14:28:19 -0700, Larry Hudson org...@yahoo.com
 wrote:
 
 On 10/30/2014 01:16 PM, Seymore4Head wrote:
  class pet:
   def set_age(self,age):
   self.age=age
   def get_age(self):
   return self.age
  pax=pet
  pax.set_age(4)
 
  Traceback (most recent call last):
 File C:\Functions\test.py, line 18, in module
   pax.set_age(4)
  TypeError: set_age() missing 1 required positional argument: 'age'
 
  I am trying to pass 4 as the age.  Obviously I am doing it wrong.
 
 You have already received the answer -- pax=pet should be pax=pet(), but I 
 have a simple 
 side-comment about style.  It is common Python convention to capitalize 
 class names, IOW make 
 this class Pet instead of class pet.  This is convention not a requirement, 
 but it does help 
 distinguish class names from ordinary variable names -- especially to others 
 reading your code 
 (as well as yourself a few days later).   ;-)
 
   -=- Larry -=-
 
 I try to take typing shortcuts and it bites me in the behind.
 Good suggestion
 Thanks

A shortcut is the fastest way to get somewhere you weren't going.

Python makes programming very easy (Compared to C/C++ and many other 
languages), but there are still a lot of shortcuts you can't make.
-- 
https://mail.python.org/mailman/listinfo/python-list


ANN: Antipathy v0.8

2014-10-30 Thread Ethan Furman
has just been made compatible with Python 3!  It runs on everything from 2.4 forward, haven't testing anything prior to 
that.


It is available for download at https://pypi.python.org//pypi/antipathy

---

Antipathy -- for those tired of ``os.path``
===

Tired of calling a function for every path manipulation you need to do?

Is:

 path, filename = os.path.split(some_name)
 basename, ext = os.path.splitext(filename)
 basename = basename + '_01'
 new_name = os.path.join(path, basename+ext)

wearing on your nerves?

In short, are you filled with antipathy [1] for os.path?

Then get antipathy and work with Path:

 some_name = Path('/home/ethan/source/my_file.txt')
 backups = Path('/home/ethan/backup/')
 print some_name.path
'/home/ethan/source/'
 print some_name.ext
'.txt'
 print some_name.exists()
True  # (well, if it happens to exist at this moment ;)
 backup = backups / some_name.filename + '_01' + some_name.ext
 print backup
'/home/ethan/backup/my_file_01.txt'
 some_name.copy(backup)

Because Path is a subclass of bytes/str/unicode, it can still be passed to other functions that expect a 
bytes/str/unicode object and work seamlessly [2].


[1] https://www.google.com/#q=antipathy

[2] in most cases -- there are a few places that do a `type` check instead of 
an `isinstance` check.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Saving a file in the background -- How?

2014-10-30 Thread Deepfriedice

Why not just call the save function as a separate thread?
threading.Thread(target=save, args=(data)).start()
--
https://mail.python.org/mailman/listinfo/python-list


Re: set environmental variable from python

2014-10-30 Thread Dave Angel

On 10/30/2014 09:22 PM, Artur Bercik wrote:

I have to set environmental variable in my windows PC as follows:

variable name: GISBASE

value: C:\GRASS-64

Is it possible to set it from python?


Which Python?  I'll have to assume 3.x



import sys

sys.path.append(C:\\GRASS-64)

But how to give variable name? I have to set both the variable name and
value.



sys.path has nothing to do with an environment variable of GISBASE.

Instead you could look up os.environ at:

  https://docs.python.org/3/library/os.html

Also see os.getenv and os.setenv.



Note that it's not necessarily supported.  But I believe it is for a 
standard build on Windows.


Next question is what you hope to achieve by setting such a variable. 
You do realize that it will vanish again when your python process ends? 
 So if you're just planning to use it in your own code, I'd recommend 
finding another method of saving the name  value.


The only value I can see is if you plan to create a subprocess from your 
Python code.


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


Re: Saving a file in the background -- How?

2014-10-30 Thread Terry Reedy

On 10/30/2014 6:21 PM, Joel Goldstick wrote:

On Thu, Oct 30, 2014 at 5:30 PM, Virgil Stokes v...@it.uu.se wrote:

While running a python program I need to save some of the data that is being
created. I would like to save the data to a file on a disk according to a
periodical schedule  (e.g. every 10 minutes). Initially, the amount of data
is small ( 1 MB) but after sometime the amount of data can be 10MB. If a
problem occurs during data creation, then the user should be able to start
over from the last successfully saved data.

For my particular application, no other file is being saved and the data
should always replace (not be appended to) the previous data saved. It is
important that  the data be saved without any obvious distraction to the
user who is busy creating more data. That is, I would like to save the data
in the background.

What is a good method to perform this task using Python 2.7.8 on a Win32
platform?
--
https://mail.python.org/mailman/listinfo/python-list


I've not tried this, but stackoverflow has a solution that looks like
it could work for you:
http://stackoverflow.com/questions/16214736/write-data-to-disk-in-python-as-a-background-process


Python 3.4 should have an asyncio solution.


--
Terry Jan Reedy

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


Re: set environmental variable from python

2014-10-30 Thread Artur Bercik
Dear Dave Angel

Thanks for your answer.

I am using Python 2.7

I want to set it permanently.
I have to set several variables so it would be easier if I could set them
from Python.

Hearing the solution.

On Fri, Oct 31, 2014 at 10:50 AM, Dave Angel da...@davea.name wrote:

 On 10/30/2014 09:22 PM, Artur Bercik wrote:

 I have to set environmental variable in my windows PC as follows:

 variable name: GISBASE

 value: C:\GRASS-64

 Is it possible to set it from python?


 Which Python?  I'll have to assume 3.x


 import sys

 sys.path.append(C:\\GRASS-64)

 But how to give variable name? I have to set both the variable name and
 value.


 sys.path has nothing to do with an environment variable of GISBASE.

 Instead you could look up os.environ at:

   https://docs.python.org/3/library/os.html

 Also see os.getenv and os.setenv.



 Note that it's not necessarily supported.  But I believe it is for a
 standard build on Windows.

 Next question is what you hope to achieve by setting such a variable. You
 do realize that it will vanish again when your python process ends?  So if
 you're just planning to use it in your own code, I'd recommend finding
 another method of saving the name  value.

 The only value I can see is if you plan to create a subprocess from your
 Python code.

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

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


Re: set environmental variable from python

2014-10-30 Thread Zachary Ware
On Thursday, October 30, 2014, Artur Bercik vbubbl...@gmail.com wrote:

 Dear Dave Angel

 Thanks for your answer.

 I am using Python 2.7

 I want to set it permanently.
 I have to set several variables so it would be easier if I could set them
 from Python.


Depending on how permanently you mean, about your only solutions would be
os.system('setx ...') or manually manipulating the registry with the
_winreg module.

Hope this helps,
--
Zach


-- 
Sent from Gmail Mobile
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: set environmental variable from python

2014-10-30 Thread Rustom Mody
On Friday, October 31, 2014 8:01:08 AM UTC+5:30, Zachary Ware wrote:
 On Thursday, October 30, 2014, Artur Bercik vbub...@gmail.com wrote:
 
 Dear Dave Angel
 
 
 Thanks for your answer.
 
 
 I am using Python 2.7
 
 
 I want to set it permanently.
 I have to set several variables so it would be easier if I could set them 
 from Python.
 
 
 Depending on how permanently you mean, about your only solutions
 would be os.system('setx ...') or manually manipulating the
 registry with the _winreg module.

Or dont do it from python but directly with regedit??

The question really is: Why do you wish to do this from within python?


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


Re: set environmental variable from python

2014-10-30 Thread Artur Bercik
could you please elaborate 'setx ...'?


On Fri, Oct 31, 2014 at 11:30 AM, Zachary Ware 
zachary.ware+pyl...@gmail.com wrote:

 On Thursday, October 30, 2014, Artur Bercik vbubbl...@gmail.com wrote:

 Dear Dave Angel

 Thanks for your answer.

 I am using Python 2.7

 I want to set it permanently.
 I have to set several variables so it would be easier if I could set them
 from Python.


 Depending on how permanently you mean, about your only solutions would
 be os.system('setx ...') or manually manipulating the registry with the
 _winreg module.

 Hope this helps,
 --
 Zach


 --
 Sent from Gmail Mobile

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


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


Re: set environmental variable from python

2014-10-30 Thread Artur Bercik
I have to set several variables so it would be easier if I could set them
from Python.

On Fri, Oct 31, 2014 at 11:36 AM, Rustom Mody rustompm...@gmail.com wrote:

 On Friday, October 31, 2014 8:01:08 AM UTC+5:30, Zachary Ware wrote:
  On Thursday, October 30, 2014, Artur Bercik vbub...@gmail.com wrote:
 
  Dear Dave Angel
 
 
  Thanks for your answer.
 
 
  I am using Python 2.7
 
 
  I want to set it permanently.
  I have to set several variables so it would be easier if I could set
 them from Python.
 
 
  Depending on how permanently you mean, about your only solutions
  would be os.system('setx ...') or manually manipulating the
  registry with the _winreg module.

 Or dont do it from python but directly with regedit??

 The question really is: Why do you wish to do this from within python?


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

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


Re: set environmental variable from python

2014-10-30 Thread Rustom Mody
On Friday, October 31, 2014 7:33:43 AM UTC+5:30, Artur Bercik wrote:
 Dear Dave Angel
 
 
 Thanks for your answer.
 
 
 I am using Python 2.7
 
 
 I want to set it permanently.
 I have to set several variables so it would be easier if I could set them 
 from Python.

regedit is scriptable
http://support.microsoft.com/kb/310516

[Be careful though! Follow the precautions like backing up the registry
before messing around]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: set environmental variable from python

2014-10-30 Thread Zachary Ware
On Thu, Oct 30, 2014 at 9:40 PM, Artur Bercik vbubbl...@gmail.com wrote:
 could you please elaborate 'setx ...'?

From a Command Prompt, do 'help setx' for details on how to use setx.

Rustom's suggestion of using regedit is going to be far easier than
using _winreg (which probably shouldn't even be considered as an
option).  Using `os.system('setx ...')` is going to be the easiest way
to do things if you have to calculate the values of your variables,
but if you just have a bunch of values that you're going to have to
key in anyway, just use setx directly (or in a batch script).

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


Re: Python Style Question

2014-10-30 Thread Steven D'Aprano
Roy Smith wrote:

 In article 54521c8f$0$12982$c3e8da3$54964...@news.astraweb.com,
  Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
 
 Anton wrote:
 
  Let's say I have an incoming list of values *l*. Every element of *l*
  can be one of the following options:
  1) an integer value
  2) a string in form of 'int_value', e.g. '7'
  3) a string with a json serialization of an integer value, e.g. '7'
  4) something else that should be ignored
  
  I need to transform this list into another list with values from
  options 1)-3) coerced to int. The code below should do this.
 
 I don't particularly like either version. I prefer this:
 
 def load_int(obj):
 if isinstance(obj, int):
 # Case 1), an int, e.g. 7
 return obj
 elif isinstance(obj, str):
 # Case 2) and 3), a str or JSON serialised int.
 # E.g. '7' or '7'.
 try:
 return int(obj)
 except ValueError:
 return int(json.loads(obj))
 raise TypeError('require int or str, got %s' % type(obj).__name__)
 
 Depending on how strictly you're trying to do input validation, the
 int(json.loads(obj)) may not be what you want.  It allows well-formed
 json encoding floats, for example.

Really?

py int(json.loads(json.dumps(23.5)))
23

Damn! You're right.

Back to Plan A:

elif isinstance(obj, str):
try:
return int(obj)
except ValueError:
if obj and obj.startswith('') and obj.endswith(''):
return int(obj[1:-1])
raise


But of course even the int() function itself may be a little more flexible
than we might want:

py int('1')
1


So I guess the lessons are:

* before writing code, you need to decide what the code is meant to do;

* and that includes what input must be rejected, not just what input 
  must be accepted.


 And, of course, since
 
 isinstance(True, int)
 True
 
 this code accepts booleans.  Oh, but wait, that's by design :-)

Naturally :-)

If you wanted to avoid it, that's easy, add a clause:

if isinstance(obj, bool):
raise TypeError

at the start of the function.


-- 
Steven

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


Re: Python Style Question

2014-10-30 Thread Denis McMahon
On Fri, 31 Oct 2014 09:48:10 +1100, Steven D'Aprano wrote:

 MRAB wrote:

 How about:
 
 int(str(obj).strip(''))
 
 Absolutely not.
 
 obj = '1\n\n\n\n'  # not valid JSON load_int(obj)
 = raises ValueError int(str(obj).strip(''))
 = wrongly returns 1

How about

#!/usr/bin/python

import re, json

l = [1, -1, 0, '+2', '2', '-2', '0', '+3', '3', '-3', '0', 
 json.dumps(-4), json.dumps(4), json.dumps(0), 
 'x', 'sqjklsqjk__', (5, 6), 
 7.7, -7.7, '8.8', '+8.8', '-8.8', '9.9', '+9.9', '-9.9']

patt1 = re.compile(r'^([-+]?\d+)$')
patt2 = re.compile(r'^([-+]?\d+)$')

def getTheInt(x):

if isinstance(x,int):
return x

if isinstance(x,str):
tmp = patt1.match(x)

if tmp:
return int(tmp.group(1))

tmp = patt2.match(x)

if tmp:
return int(tmp.group(1))

return None

a = []

for n in l:
a.append(getTheInt(n))

print a

# end of code

prints:

[1, -1, 0, 2, 2, -2, 0, 3, 3, -3, 0, -4, 4, 0, None, None, None, None, 
None, None, None, None, None, None, None]

I know re matching the strings may be overkill, but it may be the best 
way of checking that the string contains the expected character format to 
convert to an int.

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


[issue11874] argparse assertion failure with brackets in metavars

2014-10-30 Thread Tshepang Lekhonkhobe

Changes by Tshepang Lekhonkhobe tshep...@gmail.com:


--
nosy:  -tshepang

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



[issue22762] PyObject_Call called with an exception set while displaying a traceback

2014-10-30 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 9dddc95ef31e by Victor Stinner in branch '3.4':
Issue #22762: Fix _Py_DisplaySourceLine(), clear the exception if
https://hg.python.org/cpython/rev/9dddc95ef31e

New changeset f4f5b942e5e0 by Victor Stinner in branch 'default':
(Merge 3.4) Issue #22762: Fix _Py_DisplaySourceLine(), clear the exception if
https://hg.python.org/cpython/rev/f4f5b942e5e0

--
nosy: +python-dev

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



[issue22762] PyObject_Call called with an exception set while displaying a traceback

2014-10-30 Thread STINNER Victor

STINNER Victor added the comment:

Thanks for the report and the patch. It was not easy to reproduce the issue, 
but I reproduced the assertion error. I'm not sure that it's useful to add an 
unit test.

--
resolution:  - fixed
status: open - closed

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



[issue18235] _sysconfigdata.py wrong on AIX installations

2014-10-30 Thread Phil Elson

Phil Elson added the comment:

FWIW - this doesn't appear to have been backported to v2.7.x. As a result, the 
./Modules/ld_so_aix reference still exists in _sysconfigdata.py in v2.7.8 (and 
therefore I was unable to build numpy). The workaround is easy enough, it is 
just something that is worth noting.

--
nosy: +pelson

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



[issue22764] object lifetime fragility in unittest tests

2014-10-30 Thread Robert Collins

New submission from Robert Collins:

test_assertRaises_frames_survival 
(unittest2.test.test_assertions.Test_Assertions
Depends on refcount behaviour to pass - adding a gc.collect() before the 
weakref checks is sufficient to fix things on pypy.

test_no_exception_leak (unittest2.test.test_case.Test_TestCase
similarly here adding a juidicious gc.collect solves the issue.

--
messages: 230258
nosy: rbcollins
priority: normal
severity: normal
status: open
title: object lifetime fragility in unittest tests
versions: Python 3.5

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



[issue22764] object lifetime fragility in unittest tests

2014-10-30 Thread Robert Collins

Robert Collins added the comment:

Herewith a patch. Applied to unittest2 for backport to unbreak its tests on 
pypy.

--
keywords: +patch
Added file: http://bugs.python.org/file37072/issue22764.patch

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



[issue22764] object lifetime fragility in unittest tests

2014-10-30 Thread Robert Collins

Changes by Robert Collins robe...@robertcollins.net:


--
type:  - behavior

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



[issue20440] Use Py_REPLACE/Py_XREPLACE macros

2014-10-30 Thread Eldar Abusalimov

Changes by Eldar Abusalimov eldar.abusali...@gmail.com:


--
nosy: +abusalimov

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



[issue22764] object lifetime fragility in unittest tests

2014-10-30 Thread Antoine Pitrou

Antoine Pitrou added the comment:

I think the change in test_assertions is wrong: it doesn't test what the change 
was meant to fix in the first place.

--
nosy: +pitrou

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



[issue22764] object lifetime fragility in unittest tests

2014-10-30 Thread Antoine Pitrou

Antoine Pitrou added the comment:

You could instead mark the test as cpython-specific.

--

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



[issue22764] object lifetime fragility in unittest tests

2014-10-30 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Le 30/10/2014 12:00, Robert Collins a écrit :
 
 Ah, perhaps the test was flawed to start with, since no effort is
 made
in it to capture the error and then process it. If we pass a result in,
the traceback will have a ref and gc.collect() can't possibly be
discarding the entire structure.

Yes, that would be another way to fix it, probably.

--

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



[issue22764] object lifetime fragility in unittest tests

2014-10-30 Thread Robert Collins

Robert Collins added the comment:

Hmm? I must have misunderstood the test. Here's my understanding: the test is 
testing that a an object ref only held in the traceback object of the exception 
is cleaned up such that it can be collected. In a refcount system that 
collection is immediate, in a gc world its after the next gc run.

Ah, perhaps the test was flawed to start with, since no effort is made in it to 
capture the error and then process it. If we pass a result in, the traceback 
will have a ref and gc.collect() can't possibly be discarding the entire 
structure.

--

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



[issue22764] object lifetime fragility in unittest tests

2014-10-30 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 Here's my understanding: the test is testing that a an object ref only held 
 in the traceback object of the exception is cleaned up such that it can be 
 collected

The best way to check would be to revert the case.py changes in 6ab3193e890e. 
My intuition is that the test would then fail, but succeed with your changes.

--

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



[issue22765] Fixes for test_gdb (first frame address, entry values)

2014-10-30 Thread Bohuslav Slavek Kabrda

New submission from Bohuslav Slavek Kabrda:

The attached patch fixes two test_gdb problems that can occur under some 
circumstances:

- With new GDB (I think version = 7.4.0, but I'm not sure about the precise 
version), GDB sometimes prints entry-values for variables, which can lead to 
failures like: AssertionError: 'v@entry=()' != '()'. The cure for that is 
using set print entry-values no in GDB. I think this is also the root cause 
of issue 17126.

- While building on ppc64 little endian for Fedora, we experienced GDB printing 
program counter for the first frame, which breaks regular expressions matching 
in tests, e.g. instead of

#0 in PyObject_Print

the lines can look like

#0 0x3fffb7dd1798 in PyObject_Print

I've talked to Fedora's GDB maintainer and I've been told that this can happen 
and it's not a GDB bug - GDB does not guarantee this. Therefore the second part 
of the attached patch turns printing program counters for *all* frames using 
set print address off to achieve same GDB output everywhere.

--
components: Tests
files: test_gdb-ppc64le-and-entry-values-fix.patch
keywords: patch
messages: 230265
nosy: bkabrda
priority: normal
severity: normal
status: open
title: Fixes for test_gdb (first frame address, entry values)
versions: Python 2.7, Python 3.5
Added file: 
http://bugs.python.org/file37073/test_gdb-ppc64le-and-entry-values-fix.patch

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



[issue22682] Add support of KZ1048 (RK1048) encoding

2014-10-30 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc added the comment:

Looks good to me.
I checked that there are only 16 differences between cp1251 and kz1048,
and that the two standards define the same mapping.

--
nosy: +amaury.forgeotdarc

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



[issue22141] rlcompleter.Completer matches too much

2014-10-30 Thread Claudiu Popa

Claudiu Popa added the comment:

Looks good to me. You might want to sign the contributor agreement: 
https://www.python.org/psf/contrib/contrib-form/. This is required for 
non-trivial contributions. You'll get a * next to your name after signing it.

--
stage: patch review - commit review

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



[issue22763] load_tests chaining into discover from non-discover entry point gets top_level_dir wrong

2014-10-30 Thread R. David Murray

R. David Murray added the comment:

+1 on the refactoring.  I think it makes more conceptual sense.

--
nosy: +r.david.murray

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



[issue22143] rlcompleter.Completer has duplicate matches

2014-10-30 Thread Claudiu Popa

Claudiu Popa added the comment:

I don't know why there's no review link for your patch. Anyway..

+self.assertTrue(c.complete(A.foo, 0) in ['A.foo(', 'A.foobar('])
+self.assertTrue(c.complete(A.foo, 1) in ['A.foo(', 'A.foobar('])


You can use self.assertIn for these.

+self.assertEqual(c.complete(b.foo, 1), None)


self.assertIsNone.


Otherwise, the patch looks good to me.

--

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



[issue22143] rlcompleter.Completer has duplicate matches

2014-10-30 Thread Lorenz Quack

Lorenz Quack added the comment:

Thanks for reviewing!

test now use assertIn and assertIsNone as suggested

PS: My Contributors Agreement is in progress. Just emailed the PSF with some 
question (but I intend to sign it)

--
Added file: http://bugs.python.org/file37074/rlcompleter_22143.patch

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



[issue22766] collections.Counter's in-place operators should return NotImplemented for unsupported types

2014-10-30 Thread Joshua Chin

New submission from Joshua Chin:

Currently, in-place operations on 'collections.Counter' with unsupported types 
raises an 'AttributeError'.

Example:
 import collections
 counter = collections.Counter()
 counter += 1
Traceback (most recent call last):
  File stdin, line 1, in module
  File 
/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/collections/__init__.py,
 line 709, in __iadd__
for elem, count in other.items():
AttributeError: 'int' object has no attribute 'items'

Instead, it should return 'NotImplemented' if 'other' is not a 
'collections.Counter'

--
components: Library (Lib)
files: counter.patch
keywords: patch
messages: 230271
nosy: Joshua.Chin
priority: normal
severity: normal
status: open
title: collections.Counter's in-place operators should return NotImplemented 
for unsupported types
type: behavior
versions: Python 3.4
Added file: http://bugs.python.org/file37075/counter.patch

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



[issue22766] collections.Counter's in-place operators should return NotImplemented for unsupported types

2014-10-30 Thread Ethan Furman

Changes by Ethan Furman et...@stoneleaf.us:


--
assignee:  - rhettinger
nosy: +ethan.furman, rhettinger

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



[issue22766] collections.Counter's in-place operators should return NotImplemented for unsupported types

2014-10-30 Thread Ethan Furman

Changes by Ethan Furman et...@stoneleaf.us:


--
versions: +Python 2.7, Python 3.5

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



[issue22766] collections.Counter's in-place operators should return NotImplemented for unsupported types

2014-10-30 Thread R. David Murray

R. David Murray added the comment:

That would prevent it from working with work alike (duck type) classes, 
though.

--
nosy: +r.david.murray

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



[issue22766] collections.Counter's in-place operators should return NotImplemented for unsupported types

2014-10-30 Thread Ethan Furman

Ethan Furman added the comment:

As I noted in my review, the docstring specifically says other Counter.

If we want to relax that we could check for an 'items' attribute and 'return 
NotImplemented' if it isn't there, but one or the other should definitely 
happen.

--

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



[issue22767] `separators` argument to json.dumps() behaves unexpectedly across 2.x vs 3.x

2014-10-30 Thread Tom Christie

New submission from Tom Christie:

This is one of those behavioural issues that is a borderline bug.

The seperators argument to `json.dumps()` behaves differently across python 2 
and 3.

* In python 2 it should be provided as a bytestring, and can cause a 
UnicodeDecodeError otherwise.
* In python 3 it should be provided as unicode,and can cause a TypeError 
otherwise.

Examples:

Python 2.7.2
 print json.dumps({'snowman': '☃'}, separators=(':', ','), 
ensure_ascii=False)
{snowman,☃}
 print json.dumps({'snowman': '☃'}, separators=(u':', u','), 
ensure_ascii=False)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1: 
ordinal not in range(128)

And:

Python 3.4.0
 print(json.dumps({'snowman': '☃'}, separators=(':', ','), 
ensure_ascii=False))
{snowman,☃}
 print(json.dumps({'snowman': '☃'}, separators=(b':', b','), 
ensure_ascii=False))
...
TypeError: sequence item 2: expected str instance, bytes found

Technically this isn't out of line with the documentation - in both cases it 
uses `separators=(':', ',')` which is indeed the correct type in both v2 and 
v3. However it's unexpected behaviour that it changes types between versions, 
without being called out.

Working on a codebase with `from __future__ import unicode_literals` this is 
particularly unexpected because we get a `UnicodeDecodeError` when running code 
that otherwise looks correct.

It's also slightly awkward to fix because it's a bit of a weird branch 
condition.

The fix would probably be to forcibly coerce it to the correct type regardless 
of if it is supplied as unicode or a bytestring, or at least to do so for 
python 2.7.

Possibly related to http://bugs.python.org/issue22701 but wasn't able to 
understand if that ticket was in fact a different user error.

--
messages: 230274
nosy: Tom.Christie
priority: normal
severity: normal
status: open
title: `separators` argument to json.dumps() behaves unexpectedly across 2.x vs 
3.x
type: behavior
versions: Python 2.7, Python 3.4

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



[issue22767] `separators` argument to json.dumps() behaves unexpectedly across 2.x vs 3.x

2014-10-30 Thread Georg Brandl

Georg Brandl added the comment:

IMO the snowman should be a Unicode string in the second example for Python 2.7.

--
nosy: +georg.brandl

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



[issue22767] `separators` argument to json.dumps() behaves unexpectedly across 2.x vs 3.x

2014-10-30 Thread Georg Brandl

Georg Brandl added the comment:

 in the second example

or even, in both examples.

--

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



[issue22766] collections.Counter's in-place operators should return NotImplemented for unsupported types

2014-10-30 Thread R. David Murray

R. David Murray added the comment:

'counter' in the docstrings is in lower case, so that says nothing dispositive. 
 However, __add__ does an ininstance check, so it is hard to see why __iadd__ 
does not.

Personally I'd drop the isinstance checks and let the errors bubble up as they 
may.  Why should subtract explicitly support other data types, but not 
__sub__/__isub__?  But Raymond's opinion should hold the most weight here.

--

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



[issue22766] collections.Counter's in-place operators should return NotImplemented for unsupported types

2014-10-30 Thread Ethan Furman

Ethan Furman added the comment:

Indeed -- we mostly discuss with each other to try and sway his opinion.  :)

stdlib types should not let every error bubble up.  Consider a dict:

-- d = {}
-- d += 2
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: unsupported operand type(s) for +=: 'dict' and 'int'


now look at Counter

-- from collections import Counter
-- c = Counter()
-- c += 2
Traceback (most recent call last):
  File stdin, line 1, in module
  File /home/ethan/source/python/cpython/Lib/collections/__init__.py, line 
709, in __iadd__
for elem, count in other.items():
AttributeError: 'int' object has no attribute 'items'


Counter is not user-friendly in this case.

There are other areas of Counter that accept arbitrary mappings, so I would be 
fine the __ixxx__ methods also accepting arbitrary mappings, but if the thing 
passed in *will not* work with Counter, then returning NotImplemented is the 
appropriate course of action.

--

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



[issue22767] `separators` argument to json.dumps() behaves unexpectedly across 2.x vs 3.x

2014-10-30 Thread R. David Murray

R. David Murray added the comment:

And that works, including with the future import.  I don't remember if this is 
a bug we've fixed since 2.7.2, but I don't think so.

In Python3, json explicitly does not support bytes.

--
nosy: +r.david.murray
resolution:  - not a bug
stage:  - resolved
status: open - closed

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



[issue22766] collections.Counter's in-place operators should return NotImplemented for unsupported types

2014-10-30 Thread Antoine Pitrou

Antoine Pitrou added the comment:

I also think returning NotImplemented would be the right thing here.

--
nosy: +pitrou
type: behavior - enhancement
versions:  -Python 2.7, Python 3.4

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



[issue22768] Add a way to get the peer certificate of a SSL Transport

2014-10-30 Thread Mathieu Pasquet

New submission from Mathieu Pasquet:

Currently, the only workaround is to use transport._sock.getpeercert(True) on 
the Transport returned by loop.create_connection(), which is not something to 
be encouraged. It is useful to get such information, for example to perform a 
manual certificate check against a previously recorded certificate or hash.

I attached a trivial patch adding an extra 'peercert_bin' info, but I do not 
know if this is the right approach, as other issues of feature disparity might 
arise when more people try to switch to asyncio. Exposing a proxy SSLSocket 
object for read-only functions might be more beneficial.

--
components: asyncio
files: peercert_bin.patch
keywords: patch
messages: 230281
nosy: gvanrossum, haypo, mathieui, yselivanov
priority: normal
severity: normal
status: open
title: Add a way to get the peer certificate of a SSL Transport
type: enhancement
versions: Python 3.4
Added file: http://bugs.python.org/file37076/peercert_bin.patch

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



[issue22768] Add a way to get the peer certificate of a SSL Transport

2014-10-30 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Thanks for the patch!

 other issues of
 feature disparity might arise when more people try to switch to asyncio. 
 Exposing a proxy SSLSocket object for read-only functions might be
 more beneficial.

I'm not sure that would make a difference. We still have to implement the proxy 
SSLSocket, which is no easier than adding the extra info by hand. Or did I 
misunderstand you?

--
nosy: +pitrou

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



[issue8876] distutils should not assume that hardlinks will work

2014-10-30 Thread Roundup Robot

Roundup Robot added the comment:

New changeset d94d8789e924 by Antoine Pitrou in branch '3.4':
Issue #8876: distutils now falls back to copying files when hard linking 
doesn't work.
https://hg.python.org/cpython/rev/d94d8789e924

New changeset ce484e0840e3 by Antoine Pitrou in branch 'default':
Issue #8876: distutils now falls back to copying files when hard linking 
doesn't work.
https://hg.python.org/cpython/rev/ce484e0840e3

--
nosy: +python-dev

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



[issue22768] Add a way to get the peer certificate of a SSL Transport

2014-10-30 Thread Mathieu Pasquet

Mathieu Pasquet added the comment:

I'm not sure that would make a difference. We still have to implement
the proxy SSLSocket, which is no easier than adding the extra info by
hand. Or did I misunderstand you?


The difference would be that exposing methods can be more future-proof, as some 
methods take parameters (like the offender getpeercert(bool), or 
get_channel_binding() that takes an element of ssl.CHANNEL_BINDING_TYPES, list 
that may grow in the future) that need to be covered in the properties. But the 
API of SSLSocket is stable and small so I don't think it really matters.

--

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



[issue8876] distutils should not assume that hardlinks will work

2014-10-30 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 263395345aa7 by Antoine Pitrou in branch '2.7':
Issue #8876: distutils now falls back to copying files when hard linking 
doesn't work.
https://hg.python.org/cpython/rev/263395345aa7

--

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



[issue8876] distutils should not assume that hardlinks will work

2014-10-30 Thread Antoine Pitrou

Antoine Pitrou added the comment:

This should now be fixed. Thanks for your patience :)

--
resolution:  - fixed
stage: patch review - resolved
status: open - closed

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




[issue22768] Add a way to get the peer certificate of a SSL Transport

2014-10-30 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 some methods take parameters (like the offender getpeercert(bool), or 
 get_channel_binding() that takes an element of 
 ssl.CHANNEL_BINDING_TYPES, list that may grow in the future) that need 
 to be covered in the properties

That's a good point. I don't have any strong feelings either way. Perhaps other 
people want to chime in?

As for the patch, it will need to add a unit test as well.

--
stage:  - patch review
versions: +Python 3.5 -Python 3.4

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



[issue22765] Fixes for test_gdb (first frame address, entry values)

2014-10-30 Thread Antoine Pitrou

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


--
nosy: +dmalcolm

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



[issue22417] PEP 476: verify HTTPS certificates by default

2014-10-30 Thread Alex Gaynor

Alex Gaynor added the comment:

Patch now makes more precise assertions about the type of error that's 
occurring.

--
Added file: http://bugs.python.org/file37077/issue22417.diff

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



[issue22767] `separators` argument to json.dumps() behaves unexpectedly across 2.x vs 3.x

2014-10-30 Thread Tom Christie

Tom Christie added the comment:

Not too fussed if this is addressed or not, but I think this is closed a little 
prematurely.

I don't think there's a problem under Python 3, that's entirely reasonable.

However under Python 2, `json.dumps()` will normally handle *either* bytes or 
unicode transparently for you (just altering the return type accordingly).

If you happen to be using unicode separators, then the normally lax behaviour 
of either unicode or bytes that stops being the case.

--

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



[issue8876] distutils should not assume that hardlinks will work

2014-10-30 Thread Éric Araujo

Éric Araujo added the comment:

Thanks for the patches folks!

--

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



[issue22767] `separators` argument to json.dumps() behaves unexpectedly across 2.x vs 3.x

2014-10-30 Thread R. David Murray

R. David Murray added the comment:

But only if you use non-ascii in the binary input, in which case you get an 
encoding error, which is a correct error.

--

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



[issue22759] pathlib: Path.exists broken

2014-10-30 Thread Antoine Pitrou

Antoine Pitrou added the comment:

ENAMETOOLONG: that doesn't mean the file doesn't exist. For example, it could 
be accessed by changing the current directory and shortening the residual path 
name.

ELOOP: unfortunately it doesn't guarantee that there is a real symlink loop, 
just that the OS decided to bail out after a certain number of indirections.

So in both cases I think we should let the errors bubble up.

--

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



[issue22759] pathlib: Path.exists broken

2014-10-30 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Here is a patch with tests.

--
stage: test needed - patch review
Added file: http://bugs.python.org/file37078/path_exists_enotdir.patch

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



[issue22759] pathlib: Path.exists broken

2014-10-30 Thread Hristo Venev

Hristo Venev added the comment:

Should I file bugs for is_dir, is_file, is_symlink, is_socket, is_fifo, 
is_block_device and is_char_device?

--

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



[issue22759] pathlib: Path.exists broken

2014-10-30 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Le 30/10/2014 20:36, Hristo Venev a écrit :
 
 Hristo Venev added the comment:
 
 Should I file bugs for is_dir, is_file, is_symlink, is_socket, is_fifo, 
 is_block_device and is_char_device?

Hmm... good catch. No, this issue will do.

--

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



[issue22759] pathlib: Path.exists broken

2014-10-30 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Updated patch for other querying function.

--
Added file: http://bugs.python.org/file37079/path_exists_enotdir2.patch

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



  1   2   >