[issue1535] Rename __builtin__ to builtins

2007-12-02 Thread Georg Brandl

Georg Brandl added the comment:

Committed r59268.

--
status: open -> closed

__
Tracker <[EMAIL PROTECTED]>

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



[issue1537] Change GeneratorExit's base class from Exception to BaseException

2007-12-02 Thread Christian Heimes

Christian Heimes added the comment:

Can you also add a comment to ./Doc/reference/expressions.rst and update
Misc/NEWS please? The rest of the patch is looking good.

--
assignee:  -> tiran
keywords: +patch
nosy: +tiran
priority:  -> normal

__
Tracker <[EMAIL PROTECTED]>

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



[issue1520] 'without make' documentation build anomaly

2007-12-02 Thread Tim Golden

Tim Golden added the comment:

Looks like it's the backslash as Windows path separator confusing the
sphinx.util.relative_uri function. I'll try to put a patch together,
although I'm not sure if relative_uri should use os.sep or whether the
paths should be canonicalised before getting there. I'll try with os.sep
to start with.

--
nosy: +tim.golden

__
Tracker <[EMAIL PROTECTED]>

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



[issue1537] Change GeneratorExit's base class from Exception to BaseException

2007-12-02 Thread Antoine Pitrou

Antoine Pitrou added the comment:

I'm not sure this change is necessary. Why don't you catch StandardError
instead of Exception? StandardError catches all Exception subtypes
except GeneratorExit, StopIteration and the various Warnings.

--
nosy: +pitrou

__
Tracker <[EMAIL PROTECTED]>

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



[issue1537] Change GeneratorExit's base class from Exception to BaseException

2007-12-02 Thread Christian Heimes

Christian Heimes added the comment:

You make a good point. Can you take it to the mailing list, please?

__
Tracker <[EMAIL PROTECTED]>

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



[issue1487] PEP 366 implementation

2007-12-02 Thread Nick Coghlan

Changes by Nick Coghlan:


Removed file: http://bugs.python.org/file8794/pep_366_v1.diff

__
Tracker <[EMAIL PROTECTED]>

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



[issue1487] PEP 366 implementation

2007-12-02 Thread Nick Coghlan

Nick Coghlan added the comment:

Posted v2 of the patch, which fixes the problem Guido noted, and
improved the tests to make sure __package__ is being set correctly.
There's also now an explicit test for using -m on a module inside a
package (which proved harder to write than I expected - it isn't easy to
fiddle with sys.path when the subprocess is running python with the -E
flag!).

Added file: http://bugs.python.org/file8852/pep_366_v2.diff

__
Tracker <[EMAIL PROTECTED]>

__Index: Python/import.c
===
--- Python/import.c (revision 59120)
+++ Python/import.c (working copy)
@@ -2106,7 +2106,8 @@
 {
static PyObject *namestr = NULL;
static PyObject *pathstr = NULL;
-   PyObject *modname, *modpath, *modules, *parent;
+   static PyObject *pkgstr = NULL;
+   PyObject *pkgname, *modname, *modpath, *modules, *parent;
 
if (globals == NULL || !PyDict_Check(globals) || !level)
return Py_None;
@@ -2121,44 +2122,103 @@
if (pathstr == NULL)
return NULL;
}
+   if (pkgstr == NULL) {
+   pkgstr = PyString_InternFromString("__package__");
+   if (pkgstr == NULL)
+   return NULL;
+   }
 
*buf = '\0';
*p_buflen = 0;
-   modname = PyDict_GetItem(globals, namestr);
-   if (modname == NULL || !PyString_Check(modname))
-   return Py_None;
+   pkgname = PyDict_GetItem(globals, pkgstr);
 
