[issue1035] bytes buffer API needs to support read locking and/or PyBUF_LOCKDATA

2007-09-11 Thread Gregory P. Smith

Gregory P. Smith added the comment:

Attaching the most recent patch (minor update from the second one i sent
to the python-3000 mailing list to initialize ob_readonly_exports = 0 in
the appropriate places).

Current mailing list discussion is pointing out that the name LOCKDATA
means something other than what the existing pep3118 description implies
and that we may want to modify the pep to support more obviously named
things such as READ_LOCK, and EXCLUSIVE or similar...  here's a link to
the current thread:

http://mail.python.org/pipermail/python-3000/2007-September/010325.html

--
keywords: +patch
title: bytes buffer API needs to support PyBUF_LOCKDATA -> bytes buffer API 
needs to support read locking and/or PyBUF_LOCKDATA

__
Tracker <[EMAIL PROTECTED]>

__Index: Include/bytesobject.h
===
--- Include/bytesobject.h   (revision 58109)
+++ Include/bytesobject.h   (working copy)
@@ -18,15 +18,16 @@
  * to contain a char pointer, not an unsigned char pointer.
  */
 
 /* Object layout */
 typedef struct {
 PyObject_VAR_HEAD
 /* XXX(nnorwitz): should ob_exports be Py_ssize_t? */
-int ob_exports; /* how many buffer exports */
+int ob_exports; /* How many buffer exports */
+int ob_readonly_exports; /* How many buffer exports as readonly */
 Py_ssize_t ob_alloc; /* How many bytes allocated */
 char *ob_bytes;
 } PyBytesObject;
 
 /* Type object */
 PyAPI_DATA(PyTypeObject) PyBytes_Type;
 
Index: Objects/bytesobject.c
===
--- Objects/bytesobject.c   (revision 58109)
+++ Objects/bytesobject.c   (working copy)
@@ -2,14 +2,114 @@
 
 /* XXX TO DO: optimizations */
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
 #include "structmember.h"
 
+/*
+ * Constants for use with the PyBytesObject.ob_readonly_exports.
+ * XXX(gps) rename these and move them to the header file.
+ */
+#define MAX_READONLY_EXPORTS(INT_MAX)
+#define MAX_EXPORTS (INT_MAX)
+
+/* 
+ * Should we bounds check PyBytesObject.ob_exports and
+ * ob_readonly_exports when we increment them?
+ */
+#if MAX_READONLY_EXPORTS <= USHRT_MAX
+#define BOUNDS_CHECK_EXPORTS 1
+#else
+#undef BOUNDS_CHECK_EXPORTS
+#endif
+
+/*
+ * TODO(gps) Do we want to provide an exported interface for any of 
+ * these inlines for use by C code that uses Bytes objects directly
+ * rather than the buffer API?  I suggest C code should prefer to use
+ * the buffer API (though it is heavier weight).  Exporting is_readonly()
+ * might be useful?
+ */
+
+/*
+ * Is this bytes object currently read only?  0: no, 1: yes
+ */
+Py_LOCAL_INLINE(int) is_readonly(PyBytesObject *obj)
+{
+assert(obj->ob_readonly_exports <= obj->ob_exports);
+return (obj->ob_readonly_exports > 0 && obj->ob_exports == 0);
+}
+
+/*
+ * Increment the export count.  For use by getbuffer.
+ *
+ * Returns: 0 on success, -1 on failure with an exception set.
+ * (-1 matches the required buffer API getbuffer return value)
+ */
+Py_LOCAL_INLINE(int) inc_exports(PyBytesObject *obj)
+{
+#ifdef BOUNDS_CHECK_EXPORTS
+if (MAX_EXPORTS <= obj->ob_exports) {
+/* XXX(gps): include object id in the error? */
+PyErr_SetString(PyExc_RuntimeError,
+"ob_exports overflow");
+return -1;
+}
+#endif
+obj->ob_exports++;
+return 0;
+}
+
+/*
+ * Decrement the export count.  For use by releasebuffer.
+ */
+Py_LOCAL_INLINE(void) dec_exports(PyBytesObject *obj)
+{
+obj->ob_exports--;
+}
+
+
+/*
+ * Increment the readonly export count if the object is mutable.
+ * Must be called with the GIL held.
+ *
+ * For use by the buffer API to implement PyBUF_LOCKDATA requests.
+ *
+ * Returns: 0 on success, -1 on failure with an exception set.
+ * (-1 matches the required buffer API getbuffer return value)
+ */
+Py_LOCAL_INLINE(int) inc_readonly_exports(PyBytesObject *obj)
+{
+#ifdef BOUNDS_CHECK_EXPORTS
+if (MAX_READONLY_EXPORTS <= obj->ob_readonly_exports) {
+/* XXX(gps): include object id in the error? */
+PyErr_SetString(PyExc_RuntimeError,
+"ob_readonly_exports overflow");
+return 1;
+}
+#endif
+obj->ob_readonly_exports++;
+return 0;
+}
+
+
+/*
+ * Decrement the readonly export count.
+ * Must be called with the GIL held.
+ *
+ * For use by the buffer API to implement PyBUF_LOCKDATA requests.
+ */
+Py_LOCAL_INLINE(void) dec_readonly_exports(PyBytesObject *obj)
+{
+assert(obj->ob_readonly_exports <= obj->ob_exports);
+obj->ob_readonly_exports--;
+}
+
+
 /* The nullbytes are used by the stringlib during partition.
  * If partition is removed from bytes, nullbytes and its helper
  * Init/Fini should also be removed.
  */
 static PyBytesObject *nullbytes = NULL;
 
 void
