[issue12567] curses implementation of Unicode is wrong in Python 3

2011-11-27 Thread STINNER Victor

STINNER Victor  added the comment:

New changeset bf51e32b2a81 by Victor Stinner in branch 'default':
Issue #13415: test_curses skips unencodable characters
http://hg.python.org/cpython/rev/bf51e32b2a81

(Oops, I copy-pasted the issue number from my previous commit, and the issue 
number was wrong...)

--

___
Python tracker 

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



[issue13415] del os.environ[key] ignores errors

2011-11-27 Thread STINNER Victor

Changes by STINNER Victor :


--
Removed message: http://bugs.python.org/msg148467

___
Python tracker 

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



[issue12567] curses implementation of Unicode is wrong in Python 3

2011-11-27 Thread STINNER Victor

STINNER Victor  added the comment:

Compile output on OpenSolaris:

Consider setting $PYTHONHOME to [:]
ld: fatal: file /usr/local/lib/libncursesw.so: wrong ELF class: ELFCLASS32
ld: fatal: file processing errors. No output written to 
build/lib.solaris-2.11-i86pc-3.3-pydebug/readline.so
collect2: ld returned 1 exit status
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:279:
 error: expected declaration specifiers or '...' before 'cchar_t'
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:
 In function 'PyCurses_ConvertToCchar_t':
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:298:
 error: 'wch' undeclared (first use in this function)
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:298:
 error: (Each undeclared identifier is reported only once
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:298:
 error: for each function it appears in.)
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:
 In function 'PyCursesWindow_AddCh':
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:584:
 error: 'cchar_t' undeclared (first use in this function)
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:584:
 error: expected ';' before 'wch'
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:618:
 error: 'wch' undeclared (first use in this function)
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:618:
 error: too many arguments to function 'PyCurses_ConvertToCchar_t'
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:623:
 warning: implicit declaration of function 'mvwadd_wch'
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:625:
 warning: implicit declaration of function 'wadd_wch'
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:
 In function 'PyCursesWindow_AddStr':
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:702:
 warning: implicit declaration of function 'mvwaddwstr'
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:704:
 warning: implicit declaration of function 'waddwstr'
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:
 In function 'PyCursesWindow_AddNStr':
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:779:
 warning: implicit declaration of function 'mvwaddnwstr'
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:781:
 warning: implicit declaration of function 'waddnwstr'
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:
 In function 'PyCursesWindow_Get_WCh':
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:1187:
 warning: implicit declaration of function 'wget_wch'
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:1194:
 warning: implicit declaration of function 'mvwget_wch'
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:
 In function 'PyCursesWindow_InsStr':
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:1468:
 warning: implicit declaration of function 'mvwins_wstr'
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:1470:
 warning: implicit declaration of function 'wins_wstr'
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:
 In function 'PyCursesWindow_InsNStr':
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:1546:
 warning: implicit declaration of function 'mvwins_nwstr'
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:1548:
 warning: implicit declaration of function 'wins_nwstr'
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:
 In function 'PyCurses_Unget_Wch':
/export/home/buildbot/64bits/3.x.cea-indiana-amd64/build/Modules/_cursesmodule.c:3130:
 warning: implicit declaration of function 'unget_wch'
ld: fatal: file /usr/local/lib/libpanelw.so: wrong ELF class: ELFCLASS32
ld: fatal: file /usr/local/lib/libncursesw.so: wrong ELF class: ELFCLASS32
ld: fatal: file processing errors. No output written to 
build/lib.solaris-2.11-i86pc-3.3-pydebug/_curses_panel.so
collect2: ld returned 1 exit status

--

___
Python tracker 

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



[issue13415] del os.environ[key] ignores errors

2011-11-27 Thread Roundup Robot

Roundup Robot  added the comment:

New changeset bf51e32b2a81 by Victor Stinner in branch 'default':
Issue #13415: test_curses skips unencodable characters
http://hg.python.org/cpython/rev/bf51e32b2a81

--

___
Python tracker 

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



[issue13120] Default nosigint option to pdb.Pdb() prevents use in non-main thread

2011-11-27 Thread Ilya Sandler

Ilya Sandler  added the comment:

I think stuff like this can only be tested out-of-process.

So I added an out-of-process test to test_pdb.py. The test passes with the 
fixed pdb.py. (and fails with the original one).

Patch for the test attached.