-   modpath = PyDict_GetItem(globals, pathstr);
-   if (modpath != NULL) {
-   Py_ssize_t len = PyString_GET_SIZE(modname);
-   if (len > MAXPATHLEN) {
+   if ((pkgname != NULL) && (pkgname != Py_None)) {
+   /* __package__ is set, so use it */
+   Py_ssize_t len;
+   if (!PyString_Check(pkgname)) {
PyErr_SetString(PyExc_ValueError,
-   "Module name too long");
+   "__package__ set to non-string");
return NULL;
}
-   strcpy(buf, PyString_AS_STRING(modname));
-   }
-   else {
-   char *start = PyString_AS_STRING(modname);
-   char *lastdot = strrchr(start, '.');
-   size_t len;
-   if (lastdot == NULL && level > 0) {
+   len = PyString_GET_SIZE(pkgname);
+   if (len == 0) {
+   if (level > 0) {
+   PyErr_SetString(PyExc_ValueError,
+   "Attempted relative import in 
non-package");
+   return NULL;
+   }
+   return Py_None;
+   }
+   if (len > MAXPATHLEN) {
PyErr_SetString(PyExc_ValueError,
-   "Attempted relative import in non-package");
+   "Package name too long");
return NULL;
}
-   if (lastdot == NULL)
+   strcpy(buf, PyString_AS_STRING(pkgname));
+   } else {
+   /* __package__ not set, so figure it out and set it */
+   modname = PyDict_GetItem(globals, namestr);
+   if (modname == NULL || !PyString_Check(modname))
return Py_None;
-   len = lastdot - start;
-   if (len >= MAXPATHLEN) {
-   PyErr_SetString(PyExc_ValueError,
-   "Module name too long");
-   return NULL;
+   
+   modpath = PyDict_GetItem(globals, pathstr);
+   if (modpath != NULL) {
+   /* __path__ is set, so modname is already the package 
name */
+   Py_ssize_t len = PyString_GET_SIZE(modname);
+   int error;
+   if (len > MAXPATHLEN) {
+   PyErr_SetString(PyExc_ValueError,
+   "Module name too long");
+   return NULL;
+   }
+   strcpy(buf, PyString_AS_STRING(modname));
+   error = PyDict_SetItem(globals, pkgstr, modname);
+   if (error) {
+   PyErr_SetString(PyExc_ValueError,
+   "Could not set __package__");
+   return NULL;
+   }
+   } else {
+   /* Normal module, so work out the package name if any */
+   char *start = PyString_AS_STRING(modname);
+   char *lastdot = 

[issue1539] test_collections: failing refleak test

2007-12-02 Thread Christian Heimes

New submission from Christian Heimes:

The refleak tests of test_collections are broken. I fear that my changes
to regrtest.py have cause the problem but I don't understand why it's
broken. Can you have a look please?

--
assignee: gvanrossum
components: Tests
keywords: py3k
messages: 58088
nosy: gvanrossum, tiran
priority: normal
severity: normal
status: open
title: test_collections: failing refleak test
versions: Python 3.0

__
Tracker <[EMAIL PROTECTED]>

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



[issue1540] Refleak tests: test_doctest and test_gc are failing

2007-12-02 Thread Christian Heimes

New submission from Christian Heimes:

I've seen the problem on Windows only. test_doctest fails and the
problem also causes test_gc to fail when it is run after test_doctest.
W/o a prior run of test_doctest test_gc doesn't fail.

File "c:\dev\python\py3k\lib\test\test_doctest.py", line 1570, in
test.test_doct
est.test_debug
Failed example:
try: doctest.debug_src(s)
finally: sys.stdin = real_stdin
Expected:
> (1)()
(Pdb) next
12
--Return--
> (1)()->None
(Pdb) print(x)
12
(Pdb) continue
Got:
> c:\dev\python\py3k\lib\io.py(281)__del__()
-> try:
(Pdb) next
> c:\dev\python\py3k\lib\io.py(282)__del__()
-> self.close()
(Pdb) print(x)
*** NameError: NameError("name 'x' is not defined",)
(Pdb) continue
12
**
1 items had failures:
   1 of   4 in test.test_doctest.test_debug
***Test Failed*** 1 failures.
test test_doctest failed -- 1 of 418 doctests failed
test_gc
test test_gc failed -- Traceback (most recent call last):
  File "c:\dev\python\py3k\lib\test\test_gc.py", line 193, in test_saveall
self.assertEqual(gc.garbage, [])
AssertionError: [] != []

2 tests failed:
test_doctest test_gc

--
components: Tests, Windows
keywords: py3k
messages: 58089
nosy: tiran
priority: normal
severity: normal
status: open
title: Refleak tests: test_doctest and test_gc are failing
versions: Python 3.0

__
Tracker <[EMAIL PROTECTED]>

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



[issue1520] 'without make' documentation build anomaly

2007-12-02 Thread Tim Golden

Tim Golden added the comment:

Patch against sphinx r59269. Split on "/" and local os.sep. Causes
problems with sphinx-web under native Win32.

Added file: http://bugs.python.org/file8853/sphinx-r59269.patch

__
Tracker <[EMAIL PROTECTED]>

__

sphinx-r59269.patch
Description: Binary data
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1520] 'without make' documentation build anomaly

2007-12-02 Thread Tim Golden

Tim Golden added the comment:

I'm a little flummoxed. Patching relative_uri in the
sphinx/util/__init__.py to re.split on ("/" + os.sep) sorts out the
static generation. But it seems to introduce a couple of problems with
the web-server version of the docs. One is that links end up without a
category: http://localhost:3000/windows/ instead of
http://localhost:3000/using/windows/. The other is that, even if you put
the URLs in by hand, they don't work whereas /using%5cwindows *does*
work. Which suggests that the windows-y path is being stored somewhere
in the pickle files.

So now we're stretched two ways: the HTML needs /-delimited names to
work; the pickled files need \-delimited. I'm still looking at it, but
if anyone has more knowledge that I have (couldn't exactly have less)
then please feel free to chip in.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1520] 'without make' documentation build anomaly

2007-12-02 Thread Joseph Armbruster

Joseph Armbruster added the comment:

Tim,

Post up a patch of what you have up to now and I will look at it today.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1541] Bad OOB data management when using asyncore with select.poll()

2007-12-02 Thread billiejoex

New submission from billiejoex:

asyncore's module readwrite() function, used when invoking
asyncore.loop(use_poll=1), erroneously calls handle_read_event() when
receiving OOB (Out Of Band) data. handle_expt_event() should be called
instead.
The patch in attachment does that.


In addition I strongly think that POLLERR, POLLHUP and POLLNVAL events
handling is incorrect too.
As far as I read from here:
http://www.squarebox.co.uk/cgi-squarebox/manServer/usr/share/man/man0p/poll.h.0p
...they refers to the following events:

POLLERR An error has occurred (revents only).
POLLHUP Device has been disconnected ( revents only).
POLLNVALInvalid fd member (revents only).

They are actually associated to handle_expt_event() and this is
incorrect since it should be called only when receiving OOB data.

if flags & (select.POLLERR | select.POLLHUP | select.POLLNVAL):
obj.handle_expt_event()

I'm not sure what should be called instead, if handle_read_event or
handle_read or handle_error.

I tried to take a look at how Twisted manages the thing but it seems
that OOB is not even supported.
Maybe someone with more experience in using select.poll could clarify that.

--
components: Library (Lib)
files: asyncore.diff
messages: 58093
nosy: billiejoex
severity: normal
status: open
title: Bad OOB data management when using asyncore with select.poll()
type: behavior
versions: Python 2.5
Added file: http://bugs.python.org/file8854/asyncore.diff

__
Tracker <[EMAIL PROTECTED]>

__

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



[issue1542] Ship 32 and 64bit libs with MSI installer

2007-12-02 Thread Christian Heimes

New submission from Christian Heimes:

Hello Martin!

How do you like the idea to ship the 32bit and 64bit libs with the MSI
installer? The 64bit libs could be stored in libs64 while the 32bit libs
stay in libs.

I'm working on a task for the GHOP to add cross compiling support to
msvc9compiler. The extra libs are needed to compile 64bit libs on Win32
or the other way around.

Christian

--
assignee: loewis
components: Installation, Windows
messages: 58094
nosy: loewis, tiran
priority: low
severity: normal
status: open
title: Ship 32 and 64bit libs with MSI installer
versions: Python 2.6, Python 3.0

__
Tracker <[EMAIL PROTECTED]>

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



[issue1543] MSI installer needs to be updated to install x86 and x64 versions of Python on Vista 64 bit

2007-12-02 Thread Isaul Vargas

New submission from Isaul Vargas:

Problem:
I'd like to run Python 32 bit (for compatibility with extensions) and 
Python 64 bit on Vista (for speed and 64 bit apps) on one machine. 
However Vista has an 'improved' installer for MSI apps, where if I 
install Python 64 bit first, I can't install Python 32 bit afterwards, 
because Vista's Window Installer says 'Another version of this product 
is already installed. Installation of this version cannot continue. To 
configure or remove the existing version of this product, use 
Add/Remove Programs on the Control Panel'

The converse of this is true, if you install Python 64 bit first, you 
cannot install Python 32 bit afterwards.

The MSI packaging needs to be updated.

--
components: Installation, Windows
messages: 58095
nosy: Dude-X
severity: normal
status: open
title: MSI installer needs to be updated to install x86 and x64 versions of 
Python on Vista 64 bit
versions: Python 2.5, Python 2.6, Python 3.0

__
Tracker <[EMAIL PROTECTED]>

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



[issue1537] Change GeneratorExit's base class from Exception to BaseException

2007-12-02 Thread Chad Austin

Chad Austin added the comment:

The mailing list discussion continues...  in the meantime, I will 
update the patch with your suggestions.

Can you describe to me what should change in Doc/reference/
expressions.rst?  It makes sense to remove the section in the example 
that says you should never catch GeneratorExit.  Should I mention 
anything about why?

__
Tracker <[EMAIL PROTECTED]>

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



[issue1543] MSI installer needs to be updated to install x86 and x64 versions of Python on Vista 64 bit

2007-12-02 Thread Georg Brandl

Changes by Georg Brandl:


--
assignee:  -> loewis
nosy: +loewis

__
Tracker <[EMAIL PROTECTED]>

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



[issue1537] Change GeneratorExit's base class from Exception to BaseException

2007-12-02 Thread Chad Austin

Chad Austin added the comment:

New patch...

Added file: http://bugs.python.org/file8855/GeneratorExit-BaseException-2.patch

__
Tracker <[EMAIL PROTECTED]>

__

GeneratorExit-BaseException-2.patch
Description: Binary data
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1542] Ship 32 and 64bit libs with MSI installer

2007-12-02 Thread Martin v. Löwis

Martin v. Löwis added the comment:

I don't mind adding the libs, although I think inclusion of the libs
should be reconsidered, anyway. Why do we ship all of them, when you
only ever need pythonxy.lib?

If you are creating separate directories, please don't indicate the
"64-bit" ones as "libs64" or some such. They are processor-specific, and
neither "32-bit" nor "64-bit" is the name of a microprocessor. Instead,
the processor families are called "IA-32" (also x86, and Intel), "IA-64"
(also Itanium), "AMD64" (also x86-64, x64, EM64T, and Intel64).

__
Tracker <[EMAIL PROTECTED]>

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



[issue1487] PEP 366 implementation

2007-12-02 Thread Guido van Rossum

Guido van Rossum added the comment:

Great, now check it in!

On Dec 2, 2007 6:01 AM, Nick Coghlan <[EMAIL PROTECTED]> wrote:
>
> Nick Coghlan added the comment:
>
> Posted v2 of the patch, which fixes the problem Guido noted, and
> improved the tests to make sure __package__ is being set correctly.
> There's also now an explicit test for using -m on a module inside a
> package (which proved harder to write than I expected - it isn't easy to
> fiddle with sys.path when the subprocess is running python with the -E
> flag!).
>
> Added file: http://bugs.python.org/file8852/pep_366_v2.diff
>
>
> __
> Tracker <[EMAIL PROTECTED]>
> 
> __

__
Tracker <[EMAIL PROTECTED]>

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



[issue1543] MSI installer needs to be updated to install x86 and x64 versions of Python on Vista 64 bit

2007-12-02 Thread Martin v. Löwis

Martin v. Löwis added the comment:

It's not so clear that this is a bug. If you install both versions
simultaneously, they might stomp on each other's registry settings, at
least for the extensions. So this is rather a feature request.

Notice that the behaviour is not new to Vista. Ever since the early days
of MSI, two simultaneous installations of the same product were not
supported, and ever since Python started using MSI, it uses one product
ID per feature release.

In any case, this was fixed in r59112.

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

__
Tracker <[EMAIL PROTECTED]>

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



[issue1520] 'without make' documentation build anomaly

2007-12-02 Thread Tim Golden

Tim Golden added the comment:

OK, hacking away a bit further, I think I've found a solution, but I'll
need to tidy it up a bit. In essence, the problem is that the "filename"
is trying to be two things: the pointer for the local filesystem, and
the uri for the web server. On *nix, this will pretty much work. On
Windows -- and elsewhere, it won't.

My approach is to treat the filename a little like unicode: decode to
"web-format" on the way in; encode to "local-format" on the way out. In
practice, this resolves to a bunch of .replace(path.sep, "/") calls in
one place and .replace("/", path.sep) in the comparatively rare cases we
actually need to read the local filesystem.

I realise that, on Windows, I could get a bit hacky and just assume that
"/" will work throughout. But that obviously fails now for things like
VMS and in the future for the hypothetical filesystem which uses "." as
its separator etc.

I'm still working it through. The web and html versions are certainly
working but I need to check out htmlhelp which has its own special needs.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1245] Document PySys_* API functions

2007-12-02 Thread Georg Brandl

Georg Brandl added the comment:

Fixed as of r59281, thanks to GHOP student Charlie Shepherd.

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

__
Tracker <[EMAIL PROTECTED]>

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



[issue1719933] No docs for PyEval_EvalCode and related functions

2007-12-02 Thread Georg Brandl

Georg Brandl added the comment:

Fixed as of r59262.

--
nosy: +georg.brandl
resolution:  -> fixed
status: open -> closed

_
Tracker <[EMAIL PROTECTED]>

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



[issue1520] 'without make' documentation build anomaly

2007-12-02 Thread Georg Brandl

Georg Brandl added the comment:

Really great that you're doing this! Many thanks!

(Yes, I must admit that I was sloppy there...)

__
Tracker <[EMAIL PROTECTED]>

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



[issue1520] 'without make' documentation build anomaly

2007-12-02 Thread Joseph Armbruster

Joseph Armbruster added the comment:

Tim,

Appears you are on your way to a fix.  If you need it tested on an
alternate windows machine, post up and i'll run through it.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1283] PyBytes (buffer) .extend method needs to accept any iterable of ints

2007-12-02 Thread Alexandre Vassalotti

Alexandre Vassalotti added the comment:

Here yet another revision of the patch. This one makes
bytearray.extend()   try to determine the length of its argument a bit
more aggressively -- i.e., also uses PyObject_Length().

Added file: http://bugs.python.org/file8856/byte_extend-4.patch

__
Tracker <[EMAIL PROTECTED]>

__Index: Objects/bytesobject.c
===
--- Objects/bytesobject.c	(revision 59259)
+++ Objects/bytesobject.c	(working copy)
@@ -2487,24 +2487,6 @@
 return NULL;
 }
 