@@ -23,14 +123,15 @@
 {
 nullbytes = PyObject_New(PyBytesObject,

[issue1152] Bug in documentation for SimpleXMLRPCServer

2007-09-11 Thread Georg Brandl

Changes by Georg Brandl:


--
assignee:  -> georg.brandl
nosy: +georg.brandl

__
Tracker <[EMAIL PROTECTED]>

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



[issue1142] code sample showing errors reading large files with py 2.5/3.0

2007-09-11 Thread christen

christen added the comment:

Bug is still there but pb is solved, simply use oepn('file', 'U')
see outputs :

fichin=open('test.txt','U')
===>
(2, 5, 0, 'final', 0)
2007-09-12 08:00:43
(500, 9.31236239624)
(1000, 22.31236239624)
(1500, 35.094000101089478)
(2000, 47.81236239624)
(2500, 60.56236239624)
(3000, 73.265000104904175)
(3500, 85.95368664551)
(4000, 98.672000169754028)
(4500, 111.35900020599365)
(5000, 123.98400020599365)
(5500, 136.625)
(6000, 149.26500010490417)
(6500, 161.9060001373291)
(7000, 174.625)
(7500, 187.29700016975403)
(8000, 199.8910490417)
(8500, 212.5310001373291)
('total lines read ', 85014960)
212.56236

now with
fichin=open('test.txt')
or
fichin=open('test.txt','r')
===>

(2, 5, 0, 'final', 0)
2007-09-12 08:04:48
(500, 3.18763760376)
(1000, 6.3440001010894775)
(1500, 9.4690001010894775)
(2000, 12.594000101089478)
(2500, 15.719000101089478)
(3000, 18.844000101089478)
(3500, 21.969000101089478)
(4000, 25.094000101089478)
(4500, 28.219000101089478)
(5000, 31.344000101089478)
(5500, 34.469000101089478)
(6000, 37.594000101089478)
* 62410138   
62410139 *
* 62414887   
62414888 *
* 62415540   
62415541 *
* 62420289   
62420290 *
* 62420942   
62420943 *
* 62421595   
62421596 *
* 62422248   
62422249 *
* 62422901   
62422902 *
* 62427650   
62427651 *
* 62428303   
62428304 *
(6500, 40.75)
(7000, 43.95368664551)
(7500, 47.125)
(8000, 50.32868664551)
(8500, 53.51632424927)
('total lines read ', 85014950)
53.516324

best
Richard

__
Tracker <[EMAIL PROTECTED]>

__begin:vcard
fn:Richard Christen
n:Christen;Richard
org;quoted-printable:CNRS UMR 6543  & Universit=C3=A9 de Nice;Laboratoire de Biologie Virtuelle
adr:Parc Valrose;;Centre de Biochimie;Nice;;06108;France
email;internet:[EMAIL PROTECTED]
title;quoted-printable:Champion de saut en =C3=A9paisseur
tel;work:33- 492 076 947
url:http://bioinfo.unice.fr
version:2.1
end:vcard

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



[issue1152] Bug in documentation for SimpleXMLRPCServer

2007-09-11 Thread Frank Millman

New submission from Frank Millman:

I spotted a minor bug in the documentation to SimpleXMLRPCServer.

Background: 
xmlrpclib.py has the following - 

# This class is available as ServerProxy and Server.  New code 
should 
# use ServerProxy, to avoid confusion. 
# 
... 
class ServerProxy: 
... 
Server = ServerProxy 

The bug: 
Section 18.25.1 SimpleXMLRPCServer Objects 
... 
Example: 
... 
The following client code will call the methods made available by 
the preceding server: 
import xmlrpclib 
s = xmlrpclib.Server('http://localhost:8000') 

It should say: 
s = xmlrpclib.ServerProxy('http://localhost:8000')

--
components: Documentation
messages: 55836
nosy: FrankMillman
severity: normal
status: open
title: Bug in documentation for SimpleXMLRPCServer
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



[issue1147] string exceptions inconsistently deprecated/disabled

2007-09-11 Thread Brett Cannon

Brett Cannon added the comment:

Rev. 58109 covers 2.5.

--
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



[issue1147] string exceptions inconsistently deprecated/disabled

2007-09-11 Thread Brett Cannon

Brett Cannon added the comment:

Fixed on the trunk in rev. 58108.  Need to change 2.5 to raise a warning.

--
priority:  -> normal
versions:  -Python 2.6

__
Tracker <[EMAIL PROTECTED]>

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



[issue1147] string exceptions inconsistently deprecated/disabled

2007-09-11 Thread Brett Cannon

Changes by Brett Cannon:


--
assignee:  -> brett.cannon
nosy: +brett.cannon

__
Tracker <[EMAIL PROTECTED]>

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



[issue1151] "TypeError: expected string, bytes found" instead of KeyboardInterrupt

2007-09-11 Thread Eduardo Padoan

New submission from Eduardo Padoan:

On revision 54803, interactive mode, on linux: if type ctrl+c you type
ctrl+c, it should raise KeyboardInterrupt, but "TypeError: expected
string, bytes found" printed. Also, I could *not* catch it doing:

>>> try:
... while True: pass
... except KeyboardInterrupt:
... print('Ok')
... except TypeError:
... print('Ops')
Ok

To reproduce:
>>> # press ctrl+c...
TypeError: expected string, bytes found
>>> 

It seems that it is simply printing the wrong error...

--
components: Interpreter Core
messages: 55833
nosy: eopadoan
severity: normal
status: open
title: "TypeError: expected string, bytes found" instead of KeyboardInterrupt
type: behavior
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



[issue1130] Idle - Save (buffer) - closes IDLE and does not save file (Windows XP)

2007-09-11 Thread Kurt B. Kaiser

Changes by Kurt B. Kaiser:


--
assignee:  -> kbk
keywords: +py3k
nosy: +kbk

__
Tracker <[EMAIL PROTECTED]>

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



[issue1141] reading large files

2007-09-11 Thread Ben Beasley

Ben Beasley added the comment:

See the BDFL's comment in msg55828. "I know Py3k text I/O is very slow;
it's written in Python and uses UTF-8
as the default encoding.  We've got a summer of code student working on
an accelerating this.  (And if he doesn't finish we have another year to
work on it before 3.0final is released.)"

__
Tracker <[EMAIL PROTECTED]>

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



[issue1141] reading large files

2007-09-11 Thread Ben Beasley

Ben Beasley added the comment:

I ran Richard Christen's script from msg55784 on Ubuntu Feisty Fawn
(64-bit) with both Python 2.5.1 and Python 3.0a1 (for the latter, I had
to change xrange to range).

(2, 5, 1, 'final', 0)
2007-09-11 11:39:08
(500, 7.3925600051879883)
(1000, 15.068881034851074)
(1500, 22.870260953903198)
(2000, 30.588511943817139)
(2500, 37.977153062820435)
(3000, 45.393024921417236)
(3500, 57.039968013763428)
(4000, 71.122976064682007)
(4500, 85.065402984619141)
(5000, 97.03105092048645)
(5500, 108.22125887870789)
(6000, 122.95617389678955)
(6500, 130.45936799049377)
(7000, 141.0406129360199)
(7500, 150.5293460083)
(8000, 158.0419979095459)
(8500, 168.4651789665)
('total lines written ', 85014960)
(85014960, 168.48725986480713)
**
(500, 11.699964046478271)
(1000, 18.510161876678467)
(1500, 27.110308885574341)
(2000, 35.410284996032715)
(2500, 41.88045597076416)
(3000, 48.734965085983276)
(3500, 56.416620016098022)
(4000, 65.14509105682373)
(4500, 73.711935043334961)
(5000, 82.278150081634521)
(5500, 90.984658002853394)
(6000, 99.987648963928223)
(6500, 104.64127588272095)
(7000, 109.73277306556702)
(7500, 114.78491401672363)
(8000, 120.38562488555908)
(8500, 126.08317303657532)
('total lines read ', 85014960)
294.583214998




(3, 0, 0, 'alpha', 1)
2007-09-11 12:20:53
500 117.375117064
1000 238.183109045
1500 357.397506952
2000 476.816791058
2500 597.198447943
3000 717.393661976
3500 837.278333902
4000 956.919227839
4500 1077.25333095
5000 1196.60731292
5500 1316.08601999
6000 1434.81360602
6500 1554.1584239
7000 1673.04580498
7500 1792.35387397
8000 1912.65659904
8500 2032.99598598
total lines written  85014960
85014960 2033.35042787
**
500 89.7920100689
1000 180.910079002
1500 272.628970146
2000 364.904497147
2500 457.229861021
3000 549.14190793
3500 641.054435968
4000 733.30577898
4500 826.058191061
5000 917.997677088
5500 1010.20616603
6000 1102.142905
6500 1194.16728902
7000 1286.54789495
7500 1378.50006604
8000 1470.37746692
8500 1562.25738001
total lines read  85014960
3595.88338494

--
nosy: +music

__
Tracker <[EMAIL PROTECTED]>

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



[issue1150] Rename PyBUF_WRITEABLE to PyBUF_WRITABLE

2007-09-11 Thread Guido van Rossum

New submission from Guido van Rossum:

Because writeable is not an English word; writable is.

Other names should be fixed as well.

--
messages: 55830
nosy: gvanrossum
severity: normal
status: open
title: Rename PyBUF_WRITEABLE to PyBUF_WRITABLE
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



[issue1149] fdopen does not work as expected

2007-09-11 Thread Luís Pedro Coelho

New submission from Luís Pedro Coelho:

from os import *

def Fork():
b = fork()
if b < 0:
raise Exception('fork() failed')
return b


r,w=pipe()
b = Fork()
if b == 0:
   dup2(w,1)
   close(w)
   execlp('echo',\
   'echo',\
'Hello world')
else:
   for line in fdopen(r):
   print 'Read %s' % line

I was expecting this code to print "Read Hello World". Instead, it 
hangs forever.

Changing "for line in fdopen(r): print 'Read %s' % line" 
to "line=read(r,100); print 'Read %s' % line" makes the program work 
as expected. This is what I did on my actual production code, but it 
seems funny behaviour on the part of fdopen.

I am running on Ubuntu on PowerPC.

--
components: Library (Lib)
messages: 55829
nosy: [EMAIL PROTECTED]
severity: normal
status: open
title: fdopen does not work as expected
type: behavior
versions: Python 2.3, Python 2.4, 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



[issue1142] code sample showing errors reading large files with py 2.5/3.0

2007-09-11 Thread Guido van Rossum

Guido van Rossum added the comment:

Folks, please focus on one issue at a time, and don't post such long
transcripts.

I know Py3k text I/O is very slow; it's written in Python and uses UTF-8
as the default encoding.  We've got a summer of code student working on
an accelerating this.  (And if he doesn't finish we have another year to
work on it before 3.0final is released.)

So the real problem is that on Windows in 2.x reading files > 4 GB loses
data.  Please try to see if opening the file in binary mode still loses
data.  I suspect a problem in the Windows C stdio library related to
line endings, but who knows.

--
components:  -Interpreter Core
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



[issue1148] TypeError on join - httplib mixing str and bytes

2007-09-11 Thread Eduardo Padoan

New submission from Eduardo Padoan:

To reproduce:

>>> import httplib
>>> conn = httplib.HTTPConnection("www.python.org")
>>> conn.request("GET", "/index.html")
>>> r1 = conn.getresponse()
>>> r1.read()
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/eopadoan/pub/py3k/Lib/httplib.py", line 540, in read
s = self._safe_read(self.length)
  File "/home/eopadoan/pub/py3k/Lib/httplib.py", line 627, in _safe_read
return "".join(s)
TypeError: sequence item 0: expected string or Unicode, bytes found

Also, shouldn't the message  be like "...expected str, bytes found"?

--
components: Library (Lib)
messages: 55827
nosy: eopadoan
severity: normal
status: open
title: TypeError on join - httplib mixing str and bytes
type: crash
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



[issue1739468] Add a -z interpreter flag to execute a zip file

2007-09-11 Thread Paul Moore

Paul Moore added the comment:

PJE's patch looks OK. I agree with Nick that the chain of &&s in 
PyImport_GetImporter should be expanded into a chain of ifs. As it 
stands, the code is needlessly obfuscated.

_
Tracker <[EMAIL PROTECTED]>

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



[issue1147] string exceptions inconsistently deprecated/disabled

2007-09-11 Thread Jean-Paul Calderone

New submission from Jean-Paul Calderone:

Python 2.5 deprecated raising string exceptions.  It also added the
throw method to generator objects which can be used to raise an
exception, including a string exception.  Raising an exception with this
method doesn't issue a deprecation warning.

It looks like Python 2.6 will remove string exceptions entirely. 
Current trunk still allows strings to be passed to the throw method of
generators though, and raises the string exception, again without a
deprecation warning.

--
components: Interpreter Core
messages: 55825
nosy: exarkun
severity: normal
status: open
title: string exceptions inconsistently deprecated/disabled
type: behavior
versions: Python 2.5, Python 2.6

__
Tracker <[EMAIL PROTECTED]>

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



[issue1739468] Add a -z interpreter flag to execute a zip file

2007-09-11 Thread Nick Coghlan

Nick Coghlan added the comment:

I like PJE's approach, and the patch works for me.

About the only thing I'd change is to switch the expression in
PyImport_GetImporter to a simple chain of if-statements in order to:
  - silence the warning from GCC about an unused value
  - make it more obvious to a reader what the function is doing

An optimising compiler is going to produce similar code either way, and
it took me a moment to realise that the && operations are being used
purely for their short-circuiting effect, even though there is no real
advantage to using an expression instead of a statement at that point in
the code.

Adding a simple test of the functionality to test_cmd_line would also be
good.

_
Tracker <[EMAIL PROTECTED]>

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



[issue1056] test_cmd_line starts python without -E

2007-09-11 Thread Nick Coghlan

Nick Coghlan added the comment:

Fixed for 2.6 in rev 58103

(Is the head still being merged to the py3k branch? Or does this need to
be forward-ported manually?)

--
nosy: +ncoghlan
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



[issue1146] TextWrap vs words 1-character shorter than the width

2007-09-11 Thread sam

New submission from sam:

>>> from textwrap import wrap
>>> wrap("foobarbaz reallylongwordgoeshere", width = 10)
['foobarbaz r', 'eallylongw', 'ordgoesher', 'e']
>>> print [len(s) for s in _]
[11, 10, 10, 1]

This only seems to happen when the first word on the line is exactly one
character shorter than the width, and the next word is too long to fit,
so it is broken:

>>> wrap("foo bar reallylongwordgoeshere", width = 7)
['foo bar', 'reallyl', 'ongword', 'goesher', 'e']
>>> wrap("foobarbaz really longwordgoeshere", width = 10)
['foobarbaz', 'really lon', 'gwordgoesh', 'ere']
>>> wrap("foobarbaz reallylongwordgoeshere", width = 10,
break_long_words = False)
['foobarbaz', 'reallylongwordgoeshere']

This is on Python 2.5, on Windows XP SP2.

--
messages: 55822
nosy: sam
severity: normal
status: open
title: TextWrap vs words 1-character shorter than the width
type: behavior
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



[issue1145] Allow str.join to join non-string types (as per PEP 3100)

2007-09-11 Thread Martin v. Löwis

Changes by Martin v. Löwis:


--
keywords: +patch

__
Tracker <[EMAIL PROTECTED]>

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



[issue1145] Allow str.join to join non-string types (as per PEP 3100)

2007-09-11 Thread Thomas Lee

Thomas Lee added the comment:

Oh and an example of usage:

# before the patch
', '.join([str(x) for x in [1, 2, 3]])

# after the patch
', '.join([1, 2, 3])

__
Tracker <[EMAIL PROTECTED]>

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



[issue1145] Allow str.join to join non-string types (as per PEP 3100)

2007-09-11 Thread Thomas Lee

New submission from Thomas Lee:

The current implementation of str.join requires that the parameters
passed to it be string/unicode values. A suggestion to allow it to
accept parameters of any type came up in PEP 3100. Implemented for
Unicode using the attached patch.

It would be trivial to add this functionality to the old string object
too, but I haven't been following the string to unicode discussion too
closely and I'm unsure if the old string object will remain for too much
longer.

--
components: Interpreter Core
files: join-autostr.patch
messages: 55820
nosy: thomas.lee
severity: minor
status: open
title: Allow str.join to join non-string types (as per PEP 3100)
type: behavior
versions: Python 3.0

__
Tracker <[EMAIL PROTECTED]>

__Index: Objects/unicodeobject.c
===
--- Objects/unicodeobject.c	(revision 58102)
+++ Objects/unicodeobject.c	(working copy)
@@ -5412,14 +5412,16 @@
 
 	item = PySequence_Fast_GET_ITEM(fseq, i);
 	/* Convert item to Unicode. */
-	if (! PyUnicode_Check(item) && ! PyString_Check(item)) {
-	PyErr_Format(PyExc_TypeError,
-			 "sequence item %zd: expected string or Unicode,"
-			 " %.80s found",
-			 i, Py_Type(item)->tp_name);
-	goto onError;
+	if (!PyString_Check(item) && !PyUnicode_Check(item))
+	{
+		PyObject* sval;
+		sval = PyObject_Unicode(item);
+		item = PyUnicode_FromObject(sval);
+		Py_DECREF(sval);
 	}
-	item = PyUnicode_FromObject(item);
+	else
+		item = PyUnicode_FromObject(item);
+
 	if (item == NULL)
 	goto onError;
 	/* We own a reference to item from here on. */
Index: Doc/library/stdtypes.rst
===
--- Doc/library/stdtypes.rst	(revision 58102)
+++ Doc/library/stdtypes.rst	(working copy)
@@ -786,8 +786,10 @@
 
 .. method:: str.join(seq)
 
-   Return a string which is the concatenation of the strings in the sequence *seq*.
-   The separator between elements is the string providing this method.
+   Return a string which is the concatenation of the values in the sequence *seq*.
+   Non-string values in *seq* will be converted to a string using their respective
+   implementation of :meth:`__str__`. The separator between elements is the string
+   providing this method.
 
 
 .. method:: str.ljust(width[, fillchar])
Index: Lib/test/test_descr.py
===
--- Lib/test/test_descr.py	(revision 58102)
+++ Lib/test/test_descr.py	(working copy)
@@ -3238,10 +3238,6 @@
 except ValueError: pass
 else: raise TestFailed("''.split('') doesn't raise ValueError")
 
-try: ''.join([0])
-except TypeError: pass
-else: raise TestFailed("''.join([0]) doesn't raise TypeError")
-
 try: ''.rindex('5')
 except ValueError: pass
 else: raise TestFailed("''.rindex('5') doesn't raise ValueError")
Index: Lib/test/test_unicode.py
===
--- Lib/test/test_unicode.py	(revision 58102)
+++ Lib/test/test_unicode.py	(working copy)
@@ -178,6 +178,10 @@
 def test_join(self):
 string_tests.MixinStrUnicodeUserStringTest.test_join(self)
 
+class MyWrapper:
+def __init__(self, sval): self.sval = sval
+def __str__(self): return self.sval
+
 # mixed arguments
 self.checkequalnofix('a b c d', ' ', 'join', ['a', 'b', 'c', 'd'])
 self.checkequalnofix('abcd', '', 'join', ('a', 'b', 'c', 'd'))
@@ -186,6 +190,7 @@
 self.checkequalnofix('a b c d', ' ', 'join', ['a', 'b', 'c', 'd'])
 self.checkequalnofix('abcd', '', 'join', ('a', 'b', 'c', 'd'))
 self.checkequalnofix('w x y z', ' ', 'join', string_tests.Sequence('wxyz'))
+self.checkequalnofix('1 2 foo you', ' ', 'join', [1, 2, MyWrapper('foo'), 'you'])
 
 def test_replace(self):
 string_tests.CommonTest.test_replace(self)
Index: Lib/test/string_tests.py
===
--- Lib/test/string_tests.py	(revision 58102)
+++ Lib/test/string_tests.py	(working copy)
@@ -13,6 +13,7 @@
 
 class BadSeq1(Sequence):
 def __init__(self): self.seq = [7, 'hello', 123]
+def __str__(self): return '{0} {1} {2}'.format(*self.seq)
 
 class BadSeq2(Sequence):
 def __init__(self): self.seq = ['a', 'b', 'c']
@@ -987,19 +988,19 @@
 self.checkequal('abc', 'a', 'join', ('abc',))
 self.checkequal('z', 'a', 'join', UserList(['z']))
 self.checkequal('a.b.c', '.', 'join', ['a', 'b', 'c'])
-self.checkraises(TypeError, '.', 'join', ['a', 'b', 3])
+self.checkequal('a.b.3', '.', 'join', ['a', 'b', 3])
 for i in [5, 25, 125]:
 self.checkequal'a' * i) + '-') * i)[:-1], '-', 'join',
  ['a' * i] * i)
 self.checkequal'a' * i) + '-') * i)[:-1], '-', '

