[issue41965] distutils.spawn.find_executable() fails to find .py files on Windows

2020-10-07 Thread Alexander Todorov


Alexander Todorov  added the comment:

@Eryk Sun,
you are of course correct but still don't we need to handle this in Python? 

- find_executable() will search for rst2man.py.exe which doesn't exist so no 
good for the user
- there is also no rst2man.exe which is probably an issue with how docutils 
distributes this script - e.g. it doesn't distribute the wrapper .exe file
- lastly the caller (in my case python-bugzilla) will try to execute rst2man.py 
which will probably fail but at least they would see another failure and are 
more likely to change their own code base

The trouble for me here is that find_executable() will generally not find 
anything that doesn't have .exe suffix on Windows. This is independent of how 
the resulting file would be consumed later.

--

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



[issue41965] distutils.spawn.find_executable() fails to find .py files on Windows

2020-10-07 Thread Alexander Todorov


New submission from Alexander Todorov :

As part of installing python-bugzilla via pip it searches for `rst2man` or 
`rst2man.py`, see:
https://github.com/python-bugzilla/python-bugzilla/blob/master/setup.py#L81

on Windows venvs there is venv\Scripts\rst2man.py (no .exe or without suffix) 
and when you call find_executable('rst2man.py') if doesn't find it.


The trouble is in this code snippet:

```
_, ext = os.path.splitext(executable)
if (sys.platform == 'win32') and (ext != '.exe'):
executable = executable + '.exe'
```

`ext` here is `.py` and the if condition executes its body so the executable to 
search for becomes `rst2man.py.exe` which doesn't exist.

The extension check has been like that for more than 20 years:
https://github.com/python/cpython/commit/69628b0ad10f89a65902f5b911d1040ed9ae1ca2

but IMO it should be 

```
if (sys.platform == 'win32') and (ext == ''):
executable = executable + '.exe'
```

i.e. add `.exe` only if the file we're looking for doesn't already have an 
extension.


Let me know what you think? I can submit a PR for this.


Related issues:

- https://bugs.python.org/issue2200

- https://bugs.python.org/issue39260

--
components: Distutils
messages: 378150
nosy: Alexander.Todorov, dstufft, eric.araujo
priority: normal
severity: normal
status: open
title: distutils.spawn.find_executable() fails to find .py files on Windows
type: behavior

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



[issue29756] Improve documentation for list methods that compare items by equality

2017-03-12 Thread Alexander Todorov

Alexander Todorov added the comment:

Hi folks,
I have another very similar issue, it could be the same root cause. Let me know 
if it is. 

assert 3 == 3.0  will pass

self.assertEqual(3, 3.0) - will pass

this had the nasty side effect of my test suite not catching a problem with 
SUT. I have updated the test suite to validate the result type as well but want 
to know how to file this use-case.

--

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



[issue29756] List count() counts True as 1

2017-03-08 Thread Alexander Todorov

New submission from Alexander Todorov:

When using list.count() I get the following results

>>> [1, 2, 3].count(1)
1
>>> [1, 2, 3, True].count(2)
1
>>> [1, 2, 3, True].count(True)
2
>>> [1, 2, 3, True].count(1)
2

as you can see True is considered the same as 1.  The documentation for the 
count method says:

count(...)
L.count(value) -> integer -- return number of occurrences of value

so IMO the above behavior is wrong. Seeing this on a RHEL 7 system with 
Python 3.5.1 and 2.7.5

--
messages: 289235
nosy: Alexander Todorov
priority: normal
severity: normal
status: open
title: List count() counts True as 1
versions: Python 2.7, Python 3.5

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



[issue27578] inspect.findsource raises exception with empty __init__.py

2016-07-20 Thread Alexander Todorov

New submission from Alexander Todorov:

$ python2
Python 2.7.5 (default, Oct 11 2015, 17:47:16) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import inspect
>>> from pykickstart import handlers
>>> inspect.getsource(handlers)
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib64/python2.7/inspect.py", line 701, in getsource
lines, lnum = getsourcelines(object)
  File "/usr/lib64/python2.7/inspect.py", line 690, in getsourcelines
lines, lnum = findsource(object)
  File "/usr/lib64/python2.7/inspect.py", line 538, in findsource
raise IOError('could not get source code')
IOError: could not get source code
>>> 

There is a `pykickstart/handlers/__init__.py` file which is empty and the above 
import works fine as you can see. However `inspect.findsource` raises an 
exception. The same problem exists in Python 3.5 as well. The error comes from 
here:

532 module = getmodule(object, file)
533 if module:
534 lines = linecache.getlines(file, module.__dict__)
535 else:
536 lines = linecache.getlines(file)
537 if not lines:
538 raise IOError('could not get source code')


At this point `lines` is an empty list and we raise the exception. I'm hitting 
this problem when using a mutation testing tool that relies on getsource (which 
calls findsource). 

One possible workaround is to add a comment in the __init__.py file and 
everything seems to be working then. Another one is to patch the tool I'm using 
to take into account empty __init__.py files.

--
components: Library (Lib)
messages: 270867
nosy: Alexander Todorov
priority: normal
severity: normal
status: open
title: inspect.findsource raises exception with empty __init__.py
type: behavior
versions: Python 2.7, Python 3.5

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



[issue25722] Lib/ssl.py breaks certificate validation for wildcard domains, e.g. *.s3.amazonaws.com

2015-11-24 Thread Alexander Todorov

New submission from Alexander Todorov:

The latest ssl.py file tries to validate hostnames vs certificates but includes 
a faulty regexp which causes any wildcard domains (e.g. *.s3.amazonaws.com) to 
fail validation. 

Steps to Reproduce:
>>> import ssl
>>> ssl._dnsname_match("*.s3.amazonaws.com", 
>>> "planet.sofiavalley.com.s3.amazonaws.com")
>>> 

>From Python's documentation:

[]

Used to indicate a set of characters. In a set:

...
Special characters lose their special meaning inside sets. For example, 
[(+*)] will match any of the literal characters '(', '+', '*', or ')'.


^ this is the cause of the error

I've found this after an upgrade to RHEL 7.2 which contains the faulty code 
broke s3cmd for me. The result - one of my sites was outdated for a couple of 
days.

For more info and proposed patch see:
https://bugzilla.redhat.com/show_bug.cgi?id=1284916
https://bugzilla.redhat.com/show_bug.cgi?id=1284930

Note: As far as I can tell this affects upstream Python 2.7.10 and 3.5.0, 
however in the packages Red Hat distributes the code is different between 2 and 
3 while upstream is more consistent.

--
messages: 255265
nosy: Alexander Todorov
priority: normal
severity: normal
status: open
title: Lib/ssl.py breaks certificate validation for wildcard domains, e.g. 
*.s3.amazonaws.com
versions: Python 2.7, Python 3.5

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



[issue22891] code removal from urllib.parse.urlsplit()

2014-11-18 Thread Alexander Todorov

Alexander Todorov added the comment:

 Does test cases pass after removal of those lines? (I will be surprised) 

Yes they do. Also see my detailed explanation above, there's no reason for test 
cases to fail.

--

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



[issue22891] [patch]: code removal from urllib.parse.urlsplit()

2014-11-17 Thread Alexander Todorov

New submission from Alexander Todorov:

In the urllib.parse (or urlparse on Python 2.X) module there is this function:

157 def urlsplit(url, scheme='', allow_fragments=True):
158 Parse a URL into 5 components:
159 scheme://netloc/path?query#fragment
160 Return a 5-tuple: (scheme, netloc, path, query, fragment).
161 Note that we don't break the components up in smaller bits
162 (e.g. netloc is a single string) and we don't expand % escapes.
163 allow_fragments = bool(allow_fragments)
164 key = url, scheme, allow_fragments, type(url), type(scheme)
165 cached = _parse_cache.get(key, None)
166 if cached:
167 return cached
168 if len(_parse_cache) = MAX_CACHE_SIZE: # avoid runaway growth
169 clear_cache()
170 netloc = query = fragment = ''
171 i = url.find(':')
172 if i  0:
173 if url[:i] == 'http': # optimize the common case
174 scheme = url[:i].lower()
175 url = url[i+1:]
176 if url[:2] == '//':
177 netloc, url = _splitnetloc(url, 2)
178 if allow_fragments and '#' in url:
179 url, fragment = url.split('#', 1)
180 if '?' in url:
181 url, query = url.split('?', 1)
182 v = SplitResult(scheme, netloc, url, query, fragment)
183 _parse_cache[key] = v
184 return v
185 for c in url[:i]:
186 if c not in scheme_chars:
187 break
188 else:
189 scheme, url = url[:i].lower(), url[i+1:]
190 
191 if url[:2] == '//':
192 netloc, url = _splitnetloc(url, 2)
193 if allow_fragments and '#' in url:
194 url, fragment = url.split('#', 1)
195 if '?' in url:
196 url, query = url.split('?', 1)
197 v = SplitResult(scheme, netloc, url, query, fragment)
198 _parse_cache[key] = v
199 return v



There is an issue here (or a few of them) as follows:

* if url[:1] is already lowercase (equals http) (line 173) then .lower() on  
line 174 is reduntant:
174scheme = url[:i].lower() # --- no need for .lower() b/c value is http


* OTOH line 173 could refactor the condition and match URLs where the scheme is 
uppercase. For example
173 if url[:i].lower() == 'http': # optimize the common case

* The code as is returns the same results (as far as I've tested it) for both:
urlsplit(http://github.com/atodorov/repo.git?param=value#myfragment;)
urlsplit(HTTP://github.com/atodorov/repo.git?param=value#myfragment)
urlsplit(HTtP://github.com/atodorov/repo.git?param=value#myfragment)

but the last 2 invocations also go through lines 185-199


* Lines 174-184 are essentially the same as lines 189-199. The only 
optimization I can see is avoiding the for loop around lines 185-187 which 
checks for valid characters in the URL scheme and executes only a few loops b/c 
scheme names are quite short usually.


My personal vote goes for removal of lines 173-184. 


Version-Release number of selected component (if applicable):

This is present in both Python 3 and Python 2 on all versions I have access to:

python3-libs-3.4.1-16.fc21.x86_64.rpm
python-libs-2.7.8-5.fc21.x86_64.rpm
python-libs-2.7.5-16.el7.x86_64.rpm
python-libs-2.6.6-52.el6.x86_64

Versions are from Fedora Rawhide and RHEL. Also the same code is present in the 
Mercurial repository.

Bug first reported as
https://bugzilla.redhat.com/show_bug.cgi?id=1160603

and now filing here for upstream consideration.

--
components: Library (Lib)
files: urlparse_refactor.patch
keywords: patch
messages: 231278
nosy: Alexander.Todorov
priority: normal
severity: normal
status: open
title: [patch]: code removal from urllib.parse.urlsplit()
type: enhancement
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6
Added file: http://bugs.python.org/file37212/urlparse_refactor.patch

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