-PyDoc_STRVAR(extend__doc__,
-"B.extend(iterable int) -> None\n\
-\n\
-Append all the elements from the iterator or sequence to the\n\
-end of B.");
-static PyObject *
-bytes_extend(PyBytesObject *self, PyObject *arg)
-{
-/* XXX(gps): The docstring says any iterable int will do but the
- * bytes_setslice code only accepts something supporting PEP 3118.
- * A list or tuple of 0 <= int <= 255 is supposed to work.  */
-/* bug being tracked on:  http://bugs.python.org/issue1283  */
-if (bytes_setslice(self, Py_Size(self), Py_Size(self), arg) == -1)
-return NULL;
-Py_RETURN_NONE;
-}
-
-
 PyDoc_STRVAR(reverse__doc__,
 "B.reverse() -> None\n\
 \n\
@@ -2591,6 +2573,70 @@
 Py_RETURN_NONE;
 }
 
+PyDoc_STRVAR(extend__doc__,
+"B.extend(iterable int) -> None\n\
+\n\
+Append all the elements from the iterator or sequence to the\n\
+end of B.");
+static PyObject *
+bytes_extend(PyBytesObject *self, PyObject *arg)
+{
+PyObject *it, *item, *tmp, *res;
+Py_ssize_t buf_size = 0, len = 0;
+int value;
+char *buf;
+
+/* bytes_setslice code only accepts something supporting PEP 3118. */
+if (PyObject_CheckBuffer(arg)) {
+if (bytes_setslice(self, Py_Size(self), Py_Size(self), arg) == -1)
+return NULL;
+
+Py_RETURN_NONE;
+}
+
+it = PyObject_GetIter(arg);
+if (it == NULL)
+return NULL;
+
+/* Try to determine the length of the argument. */
+buf_size = PyObject_Length(arg);
+if (buf_size < 0)
+buf_size = _PyObject_LengthHint(arg);
+if (buf_size < 0) {
+/* The length of the argument is unknown. */
+PyErr_Clear();
+buf_size = 32;
+}
+
+buf = (char *)PyMem_Malloc(buf_size * sizeof(char));
+if (buf == NULL)
+return PyErr_NoMemory();
+
+while ((item = PyIter_Next(it)) != NULL) {
+if (! _getbytevalue(item, &value)) {
+Py_DECREF(item);
+Py_DECREF(it);
+return NULL;
+}
+buf[len++] = value;
+Py_DECREF(item);
+if (len >= buf_size) {
+buf_size = len + (len >> 1) + 1;
+buf = (char *)PyMem_Realloc(buf, buf_size * sizeof(char));
+if (buf == NULL)
+return PyErr_NoMemory();
+}
+}
+Py_DECREF(it);
+
+tmp = PyBytes_FromStringAndSize(buf, len);
+res = bytes_extend(self, tmp);
+Py_DECREF(tmp);
+PyMem_Free(buf);
+
+return res;
+}
+
 PyDoc_STRVAR(pop__doc__,
 "B.pop([index]) -> int\n\
 \n\
Index: Lib/test/test_bytes.py
===
--- Lib/test/test_bytes.py	(revision 59259)
+++ Lib/test/test_bytes.py	(working copy)
@@ -529,6 +529,21 @@
 a.extend(a)
 self.assertEqual(a, orig + orig)
 self.assertEqual(a[5:], orig)
+a = bytearray(b'')
+a.extend(map(int, orig * 50))
+self.assertEqual(a, orig * 50)
+self.assertEqual(a[-5:], orig)
+a = bytearray(b'')
+a.extend(iter(map(int, orig * 50)))
+self.assertEqual(a, orig * 50)
+self.assertEqual(a[-5:], orig)
+a = bytearray(b'')
+a.extend(list(map(int, orig * 50)))
+self.assertEqual(a, orig * 50)
+self.assertEqual(a[-5:], orig)
+a = bytearray(b'')
+self.assertRaises(ValueError, a.extend, [0, 1, 2, 3, 256])
+self.assertEqual(len(a), 0)
 
 def test_remove(self):
 b = bytearray(b'hello')
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1283] PyBytes (buffer) .extend method needs to accept any iterable of ints

