[issue1611944] sndhdr.what() does not recognize wav file

2008-09-16 Thread Matthijs Kooijman

Matthijs Kooijman <[EMAIL PROTECTED]> added the comment:

I've written a new patch, which works a bit better. You can find the new
patch attached.

I've restructed the patch to prevent code duplication. Also, it now
works with other chunks than bext (I had a file with a list chunk which
triggered my interest in this bug). This is done with a hardcoded list
of valid chunks. However, it seems that there is no complete list of
valid chunk types, so it might be better to remove the chunk type check
alltogether.

Also, this patch explicitly checks for overflow, since taking a slice of
a sequence does not seem to trigger an IndexError, but just return an
empty sequence.

--
keywords: +patch
nosy: +matthijs
Added file: http://bugs.python.org/file11501/sndhdr.diff

___
Python tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1611944>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22454] Adding the opposite function of shlex.split()

2018-04-25 Thread Matthijs Kooijman

Change by Matthijs Kooijman :


--
nosy: +Matthijs Kooijman

___
Python tracker 
<https://bugs.python.org/issue22454>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22454] Adding the opposite function of shlex.split()

2018-06-07 Thread Matthijs Kooijman


Matthijs Kooijman  added the comment:

One usecase that such a function would be well-suited for is for *displaying* 
commands being executed. Then, the commands will be executed as a command+args 
array, but can be displayed unambiguously in log output.

--

___
Python tracker 
<https://bugs.python.org/issue22454>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34188] Allow dict choices to "transform" values in argpagse

2018-08-17 Thread Matthijs Kooijman


Matthijs Kooijman  added the comment:

I was today trying to achieve something similar. I also considered the solution 
using `type` argument, but that does not seem to play well with the `choices` 
argument. I was going to report that as a bug, but this issue seems similar 
enough to comment here instead.

The solution proposed by Paul works, in the sense that if 'I' is passed on the 
commandline, the parsed value because `int` (the actual type, not a string, not 
sure if Paul really intended that). However, when running --help with his 
example, you get:

usage: foo.py [-h] {,}

So:
  - Since the `choices` argument is used to display help text, `choices` should 
 contain the values that should be specified on the commandline (e.g. the 
*inputs* to the `type` converter.
 - Since the *type-converted* value is checked against the `choices` argument, 
`choices` should contain the *outputs* of the `type` converter.

AFAICS these two constraints cannot be fulfilled at the same time, except when 
no type conversion happens (or, when converted values can be stringified back 
to their unconverted value, which works in simple cases, I suppose).

IMHO this looks like a bug: `type` and `choices` do not play well together. 
Checking specified values against `choices` *before* type conversion happens 
seems more sensible to me and would fix this, as well  fullfil Victor's 
original usecase (though not with the syntax he suggests).

------
nosy: +Matthijs Kooijman

___
Python tracker 
<https://bugs.python.org/issue34188>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34188] Allow dict choices to "transform" values in argpagse

2018-08-17 Thread Matthijs Kooijman


Matthijs Kooijman  added the comment:

One way to make the original example from Victor work, is to use the following 
action class:

  class ConvertChoices(argparse.Action):
 
  """   
 
  Argparse action that interprets the `choices` argument as a dict  
  
  mapping the user-specified choices values to the resulting option 
  
  values.   
 
  """   
 
  def __init__(self, *args, choices, **kwargs): 
  
  super().__init__(*args, choices=choices.keys(), **kwargs) 
  
  self.mapping = choices
 

 
  def __call__(self, parser, namespace, value, option_string=None): 
  
  setattr(namespace, self.dest, self.mapping[value])

--

___
Python tracker 
<https://bugs.python.org/issue34188>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com