--
Added file: http://bugs.python.org/file23796/test_pdb.py.patch

___
Python tracker 

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



[issue2775] Implement PEP 3108

2011-11-27 Thread Meador Inge

Changes by Meador Inge :


--
nosy: +meador.inge

___
Python tracker 

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



[issue12627] Implement PEP 394: The "python" Command on Unix-Like Systems

2011-11-27 Thread Meador Inge

Changes by Meador Inge :


--
nosy: +meador.inge

___
Python tracker 

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



[issue11107] Cache constant "slice" instances

2011-11-27 Thread Meador Inge

Changes by Meador Inge :


--
nosy: +meador.inge

___
Python tracker 

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



[issue13405] Add DTrace probes

2011-11-27 Thread Jesús Cea Avión

Jesús Cea Avión  added the comment:

New 3.3 version.

- Use the cached UTF8 of strings inside the interpreter, instead of managing 
the details manually.

- "line" probe works, even with "computed-gotos" optimization.

The only missing feature now, compared with 2.7 version, is the "stack" helper. 
Working on it.

--

___
Python tracker 

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



[issue13405] Add DTrace probes

2011-11-27 Thread Jesús Cea Avión

Changes by Jesús Cea Avión :


Removed file: http://bugs.python.org/file23792/d7c58422eada.diff

___
Python tracker 

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



[issue13405] Add DTrace probes

2011-11-27 Thread Jesús Cea Avión

Changes by Jesús Cea Avión :


Added file: http://bugs.python.org/file23795/01f206595d16.diff

___
Python tracker 

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



[issue13443] wrong links and examples in the functional HOWTO

2011-11-27 Thread A.M. Kuchling

A.M. Kuchling  added the comment:

Yes, linking to the functional module was to point people to a module that 
might be useful, even if it's not in the stdlib.  A numeric processing or 
socket handling HOWTO would also pretty much have to link to non-stdlib 
sources.  The purpose of documentation is to be useful to the reader, so I 
think if linking to something external would be reasonably useful, we should do 
it.