2007-12-02 Thread Gregory P. Smith

Gregory P. Smith added the comment:

"There is still another possible leak if the PyMem_Realloc
return NULL (i.e., the system is out of memory), but I don't think it
worth fixing."

Do it.  It looks easy: a Py_DECREF(it) before the return PyErr_NoMemory().

__
Tracker <[EMAIL PROTECTED]>

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



[issue1283] PyBytes (buffer) .extend method needs to accept any iterable of ints

2007-12-02 Thread Alexandre Vassalotti

Alexandre Vassalotti added the comment:

Done. Is there any other issue with the patch?

Added file: http://bugs.python.org/file8857/byte_extend-5.patch

__
Tracker <[EMAIL PROTECTED]>

__Index: Objects/bytesobject.c
===
--- Objects/bytesobject.c	(revision 59259)
+++ Objects/bytesobject.c	(working copy)
@@ -2487,24 +2487,6 @@
 return NULL;
 }
 
-PyDoc_STRVAR(extend__doc__,
-"B.extend(iterable int) -> None\n\
-\n\
-Append all the elements from the iterator or sequence to the\n\
-end of B.");
-static PyObject *
-bytes_extend(PyBytesObject *self, PyObject *arg)
-{
-/* XXX(gps): The docstring says any iterable int will do but the
- * bytes_setslice code only accepts something supporting PEP 3118.
- * A list or tuple of 0 <= int <= 255 is supposed to work.  */
-/* bug being tracked on:  http://bugs.python.org/issue1283  */
-if (bytes_setslice(self, Py_Size(self), Py_Size(self), arg) == -1)
-return NULL;
-Py_RETURN_NONE;
-}
-
-
 PyDoc_STRVAR(reverse__doc__,
 "B.reverse() -> None\n\
 \n\
@@ -2591,6 +2573,72 @@
 Py_RETURN_NONE;
 }
 