[issue1123] split(None, maxsplit) does not strip whitespace correctly

2007-09-11 Thread Nir Soffer

Nir Soffer added the comment:

There is a problem only when maxsplit is smaller than the available 
splits. In other cases, the docs and the behavior match.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1144] parsermodule validation out of sync with Grammar

2007-09-11 Thread David Binger

New submission from David Binger:

>>> parser.sequence2st(parser.suite("class A(object): pass").tolist())
Traceback (most recent call last):
  File "", line 1, in 
parser.ParserError: Expected node type 326, got 329.

---

The Grammar in python 3 uses "arglist" instead of "testlist"
for class definitions.  The parsermodule's validate_class()
calls validate_testlist() where it should now be calling
validate_arglist().

--
components: Library (Lib)
messages: 55818
nosy: dbinger
severity: normal
status: open
title: parsermodule validation out of sync with Grammar
type: behavior
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



[issue1122] PyTuple_Size and PyTuple_GET_SIZE return type documentation incorrect

2007-09-11 Thread Georg Brandl

Changes by Georg Brandl:


--
assignee:  -> georg.brandl
nosy: +georg.brandl

__
Tracker <[EMAIL PROTECTED]>

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



[issue1121] Document inspect.getfullargspec()

2007-09-11 Thread Georg Brandl

Changes by Georg Brandl:


--
assignee:  -> georg.brandl
nosy: +georg.brandl

__
Tracker <[EMAIL PROTECTED]>

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