Another motivation for linking was to provide alternative explanations; if the 
reader finds the Functional HOWTO boring or too superficial or too complicated, 
maybe an alternative discussion like Mertz's "Text Processing" will fit their 
brain better.  (At least until those alternative sources become so outdated 
that they're useless...)

--

___
Python tracker 

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



[issue13120] Default nosigint option to pdb.Pdb() prevents use in non-main thread

2011-11-27 Thread Meador Inge

Meador Inge  added the comment:

Normally a test case is needed.  I tried the following:

diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -595,6 +595,25 @@ def test_pdb_run_with_code_object():
 (Pdb) continue
 """
 
+def test_pdb_continue_in_thread():
+"""Testing the ability to continue from a non-main thread.
+
+>>> import threading
+>>>
+>>> def start_pdb():
+... import pdb
+... pdb.Pdb().set_trace()
+... x = 1
+... y = 1
+...
+
+>>> with PdbTestInput(['continue']):
+...t = threading.Thread(target=start_pdb)
+...t.start()
+> (4)start_pdb()
+-> x = 1
+(Pdb) continue
+"""

but 'doctests' doesn't seem to play nicely with threading.  The pdb testsuite 
fails with:


[meadori@motherbrain cpython]$ ./python -m test test_pdb
[1/1] test_pdb
**
File "/home/meadori/code/python/cpython/Lib/test/test_pdb.py", line 610, in 
test.test_pdb.test_pdb_continue_in_thread
Failed example:
with PdbTestInput(['continue']):
   t = threading.Thread(target=start_pdb)
   t.start()
Expected:
> (4)start_pdb()
-> x = 1
(Pdb) continue
Got nothing
**
File "/home/meadori/code/python/cpython/Lib/test/test_pdb.py", line 34, in 
test.test_pdb.test_pdb_displayhook
Failed example:
def test_function(foo, bar):
import pdb; pdb.Pdb(nosigint=True).set_trace()
pass
Expected nothing
Got:
> (4)start_pdb()
Exception in thread Thread-1:

It looks like the output is going to the wrong test.

Anyone else have test ideas?  If not, then I guess it is OK to commit as is.

--

___
Python tracker 

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



[issue13490] broken downloads counting on pypi.python.org

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

Martin v. Löwis  added the comment:

Thanks for the report; this is now fixed.

Please use the PyPI bug tracker for such reports in the future, which can be 
found by following "Bug reports" on pypi.python.org, to 
http://sourceforge.net/tracker/?group_id=66150&atid=513503

--
resolution:  -> fixed
status: open -> closed

___
Python tracker 

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



[issue7111] abort when stderr is closed

2011-11-27 Thread Antoine Pitrou

Antoine Pitrou  added the comment:

Updated patch.

--
Added file: http://bugs.python.org/file23794/nostdio2.patch

___
Python tracker 

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



[issue7111] abort when stderr is closed

2011-11-27 Thread Antoine Pitrou

Antoine Pitrou  added the comment:

> +is_valid_fd(int fd)
> [...]
> +dummy_fd = dup(fd);
> +if (dummy_fd < 0)
> +return 0;
> +close(dummy_fd);
> 
> Why not use fstat() instead (does Windows have fstat()? And dup()?).

Windows has dup(), but no fstat().

> +@unittest.skipIf(os.name == 'nt', "test needs POSIX semantics")
> +def test_no_stdin(self):
> 
> It would maybe be more direct with skipUnless(os.name == 'posix').

Hmm, indeed.

> Finally, it's not that important, but it could maybe be possible to
> factorize the code, i.e. make a helper function that takes a list of
> streams and defines the preexec() function and code to test those
> streams, and then just call:

Ah, indeed perhaps.

--

___
Python tracker 

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



[issue13487] inspect.getmodule fails when module imports change sys.modules

2011-11-27 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc  added the comment:

You are certainly right, but I wonder how this can happen.
Are there modules which import something just by looking at them?
Or is is some race condition due to another running thread?

--
nosy: +amaury.forgeotdarc

___
Python tracker 

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



[issue13475] Add '-p'/'--path0' command line option to override sys.path[0] initialisation

2011-11-27 Thread Matthew Woodcraft

Matthew Woodcraft  added the comment:

The proposed --nopath0 option is something I've wished I had in the past.

If this is added, it would be good if it could be given a single-letter form 
too, because it's an option that would be useful in #! lines (they don't 
reliably support using more than one command-line argument, and single-letter 
switches can be combined while long-form ones can't).

--
nosy: +mattheww

___
Python tracker 

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



[issue13120] Default nosigint option to pdb.Pdb() prevents use in non-main thread

2011-11-27 Thread Georg Brandl

Georg Brandl  added the comment:

Patch seems fine to me.

--

___
Python tracker 

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



[issue13490] broken downloads counting on pypi.python.org

2011-11-27 Thread Antoine Pitrou

Changes by Antoine Pitrou :


--
nosy: +loewis

___
Python tracker 

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



[issue13120] Default nosigint option to pdb.Pdb() prevents use in non-main thread

2011-11-27 Thread Antoine Pitrou

Changes by Antoine Pitrou :


--
nosy: +georg.brandl
stage:  -> patch review
versions: +Python 3.3

___
Python tracker 

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



[issue7611] shlex not posix compliant when parsing "foo#bar"

2011-11-27 Thread Meador Inge

Meador Inge  added the comment:

Here a some of the relevant links from POSIX 2008:

   1. Shell Command Language - 
http://pubs.opengroup.org/onlinepubs/9699919799/idx/shell.html
   3. Shell Command Language Rationale - 
http://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xcu_chap02.html

Sections 2.3 
(http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_03)
 and 2.10 
(http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_10)
 of [1] are particularly relevant.

--
nosy: +meador.inge

___
Python tracker 

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



[issue11732] Skip decorator for tests requiring manual intervention on Windows

2011-11-27 Thread Brian Curtin

Brian Curtin  added the comment:

That would certainly be preferable when available on Windows 7. I'll look into 
how we can incorporate that.

Thanks for the idea!

--

___
Python tracker 

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



[issue11732] Skip decorator for tests requiring manual intervention on Windows

2011-11-27 Thread Catalin Iacob

Catalin Iacob  added the comment:

To avoid messing with system registry settings it sounds like 
WerRegisterRuntimeExceptionModule could also work, at least on Windows7 
http://msdn.microsoft.com/en-us/library/windows/desktop1/dd408167%28v=VS.85%29.aspx

There could be a dll which would do nothing when receiving the crash report for 
expected crashes (test_capi and test_faulthandler). 
WerRegisterRuntimeExceptionModule doesn't exist in the headers of the SDK that 
comes with VS2008 but it could be retrieved at runtime with GetProcAddress. 
It's more work than the registry setting but seems cleaner since it avoids 
changing system settings.

--

___
Python tracker 

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



[issue11732] Skip decorator for tests requiring manual intervention on Windows

2011-11-27 Thread Catalin Iacob

Changes by Catalin Iacob :


--
nosy: +catalin.iacob

___
Python tracker 

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



[issue5619] Pass MS CRT debug flags into subprocesses

2011-11-27 Thread Catalin Iacob

Changes by Catalin Iacob :


--
nosy: +catalin.iacob

___
Python tracker 

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



[issue9116] test_capi.test_no_FatalError_infinite_loop crash on Windows

2011-11-27 Thread Catalin Iacob

Changes by Catalin Iacob :


--
nosy: +catalin.iacob

___
Python tracker 

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



[issue13120] Default nosigint option to pdb.Pdb() prevents use in non-main thread

2011-11-27 Thread Meador Inge

Changes by Meador Inge :


--
nosy: +meador.inge

___
Python tracker 

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



[issue13487] inspect.getmodule fails when module imports change sys.modules

2011-11-27 Thread Meador Inge

Changes by Meador Inge :


--
nosy: +meador.inge

___
Python tracker 

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



[issue11610] Improved support for abstract base classes with descriptors

2011-11-27 Thread Darren Dale

Darren Dale  added the comment:

I'll bump this one last time.

--

___
Python tracker 

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



[issue12567] curses implementation of Unicode is wrong in Python 3

2011-11-27 Thread Jesús Cea Avión

Jesús Cea Avión  added the comment:

I am still concerned about the compilation warning in OpenIndiana buildbots :-(

--

___
Python tracker 

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



[issue13415] del os.environ[key] ignores errors

2011-11-27 Thread Roundup Robot

Roundup Robot  added the comment:

New changeset 11bbeaf03894 by Charles-François Natali in branch '2.7':
Issue #13415: Test in configure if unsetenv() has a return value or not.
http://hg.python.org/cpython/rev/11bbeaf03894

New changeset 99f5a0475ead by Charles-François Natali in branch '2.7':
Issue #13415: Skip test_os.test_unset_error on FreeBSD and OS X.
http://hg.python.org/cpython/rev/99f5a0475ead

--

___
Python tracker 

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



[issue13415] del os.environ[key] ignores errors

2011-11-27 Thread Roundup Robot

Roundup Robot  added the comment:

New changeset 26275a1c229c by Charles-François Natali in branch '3.2':
Issue #13415: Test in configure if unsetenv() has a return value or not.
http://hg.python.org/cpython/rev/26275a1c229c

New changeset bceb6aea8554 by Charles-François Natali in branch '3.2':
Issue #13415: Skip test_os.test_unset_error on FreeBSD and OS X.
http://hg.python.org/cpython/rev/bceb6aea8554

--

___
Python tracker 

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



[issue7111] abort when stderr is closed

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

Charles-François Natali  added the comment:

(No Rietveld link):

+is_valid_fd(int fd)
[...]
+dummy_fd = dup(fd);
+if (dummy_fd < 0)
+return 0;
+close(dummy_fd);

Why not use fstat() instead (does Windows have fstat()? And dup()?).

+@unittest.skipIf(os.name == 'nt', "test needs POSIX semantics")
+def test_no_stdin(self):

It would maybe be more direct with skipUnless(os.name == 'posix').

Finally, it's not that important, but it could maybe be possible to factorize 
the code, i.e. make a helper function that takes a list of streams and defines 
the preexec() function and code to test those streams, and then just call:

def test_no_stdin(self):
out, err = self._test_with_closed_streams(['stdin'])
[...]

def test_no_streams(self):
out, err = self._test_with_closed_streams(['stdin', 'stdout', 'stderr'])
[...]

--

___
Python tracker 

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



[issue13491] sqlite3 code adjustments

2011-11-27 Thread Nebelhom

New submission from Nebelhom :

The code examples for the sqlite3 library were in some cases non-functional.

With the help of Petri Lehtinen from core-mentorship, the following fixes are 
suggested.

NOTE: Last issue is not resolved yet, but suggestions have been made. Could you 
please review and decide what to do. The remaining issues have suggested fixes 
in the patch.

---

Connection.create_function(name, num_params, func)

Creates a user-defined function that you can later use from within SQL 
statements under the function name name. num_params is the number of parameters 
the function accepts, and func is a Python callable that is called as the SQL 
function.

The function can return any of the types supported by SQLite: bytes, str, 
int, float and None.

Example:

import sqlite3
import hashlib

def md5sum(t):
return hashlib.md5(t).hexdigest()

con = sqlite3.connect(":memory:")
con.create_function("md5", 1, md5sum)
cur = con.cursor()
cur.execute("select md5(?)", ("foo",))
print(cur.fetchone()[0])

This script raises error:

Traceback (most recent call last):
  File "sqlexample.py", line 12, in 
cur.execute("select md5(?)", ("foo",))
sqlite3.OperationalError: user-defined function raised exception

When md5sum is then run separately, the following traceback is given

>>> md5sum(("foo",))
Traceback (most recent call last):
  File "", line 1, in 
  File "sqlexample.py", line 7, in md5sum
return hashlib.md5(t).hexdigest()
TypeError: object supporting the buffer API required


Suggested fix:

Change ("foo") to (b"foo")



Connection.text_factory¶

Using this attribute you can control what objects are returned for the TEXT 
data type. By default, this attribute is set to str and the sqlite3 module will 
return Unicode objects for TEXT. If you want to return bytestrings instead, you 
can set it to bytes.

For efficiency reasons, there’s also a way to return str objects only for 
non-ASCII data, and bytes otherwise. To activate it, set this attribute to 
sqlite3.OptimizedUnicode.

You can also set it to any other callable that accepts a single bytestring 
parameter and returns the resulting object.

See the following example code for illustration:

import sqlite3

con = sqlite3.connect(":memory:")
cur = con.cursor()

# Create the table
con.execute("create table person(lastname, firstname)")

AUSTRIA = "\xd6sterreich"

# by default, rows are returned as Unicode
cur.execute("select ?", (AUSTRIA,))
row = cur.fetchone()
assert row[0] == AUSTRIA

# but we can make sqlite3 always return bytestrings ...
con.text_factory = str
cur.execute("select ?", (AUSTRIA,))
row = cur.fetchone()
assert type(row[0]) == str
# the bytestrings will be encoded in UTF-8, unless you stored garbage in the
# database ...
assert row[0] == AUSTRIA.encode("utf-8")

# we can also implement a custom text_factory ...
# here we implement one that will ignore Unicode characters that cannot be
# decoded from UTF-8
con.text_factory = lambda x: str(x, "utf-8", "ignore")
cur.execute("select ?", ("this is latin1 and would normally create errors" +
 "\xe4\xf6\xfc".encode("latin1"),))
row = cur.fetchone()
assert type(row[0]) == str

# sqlite3 offers a built-in optimized text_factory that will return 
bytestring
# objects, if the data is in ASCII only, and otherwise return unicode 
objects
con.text_factory = sqlite3.OptimizedUnicode
cur.execute("select ?", (AUSTRIA,))
row = cur.fetchone()
assert type(row[0]) == str

cur.execute("select ?", ("Germany",))
row = cur.fetchone()
assert type(row[0]) == str

The code example returns the following error traceback

Traceback (most recent call last):
  File "sqlexample.py", line 23, in 
assert row[0] == AUSTRIA.encode("utf-8")
AssertionError

Suggested fixes:
- #Create table... -> removed as not used
- all "assert type ... str" changed to "assert type ... bytes"
- # we can also implement... code block removed
- add ":meth:`[parameters]` needs to be a bytes type otherwise a TypeError will 
be raised." to the doc

-
Cursor.executemany(sql, seq_of_parameters)

Executes an SQL command against all parameter sequences or mappings found 
in the sequence sql. The sqlite3 module also allows using an iterator yielding 
parameters instead of a sequence.

Here’s a shorter example using a generator:

import sqlite3

def char_generator():
import string
for c in string.letters[:26]:
yield (c,)

con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.execute("create table characters(c)")

cur.executemany("insert into characters(c) values (?)", ch

[issue13490] broken downloads counting on pypi.python.org

2011-11-27 Thread holger krekel

New submission from holger krekel :

Seems like pypi.python.org does not properly maintain download counters 
anymore, at least for a few packages i looked at like pytest,execnet,tox,nose.

--
components: None
messages: 148447
nosy: hpk
priority: normal
severity: normal
status: open
title: broken downloads counting on pypi.python.org
type: behavior

___
Python tracker 

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