+PyDoc_STRVAR(extend__doc__,
+"B.extend(iterable int) -> None\n\
+\n\
+Append all the elements from the iterator or sequence to the\n\
+end of B.");
+static PyObject *
+bytes_extend(PyBytesObject *self, PyObject *arg)
+{
+PyObject *it, *item, *tmp, *res;
+Py_ssize_t buf_size = 0, len = 0;
+int value;
+char *buf;
+
+/* bytes_setslice code only accepts something supporting PEP 3118. */
+if (PyObject_CheckBuffer(arg)) {
+if (bytes_setslice(self, Py_Size(self), Py_Size(self), arg) == -1)
+return NULL;
+
+Py_RETURN_NONE;
+}
+
+it = PyObject_GetIter(arg);
+if (it == NULL)
+return NULL;
+
+/* Try to determine the length of the argument. */
+buf_size = PyObject_Length(arg);
+if (buf_size < 0)
+buf_size = _PyObject_LengthHint(arg);
+if (buf_size < 0) {
+/* The length of the argument is unknown. */
+PyErr_Clear();
+buf_size = 32;
+}
+
+buf = (char *)PyMem_Malloc(buf_size * sizeof(char));
+if (buf == NULL)
+return PyErr_NoMemory();
+
+while ((item = PyIter_Next(it)) != NULL) {
+if (! _getbytevalue(item, &value)) {
+Py_DECREF(item);
+Py_DECREF(it);
+return NULL;
+}
+buf[len++] = value;
+Py_DECREF(item);
+if (len >= buf_size) {
+buf_size = len + (len >> 1) + 1;
+buf = (char *)PyMem_Realloc(buf, buf_size * sizeof(char));
+if (buf == NULL) {
+Py_DECREF(it);
+return PyErr_NoMemory();
+}
+}
+}
+Py_DECREF(it);
+
+tmp = PyBytes_FromStringAndSize(buf, len);
+res = bytes_extend(self, tmp);
+Py_DECREF(tmp);
+PyMem_Free(buf);
+
+return res;
+}
+
 PyDoc_STRVAR(pop__doc__,
 "B.pop([index]) -> int\n\
 \n\
Index: Lib/test/test_bytes.py
===
--- Lib/test/test_bytes.py	(revision 59259)
+++ Lib/test/test_bytes.py	(working copy)
@@ -529,6 +529,21 @@
 a.extend(a)
 self.assertEqual(a, orig + orig)
 self.assertEqual(a[5:], orig)
+a = bytearray(b'')
+a.extend(map(int, orig * 50))
+self.assertEqual(a, orig * 50)
+self.assertEqual(a[-5:], orig)
+a = bytearray(b'')
+a.extend(iter(map(int, orig * 50)))
+self.assertEqual(a, orig * 50)
+self.assertEqual(a[-5:], orig)
+a = bytearray(b'')
+a.extend(list(map(int, orig * 50)))
+self.assertEqual(a, orig * 50)
+self.assertEqual(a[-5:], orig)
+a = bytearray(b'')
+self.assertRaises(ValueError, a.extend, [0, 1, 2, 3, 256])
+self.assertEqual(len(a), 0)
 
 def test_remove(self):
 b = bytearray(b'hello')
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1283] PyBytes (buffer) .extend method needs to accept any iterable of ints

2007-12-02 Thread Gregory P. Smith

Gregory P. Smith added the comment:

reading 5.patch over...

Any particular reason for using buf_size = 32 when the length isn't
known up front?  add a comment saying why (or that its just a magic
guess).  anyways it sounds like a fine starting value.  picking
anything "better" would require profiling.

perhaps use a list comprehension instead of map() in the unit test?
either works, its a style thing.

  (int(x) for x in orig*50)[int(x) for x in orig*50]

also the uses of 5 and -5 in that test could be written using
len(orig) instead of 5.

add another assertRaises that tests to make sure a list with -1 in it
raises a ValueError.

While I dislike that this code makes a temporary copy of the data
first, doing otherwise is more complicated so the simplicity of this
one wins.  Leave that optimization for later.  Your code looks good.

-gps

On 12/2/07, Alexandre Vassalotti <[EMAIL PROTECTED]> wrote:
>
> Alexandre Vassalotti added the comment:
>
> Done. Is there any other issue with the patch?
>
> Added file: http://bugs.python.org/file8857/byte_extend-5.patch
>
> __
> Tracker <[EMAIL PROTECTED]>
> 
> __
>

__
Tracker <[EMAIL PROTECTED]>

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



[issue1544] IDLE installation problems and no message errors

2007-12-02 Thread Daniela

New submission from Daniela:

Installed Python 2.5.1 on windows. Menu is set as it was supposed to,all
the options appear, the command line works perfectly, the IDLE doesn't -
I click on it in the menu and it seems it will start run and then...
nothing. No window pops up, not even a flash, no message errors,
nothing... I've reinstalled many times, 
tried to recover installation, no lucky.

Do any body had the same problem?

--
components: Installation
messages: 58111
nosy: danicyber
severity: urgent
status: open
title: IDLE installation problems and no message errors
versions: Python 2.5

__
Tracker <[EMAIL PROTECTED]>

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



[issue1545] shutil fails when copying to NTFS in Linux

2007-12-02 Thread ianaré

New submission from ianaré:

When using shutil.copy2 or copytree where the source is on a filesystem
that has octal permissions (ie ext3) and the destination is on an NTFS
partition mounted rw, the operation fails with

OSError: [Errno 1] Operation not permitted


I am attaching a version of shutil.py where this has been worked around
by calling copystat like so:

try:
copystat(src, dst)
except OSError, (n, str):
# can't change stats on NTFS partition even if
# OS supports it
if n == 1:
pass
else:
raise Error, str

--
components: Library (Lib)
files: shutil1.py
messages: 58112
nosy: ianare
severity: normal
status: open
title: shutil fails when copying to NTFS in Linux
versions: Python 2.5
Added file: http://bugs.python.org/file8859/shutil1.py

__
Tracker <[EMAIL PROTECTED]>

__"""Utility functions for copying files and directory trees.

XXX The functions here don't copy the resource fork or other metadata on Mac.

"""

import os
import sys
import stat
import os.path
from os.path import abspath

__all__ = ["copyfileobj","copyfile","copymode","copystat","copy","copy2",
   "copytree","move","rmtree","Error"]

class Error(EnvironmentError):
pass

def copyfileobj(fsrc, fdst, length=16*1024):
"""copy data from file-like object fsrc to file-like object fdst"""
while 1:
buf = fsrc.read(length)
if not buf:
break
fdst.write(buf)

def _samefile(src, dst):
# Macintosh, Unix.
if hasattr(os.path,'samefile'):
try:
return os.path.samefile(src, dst)
except OSError:
return False

# All other platforms: check for same pathname.
return (os.path.normcase(os.path.abspath(src)) ==
os.path.normcase(os.path.abspath(dst)))

def copyfile(src, dst):
"""Copy data from src to dst"""
if _samefile(src, dst):
raise Error, "`%s` and `%s` are the same file" % (src, dst)

fsrc = None
fdst = None
try:
fsrc = open(src, 'rb')
fdst = open(dst, 'wb')
copyfileobj(fsrc, fdst)
finally:
if fdst:
fdst.close()
if fsrc:
fsrc.close()

def copymode(src, dst):
"""Copy mode bits from src to dst"""
if hasattr(os, 'chmod'):
st = os.stat(src)
mode = stat.S_IMODE(st.st_mode)
os.chmod(dst, mode)

def copystat(src, dst):
"""Copy all stat info (mode bits, atime and mtime) from src to dst"""
st = os.stat(src)
mode = stat.S_IMODE(st.st_mode)
if hasattr(os, 'utime'):
os.utime(dst, (st.st_atime, st.st_mtime))
if hasattr(os, 'chmod'):
os.chmod(dst, mode)


def copy(src, dst):
"""Copy data and mode bits ("cp src dst").

The destination may be a directory.

"""
if os.path.isdir(dst):
dst = os.path.join(dst, os.path.basename(src))
copyfile(src, dst)
copymode(src, dst)

def copy2(src, dst):
"""Copy data and all stat info ("cp -p src dst").

The destination may be a directory.

"""
if os.path.isdir(dst):
dst = os.path.join(dst, os.path.basename(src))
copyfile(src, dst)
try:
copystat(src, dst)
except OSError, (n, str):
# can't change stats on ntfs partition even if
# OS supports it
if n == 1:
pass
else:
raise Error, str


def copytree(src, dst, symlinks=False):
"""Recursively copy a directory tree using copy2().

The destination directory must not already exist.
If exception(s) occur, an Error is raised with a list of reasons.

If the optional symlinks flag is true, symbolic links in the
source tree result in symbolic links in the destination tree; if
it is false, the contents of the files pointed to by symbolic
links are copied.

XXX Consider this example code rather than the ultimate tool.

"""
names = os.listdir(src)
os.makedirs(dst)
errors = []
for name in names:
srcname = os.path.join(src, name)
dstname = os.path.join(dst, name)
try:
if symlinks and os.path.islink(srcname):
linkto = os.readlink(srcname)
os.symlink(linkto, dstname)
elif os.path.isdir(srcname):
copytree(srcname, dstname, symlinks)
else:
copy2(srcname, dstname)
# XXX What about devices, sockets etc.?
except (IOError, os.error), why:
errors.append((srcname, dstname, str(why)))
# catch the Error from the recursive copytree so that we can
# continue with other files
except Error, err:
errors.extend(err.args[0])
try:
copystat(src, dst)
except OSError, (n, str):
# can't change stats on ntfs partition even if
# OS supports it
if n == 1:
pass
else:
er