[issue1193] os.system() encoding bug on Windows

2007-11-05 Thread Christian Heimes

Christian Heimes added the comment:

Python 3.0 has many more problems at its boundaries to the system on
Windows. Large parts of the API that deals with Windows system calls
have to be rewritten in order to use the wide char API.

--
keywords: +py3k
nosy: +tiran
priority: normal -> high
resolution:  -> accepted

__
Tracker <[EMAIL PROTECTED]>

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



[issue1388] py3k-pep3137: possible ref leak in ctypes

2007-11-05 Thread Thomas Heller

Thomas Heller added the comment:

./python Lib/test/regrtest.py -R:: test_ctypes does not report a leak,
so I think there is no leak.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1388] py3k-pep3137: possible ref leak in ctypes

2007-11-05 Thread Christian Heimes

Christian Heimes added the comment:

Thomas Heller wrote:
> Thomas Heller added the comment:
> 
> ./python Lib/test/regrtest.py -R:: test_ctypes does not report a leak,
> so I think there is no leak.

I'm getting

$ ./python Lib/test/regrtest.py -R:: test_ctypes
test_ctypes
beginning 9 repetitions
123456789
.
test_ctypes leaked [-33, 0, 0, 0] references, sum=-33
1 test OK.
[101762 refs]

Is that ok?

Christian

__
Tracker <[EMAIL PROTECTED]>

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



[issue1392] py3k-pep3137: str(bytes()) and str(buffer()) should raise TypeError patch

2007-11-05 Thread Christian Heimes

New submission from Christian Heimes:

str(bytes()) == repr(bytes()) and str(buffer()) == repr(buffer()) is
causing a bunch bugs which are extremely hard to understand. On several
occasions I didn't understand the problem until I removed a str() call
or made str(bytes()) and str(buffer()) raise an exception.

--
assignee: gvanrossum
components: Interpreter Core
files: py3k-pep3137_remove_str_bytes.patch
keywords: patch, py3k
messages: 57124
nosy: gvanrossum, tiran
priority: high
severity: normal
status: open
title: py3k-pep3137: str(bytes()) and str(buffer()) should raise TypeError patch
type: behavior
versions: Python 3.0
Added file: http://bugs.python.org/file8694/py3k-pep3137_remove_str_bytes.patch

__
Tracker <[EMAIL PROTECTED]>

__Index: Objects/bytesobject.c
===
--- Objects/bytesobject.c	(Revision 58843)
+++ Objects/bytesobject.c	(Arbeitskopie)
@@ -923,6 +923,14 @@
 }
 
 static PyObject *
+bytes_str(PyObject *op)
+{
+	PyErr_SetString(PyExc_TypeError,
+			"str() argument must not be a buffer instance.");
+	return NULL;
+}
+
+static PyObject *
 bytes_richcompare(PyObject *self, PyObject *other, int op)
 {
 Py_ssize_t self_size, other_size;
@@ -3063,7 +3071,7 @@
 &bytes_as_mapping,  /* tp_as_mapping */
 0,  /* tp_hash */
 0,  /* tp_call */
-(reprfunc)bytes_repr,   /* tp_str */
+(reprfunc)bytes_str,/* tp_str */
 PyObject_GenericGetAttr,/* tp_getattro */
 0,  /* tp_setattro */
 &bytes_as_buffer,   /* tp_as_buffer */
Index: Objects/stringobject.c
===
--- Objects/stringobject.c	(Revision 58843)
+++ Objects/stringobject.c	(Arbeitskopie)
@@ -679,6 +679,14 @@
 	return PyString_Repr(op, 1);
 }
 
+static PyObject *
+string_str(PyObject *op)
+{
+	PyErr_SetString(PyExc_TypeError,
+			"str() argument must not be a byte instance.");
+	return NULL;
+}
+
 static Py_ssize_t
 string_length(PyStringObject *a)
 {
@@ -3096,7 +3104,7 @@
 	&string_as_mapping,			/* tp_as_mapping */
 	(hashfunc)string_hash, 			/* tp_hash */
 	0,	/* tp_call */
-	string_repr,/* tp_str */
+	(reprfunc)string_str,			/* tp_str */
 	PyObject_GenericGetAttr,		/* tp_getattro */
 	0,	/* tp_setattro */
 	&string_as_buffer,			/* tp_as_buffer */
Index: Lib/test/test_bytes.py
===
--- Lib/test/test_bytes.py	(Revision 58843)
+++ Lib/test/test_bytes.py	(Arbeitskopie)
@@ -86,16 +86,22 @@
 self.assertRaises(ValueError, buffer, [sys.maxint+1])
 self.assertRaises(ValueError, buffer, [10**100])
 
-def test_repr_str(self):
-for f in str, repr:
-self.assertEqual(f(buffer()), "buffer(b'')")
-self.assertEqual(f(buffer([0])), "buffer(b'\\x00')")
-self.assertEqual(f(buffer([0, 1, 254, 255])),
- "buffer(b'\\x00\\x01\\xfe\\xff')")
-self.assertEqual(f(b"abc"), "b'abc'")
-self.assertEqual(f(b"'"), '''b"'"''')
-self.assertEqual(f(b"'\""), r"""b'\'"'""")
+def test_repr(self):
+self.assertEqual(repr(buffer()), "buffer(b'')")
+self.assertEqual(repr(buffer([0])), "buffer(b'\\x00')")
+self.assertEqual(repr(buffer([0, 1, 254, 255])),
+ "buffer(b'\\x00\\x01\\xfe\\xff')")
+self.assertEqual(repr(b"abc"), "b'abc'")
+self.assertEqual(repr(b"'"), '''b"'"''')
+self.assertEqual(repr(b"'\""), r"""b'\'"'""")
 
+def test_str(self):
+self.assertRaises(TypeError, str, buffer())
+self.assertRaises(TypeError, str, buffer([0]))
+self.assertRaises(TypeError, str, buffer([0, 1, 254, 255]))
+self.assertRaises(TypeError, str, b"abc")
+self.assertRaises(TypeError, str, b"'")
+self.assertRaises(TypeError, str, b"'\"")
 
 def test_compare(self):
 b1 = buffer([1, 2, 3])
@@ -370,11 +376,6 @@
 b = buffer(buf)
 self.assertEqual(b, buffer(sample))
 
-def test_to_str(self):
-self.assertEqual(str(b''), "b''")
-self.assertEqual(str(b'x'), "b'x'")
-self.assertEqual(str(b'\x80'), "b'\\x80'")
-
 def test_from_int(self):
 b = buffer(0)
 self.assertEqual(b, buffer())
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1392] py3k-pep3137: str(bytes()) and str(buffer()) should raise TypeError patch

2007-11-05 Thread Christian Heimes

Christian Heimes added the comment:

Err, please remove the (reprfunc) cast and check the language of the
error messages, too :)

__
Tracker <[EMAIL PROTECTED]>

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



[issue1392] py3k-pep3137: str(bytes()) and str(buffer()) should raise TypeError patch

2007-11-05 Thread Christian Heimes

Christian Heimes added the comment:

Here is an updated patch that fixes an error in httplib that was causing
the xmlrpc test suite to block.

Added file: http://bugs.python.org/file8695/py3k-pep3137_remove_str_bytes2.patch

__
Tracker <[EMAIL PROTECTED]>

__Index: Objects/bytesobject.c
===
--- Objects/bytesobject.c	(Revision 58857)
+++ Objects/bytesobject.c	(Arbeitskopie)
@@ -923,6 +923,14 @@
 }
 
 static PyObject *
+bytes_str(PyObject *op)
+{
+	PyErr_SetString(PyExc_TypeError,
+			"str() argument must not be a buffer instance.");
+	return NULL;
+}
+
+static PyObject *
 bytes_richcompare(PyObject *self, PyObject *other, int op)
 {
 Py_ssize_t self_size, other_size;
@@ -3063,7 +3071,7 @@
 &bytes_as_mapping,  /* tp_as_mapping */
 0,  /* tp_hash */
 0,  /* tp_call */
-(reprfunc)bytes_repr,   /* tp_str */
+bytes_str,  /* tp_str */
 PyObject_GenericGetAttr,/* tp_getattro */
 0,  /* tp_setattro */
 &bytes_as_buffer,   /* tp_as_buffer */
Index: Objects/stringobject.c
===
--- Objects/stringobject.c	(Revision 58857)
+++ Objects/stringobject.c	(Arbeitskopie)
@@ -679,6 +679,14 @@
 	return PyString_Repr(op, 1);
 }
 
+static PyObject *
+string_str(PyObject *op)
+{
+	PyErr_SetString(PyExc_TypeError,
+			"str() argument must not be a byte instance.");
+	return NULL;
+}
+
 static Py_ssize_t
 string_length(PyStringObject *a)
 {
@@ -3090,13 +3098,13 @@
 	0,	/* tp_getattr */
 	0,	/* tp_setattr */
 	0,	/* tp_compare */
-	string_repr, /* tp_repr */
+	(reprfunc)string_repr, 			/* tp_repr */
 	0,	/* tp_as_number */
 	&string_as_sequence,			/* tp_as_sequence */
 	&string_as_mapping,			/* tp_as_mapping */
 	(hashfunc)string_hash, 			/* tp_hash */
 	0,	/* tp_call */
-	string_repr,/* tp_str */
+	string_str,/* tp_str */
 	PyObject_GenericGetAttr,		/* tp_getattro */
 	0,	/* tp_setattro */
 	&string_as_buffer,			/* tp_as_buffer */
Index: Lib/httplib.py
===
--- Lib/httplib.py	(Revision 58857)
+++ Lib/httplib.py	(Arbeitskopie)
@@ -827,6 +827,7 @@
 if self.port == HTTP_PORT:
 self.putheader('Host', host_enc)
 else:
+host_enc = host_enc.decode("ascii")
 self.putheader('Host', "%s:%s" % (host_enc, self.port))
 
 # note: we are assuming that clients will not attempt to set these
Index: Lib/test/test_xmlrpc.py
===
--- Lib/test/test_xmlrpc.py	(Revision 58857)
+++ Lib/test/test_xmlrpc.py	(Arbeitskopie)
@@ -6,6 +6,7 @@
 import xmlrpclib
 import SimpleXMLRPCServer
 import threading
+import traceback
 import mimetools
 from test import test_support
 
@@ -328,6 +329,9 @@
 except xmlrpclib.ProtocolError as e:
 # protocol error; provide additional information in test output
 self.fail("%s\n%s" % (e, e.headers))
+except:
+traceback.print_exc(file=sys.stderr)
+raise
 
 def test_introspection2(self):
 try:
Index: Lib/test/test_bytes.py
===
--- Lib/test/test_bytes.py	(Revision 58857)
+++ Lib/test/test_bytes.py	(Arbeitskopie)
@@ -86,16 +86,22 @@
 self.assertRaises(ValueError, buffer, [sys.maxint+1])
 self.assertRaises(ValueError, buffer, [10**100])
 
-def test_repr_str(self):
-for f in str, repr:
-self.assertEqual(f(buffer()), "buffer(b'')")
-self.assertEqual(f(buffer([0])), "buffer(b'\\x00')")
-self.assertEqual(f(buffer([0, 1, 254, 255])),
- "buffer(b'\\x00\\x01\\xfe\\xff')")
-self.assertEqual(f(b"abc"), "b'abc'")
-self.assertEqual(f(b"'"), '''b"'"''')
-self.assertEqual(f(b"'\""), r"""b'\'"'""")
+def test_repr(self):
+self.assertEqual(repr(buffer()), "buffer(b'')")
+self.assertEqual(repr(buffer([0])), "buffer(b'\\x00')")
+self.assertEqual(repr(buffer([0, 1, 254, 255])),
+ "buffer(b'\\x00\\x01\\xfe\\xff')")
+self.assertEqual(repr(b"abc"), "b'abc'")
+self.assertEqual(repr(b"'"), '''b"'"''')
+self.assertEqual(repr(b"'\""), r"""b'\'"'""")
 
+def test_str(self):
+self.assertRaises(TypeError, str, buffer())
+self.assertRaises(TypeError, str, buffer([0]))
+self.assertRaises(TypeError, str, buffer([0, 1, 254, 255]))
+self.assertRaises(TypeError, str, b"abc")
+self.ass

[issue1392] py3k-pep3137: str(bytes()) and str(buffer()) should raise TypeError patch

2007-11-05 Thread Guido van Rossum

Guido van Rossum added the comment:

I'll look at the patches later, but we've gone over this before on the
list. str() of *any* object needs to return *something*. Yes, it's
unfortunate that this masks bugs in the transitional period, but it
really is the best thing in the long run. We had other exceptional
treatement for str vs. bytes (e.g. the comparison was raising TypeError
for a while) and we had to kill that too.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1392] py3k-pep3137: str(bytes()) and str(buffer()) should raise TypeError patch

2007-11-05 Thread Christian Heimes

Christian Heimes added the comment:

Guido van Rossum wrote:
> I'll look at the patches later, but we've gone over this before on the
> list. str() of *any* object needs to return *something*. Yes, it's
> unfortunate that this masks bugs in the transitional period, but it
> really is the best thing in the long run. We had other exceptional
> treatement for str vs. bytes (e.g. the comparison was raising TypeError
> for a while) and we had to kill that too.

Can we agree to a compromise and make str(bytes()) return
bytes().decode("ascii")? I think it's a sensible default behavior and
catches the errors in the code I've seen so far.

Christian

__
Tracker <[EMAIL PROTECTED]>

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



[issue1392] py3k-pep3137: str(bytes()) and str(buffer()) should raise TypeError patch

2007-11-05 Thread Christian Heimes

Christian Heimes added the comment:

New patch:

static PyObject *
string_str(PyObject *op)
{
return PyObject_CallMethod(op, "decode", "s", "ascii");
}

Added file: http://bugs.python.org/file8696/py3k-pep3137_str_bytes_ascii.patch

__
Tracker <[EMAIL PROTECTED]>

__Index: Objects/bytesobject.c
===
--- Objects/bytesobject.c	(Revision 58857)
+++ Objects/bytesobject.c	(Arbeitskopie)
@@ -923,6 +923,12 @@
 }
 
 static PyObject *
+bytes_str(PyObject *op)
+{
+	return PyObject_CallMethod(op, "decode", "s", "ascii");
+}
+
+static PyObject *
 bytes_richcompare(PyObject *self, PyObject *other, int op)
 {
 Py_ssize_t self_size, other_size;
@@ -3063,7 +3069,7 @@
 &bytes_as_mapping,  /* tp_as_mapping */
 0,  /* tp_hash */
 0,  /* tp_call */
-(reprfunc)bytes_repr,   /* tp_str */
+bytes_str,  /* tp_str */
 PyObject_GenericGetAttr,/* tp_getattro */
 0,  /* tp_setattro */
 &bytes_as_buffer,   /* tp_as_buffer */
Index: Objects/stringobject.c
===
--- Objects/stringobject.c	(Revision 58857)
+++ Objects/stringobject.c	(Arbeitskopie)
@@ -679,6 +679,12 @@
 	return PyString_Repr(op, 1);
 }
 
+static PyObject *
+string_str(PyObject *op)
+{
+	return PyObject_CallMethod(op, "decode", "s", "ascii");
+}
+
 static Py_ssize_t
 string_length(PyStringObject *a)
 {
@@ -3090,13 +3096,13 @@
 	0,	/* tp_getattr */
 	0,	/* tp_setattr */
 	0,	/* tp_compare */
-	string_repr, /* tp_repr */
+	(reprfunc)string_repr, 			/* tp_repr */
 	0,	/* tp_as_number */
 	&string_as_sequence,			/* tp_as_sequence */
 	&string_as_mapping,			/* tp_as_mapping */
 	(hashfunc)string_hash, 			/* tp_hash */
 	0,	/* tp_call */
-	string_repr,/* tp_str */
+	string_str,/* tp_str */
 	PyObject_GenericGetAttr,		/* tp_getattro */
 	0,	/* tp_setattro */
 	&string_as_buffer,			/* tp_as_buffer */
Index: Lib/test/test_bytes.py
===
--- Lib/test/test_bytes.py	(Revision 58857)
+++ Lib/test/test_bytes.py	(Arbeitskopie)
@@ -86,16 +86,23 @@
 self.assertRaises(ValueError, buffer, [sys.maxint+1])
 self.assertRaises(ValueError, buffer, [10**100])
 
-def test_repr_str(self):
-for f in str, repr:
-self.assertEqual(f(buffer()), "buffer(b'')")
-self.assertEqual(f(buffer([0])), "buffer(b'\\x00')")
-self.assertEqual(f(buffer([0, 1, 254, 255])),
- "buffer(b'\\x00\\x01\\xfe\\xff')")
-self.assertEqual(f(b"abc"), "b'abc'")
-self.assertEqual(f(b"'"), '''b"'"''')
-self.assertEqual(f(b"'\""), r"""b'\'"'""")
+def test_repr(self):
+self.assertEqual(repr(buffer()), "buffer(b'')")
+self.assertEqual(repr(buffer([0])), "buffer(b'\\x00')")
+self.assertEqual(repr(buffer([0, 1, 254, 255])),
+ "buffer(b'\\x00\\x01\\xfe\\xff')")
+self.assertEqual(repr(b"abc"), "b'abc'")
+self.assertEqual(repr(b"'"), '''b"'"''')
+self.assertEqual(repr(b"'\""), r"""b'\'"'""")
 
+def test_str(self):
+self.assertEqual(str(buffer()), "")
+self.assertEqual(str(buffer([0])), "\x00")
+self.assertRaises(UnicodeDecodeError, str, buffer([0, 1, 254, 255]))
+self.assertEqual(str(b"abc"), "abc")
+self.assertEqual(str(b"'"), "'")
+self.assertEqual(str(b"'\""), "'\"")
+self.assertRaises(UnicodeDecodeError, str, bytes([0, 1, 254, 255]))
 
 def test_compare(self):
 b1 = buffer([1, 2, 3])
@@ -371,9 +378,10 @@
 self.assertEqual(b, buffer(sample))
 
 def test_to_str(self):
-self.assertEqual(str(b''), "b''")
-self.assertEqual(str(b'x'), "b'x'")
-self.assertEqual(str(b'\x80'), "b'\\x80'")
+self.assertEqual(str(b''), "")
+self.assertEqual(str(b'x'), "x")
+self.assertEqual(str(b'\x61\x62'), "ab")
+self.assertRaises(UnicodeDecodeError, str, b'\xff')
 
 def test_from_int(self):
 b = buffer(0)
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1388] py3k-pep3137: possible ref leak in ctypes

2007-11-05 Thread Thomas Heller

Thomas Heller added the comment:

> $ ./python Lib/test/regrtest.py -R:: test_ctypes
> test_ctypes
> beginning 9 repetitions
> 123456789
> .
> test_ctypes leaked [-33, 0, 0, 0] references, sum=-33
> 1 test OK.
> [101762 refs]

Yes, I think this is ok.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1388] py3k-pep3137: possible ref leak in ctypes

2007-11-05 Thread Christian Heimes

Changes by Christian Heimes:


--
resolution:  -> invalid
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



[issue1392] py3k-pep3137: str(bytes()) and str(buffer()) should raise TypeError patch

2007-11-05 Thread Guido van Rossum

Guido van Rossum added the comment:

No -- making str(b) return b.decode("ascii") brings back the same issues
we had with mindlessly mixing PyString and PyUnicode in 2.x.  That was a
major disaster.

--
status: open -> 

__
Tracker <[EMAIL PROTECTED]>

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



[issue1392] py3k-pep3137: str(bytes()) and str(buffer()) should raise TypeError patch

2007-11-05 Thread Guido van Rossum

Guido van Rossum added the comment:

A compromise I could live with: add a command line option that makes it
a warning.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1392] py3k-pep3137: str(bytes()) and str(buffer()) should raise TypeError patch

2007-11-05 Thread Christian Heimes

Christian Heimes added the comment:

Guido van Rossum wrote:
> Guido van Rossum added the comment:
> 
> A compromise I could live with: add a command line option that makes it
> a warning.

Good idea. I can live with it, too. :) How do you like

-b: issue warnings about str(bytes_instance) and str(buffer_instance)
(-bb: issue errors)

Christian

__
Tracker <[EMAIL PROTECTED]>

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



[issue1392] py3k-pep3137: str(bytes()) and str(buffer()) should raise TypeError patch

2007-11-05 Thread Christian Heimes

Christian Heimes added the comment:

I've made a patch with -b -> warning and -bb > type error. I'm not happy
with the warning message. Maybe you've a better idea for it.

Added file: http://bugs.python.org/file8697/py3k-pep3137_str_bytes_warning.patch

__
Tracker <[EMAIL PROTECTED]>

__Index: Python/pythonrun.c
===
--- Python/pythonrun.c	(Revision 58857)
+++ Python/pythonrun.c	(Arbeitskopie)
@@ -75,6 +75,7 @@
 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
 int Py_InspectFlag; /* Needed to determine whether to exit at SystemError */
 int Py_NoSiteFlag; /* Suppress 'import site' */
+int Py_StrBytesWarningFlag; /* Warn on str(bytes) and str(buffer) */
 int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */
 int Py_FrozenFlag; /* Needed by getpath.c */
 int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */
Index: Include/pydebug.h
===
--- Include/pydebug.h	(Revision 58857)
+++ Include/pydebug.h	(Arbeitskopie)
@@ -11,6 +11,7 @@
 PyAPI_DATA(int) Py_InspectFlag;
 PyAPI_DATA(int) Py_OptimizeFlag;
 PyAPI_DATA(int) Py_NoSiteFlag;
+PyAPI_DATA(int) Py_StrBytesWarningFlag;
 PyAPI_DATA(int) Py_UseClassExceptionsFlag;
 PyAPI_DATA(int) Py_FrozenFlag;
 PyAPI_DATA(int) Py_TabcheckFlag;
Index: Objects/bytesobject.c
===
--- Objects/bytesobject.c	(Revision 58857)
+++ Objects/bytesobject.c	(Arbeitskopie)
@@ -923,6 +923,23 @@
 }
 
 static PyObject *
+bytes_str(PyObject *op)
+{
+	if (Py_StrBytesWarningFlag == 1) {
+		if (PyErr_WarnEx(PyExc_Warning,
+ "Calling str() on a bytes instance.",
+ 1))
+			return NULL;
+	}
+	if (Py_StrBytesWarningFlag > 1) {
+		PyErr_SetString(PyExc_TypeError,
+"Calling str() on a bytes instance.");
+		return NULL;
+	}
+	return bytes_repr((PyBytesObject*)op);
+}
+
+static PyObject *
 bytes_richcompare(PyObject *self, PyObject *other, int op)
 {
 Py_ssize_t self_size, other_size;
@@ -3063,7 +3080,7 @@
 &bytes_as_mapping,  /* tp_as_mapping */
 0,  /* tp_hash */
 0,  /* tp_call */
-(reprfunc)bytes_repr,   /* tp_str */
+bytes_str,  /* tp_str */
 PyObject_GenericGetAttr,/* tp_getattro */
 0,  /* tp_setattro */
 &bytes_as_buffer,   /* tp_as_buffer */
Index: Objects/stringobject.c
===
--- Objects/stringobject.c	(Revision 58857)
+++ Objects/stringobject.c	(Arbeitskopie)
@@ -679,6 +679,23 @@
 	return PyString_Repr(op, 1);
 }
 
+static PyObject *
+string_str(PyObject *op)
+{
+	if (Py_StrBytesWarningFlag == 1) {
+		if (PyErr_WarnEx(PyExc_Warning,
+ "Calling str() on a bytes instance.",
+ 1))
+			return NULL;
+	}
+	if (Py_StrBytesWarningFlag > 1) {
+		PyErr_SetString(PyExc_TypeError,
+"Calling str() on a bytes instance.");
+			return NULL;
+	}
+	return string_repr(op);
+}
+
 static Py_ssize_t
 string_length(PyStringObject *a)
 {
@@ -3090,13 +3107,13 @@
 	0,	/* tp_getattr */
 	0,	/* tp_setattr */
 	0,	/* tp_compare */
-	string_repr, /* tp_repr */
+	(reprfunc)string_repr, 			/* tp_repr */
 	0,	/* tp_as_number */
 	&string_as_sequence,			/* tp_as_sequence */
 	&string_as_mapping,			/* tp_as_mapping */
 	(hashfunc)string_hash, 			/* tp_hash */
 	0,	/* tp_call */
-	string_repr,/* tp_str */
+	string_str,/* tp_str */
 	PyObject_GenericGetAttr,		/* tp_getattro */
 	0,	/* tp_setattro */
 	&string_as_buffer,			/* tp_as_buffer */
Index: Modules/main.c
===
--- Modules/main.c	(Revision 58857)
+++ Modules/main.c	(Arbeitskopie)
@@ -44,7 +44,7 @@
 static int  orig_argc;
 
 /* command line options */
-#define BASE_OPTS "c:dEhim:OStuvVW:xX?"
+#define BASE_OPTS "bc:dEhim:OStuvVW:xX?"
 
 #define PROGRAM_OPTS BASE_OPTS
 
@@ -55,32 +55,34 @@
 /* Long usage message, split into parts < 512 bytes */
 static char *usage_1 = "\
 Options and arguments (and corresponding environment variables):\n\
+-b : issue warnings about str(bytes_instance) and str(buffer_instance)\n\
+ (-bb: issue errors)\n\
 -c cmd : program passed in as string (terminates option list)\n\
 -d : debug output from parser; also PYTHONDEBUG=x\n\
 -E : ignore environment variables (such as PYTHONPATH)\n\
 -h : print this help message and exit (also --help)\n\
+";
+static char *usage_2 = "\
 -i : inspect interactively after running script; forces a prompt even\n\
  if stdin does not appear to be a terminal; also PYTHONINSPECT=x\n\
-";
-static char *usage_2 = "\
 -m mod : run library module as a script (terminates 

[issue1393] function comparing lacks NotImplemented error

2007-11-05 Thread Paul Pogonyshev

New submission from Paul Pogonyshev:

I believe attached script demonstrates a bug in Python 3000.  As far as
I can tell, it should print four times 'True'.

--
components: Interpreter Core
files: test.py
messages: 57135
nosy: Paul Pogonyshev
severity: normal
status: open
title: function comparing lacks NotImplemented error
versions: Python 3.0
Added file: http://bugs.python.org/file8698/test.py

__
Tracker <[EMAIL PROTECTED]>

__class Anything:
def __eq__(self, other):
return True
def __ne__(self, other):
return False

x = lambda: None

print(x == Anything())
print(Anything() == x)

y = object()

print(y == Anything())
print(Anything() == y)
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1392] py3k-pep3137: str(bytes()) and str(buffer()) should raise TypeError patch

2007-11-05 Thread Guido van Rossum

Guido van Rossum added the comment:

The error message is fine, though you could drop the word "Calling"
without loss of information. ;-) Also, most warnings don't seem to use
a trailing period.

Perhaps you could expand this to also add a trap in the comparison
function when Py{String,Bytes} is compared to PyUnicode.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1392] py3k-pep3137: str(bytes()) and str(buffer()) should raise TypeError patch

2007-11-05 Thread Christian Heimes

Christian Heimes added the comment:

Guido van Rossum wrote:
> The error message is fine, though you could drop the word "Calling"
> without loss of information. ;-) Also, most warnings don't seem to use
> a trailing period.
> 
> Perhaps you could expand this to also add a trap in the comparison
> function when Py{String,Bytes} is compared to PyUnicode.

It's sounds like a reasonable idea. But first I'm going to hit the down
with my gf and meet some friends. Cu later!

PS: In my humble opinion Amaury Forgeot d'Arc deserves an entry in the
Misc/ACKS list for his patches.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1392] py3k-pep3137: str(bytes()) and str(buffer()) should raise TypeError patch

2007-11-05 Thread Guido van Rossum

Guido van Rossum added the comment:

> It's sounds like a reasonable idea. But first I'm going to hit the down
> with my gf and meet some friends. Cu later!

No! You're not allowed to have a life! :-)

(And no hacking drunk, either. :-)

> PS: In my humble opinion Amaury Forgeot d'Arc deserves an entry in the
> Misc/ACKS list for his patches.

Agreed -- done!

__
Tracker <[EMAIL PROTECTED]>

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



[issue1384] Windows fix for inspect tests

2007-11-05 Thread Guido van Rossum

Guido van Rossum added the comment:

Shouldn't this use os.path.normcase() instead of testing for nt and
using lower()?

--
nosy: +gvanrossum

__
Tracker <[EMAIL PROTECTED]>

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



[issue1390] toxml generates output that is not well formed

2007-11-05 Thread Thomas Conway

Thomas Conway added the comment:

Hi Martin,

You write:
It's not a bug in toxml, which should always serialize the
DOM tree if possible.

Right! In this case it is *not* possible. The generated serialization is
not a well formed XML document.

Having just consulted the DOM technical reports, I see that
createComment is specified as not generating any exceptions, so although
it would be quite a sensible place to check that one was not creating an
insane document, probably one should not do the check there. I think
you're right that this *is* a bug in DOM, and I will report it there.

Having said that, I still think that toxml should throw an exception. In
general, if toxml succeeds, I would expect to be able to parse the result.

I can propose a doco change, but I think such would only be a partial
solution. Something like the following addition to the description for
createComment

Note that comments containing the string C{-->} may make the document
unserializable.

cheers,
Tom

__
Tracker <[EMAIL PROTECTED]>

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



[issue1385] hmac module violates RFC for some hash functions, e.g. sha512

2007-11-05 Thread Guido van Rossum

Changes by Guido van Rossum:


--
assignee:  -> gregory.p.smith
nosy: +gregory.p.smith

__
Tracker <[EMAIL PROTECTED]>

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



[issue1394] simple patch, improving unreachable bytecode removing

2007-11-05 Thread Paul Pogonyshev

New submission from Paul Pogonyshev:

This patch improves bytecode output, by removing unreachable code.  It
doesn't target special cases, as now, but provides a generic implementation.

--
components: Interpreter Core
files: unreachable-code.diff
messages: 57141
nosy: Paul Pogonyshev
severity: minor
status: open
title: simple patch, improving unreachable bytecode removing
versions: Python 2.6
Added file: http://bugs.python.org/file8699/unreachable-code.diff

__
Tracker <[EMAIL PROTECTED]>

__Index: Python/peephole.c
===
*** Python/peephole.c   (revision 58867)
--- Python/peephole.c   (working copy)
***
*** 550,566 
case EXTENDED_ARG:
goto exitUnchanged;
  
!   /* Replace RETURN LOAD_CONST None RETURN with 
just RETURN */
!   /* Remove unreachable JUMPs after RETURN */
case RETURN_VALUE:
!   if (i+4 >= codelen)
!   continue;
!   if (codestr[i+4] == RETURN_VALUE &&
!   ISBASICBLOCK(blocks,i,5))
!   memset(codestr+i+1, NOP, 4);
!   else if (UNCONDITIONAL_JUMP(codestr[i+1]) &&
!ISBASICBLOCK(blocks,i,4))
!   memset(codestr+i+1, NOP, 3);
break;
}
}
--- 550,571 
case EXTENDED_ARG:
goto exitUnchanged;
  
!   /* Remove unreachable code completely */
! #if 0
!   /* These are handled differently above */
!   case CONTINUE_LOOP:
!   case JUMP_FORWARD:
!   case JUMP_ABSOLUTE:
! #endif
!   case RAISE_VARARGS:
!   case BREAK_LOOP:
case RETURN_VALUE:
!   j = i + CODESIZE(codestr[i]);
!   tgt = j;
!   while (tgt < codelen && blocks[tgt] == 
blocks[i])
!   tgt += CODESIZE(codestr[tgt]);
!   if (tgt > j)
!   memset(codestr+j, NOP, tgt-j);
break;
}
}
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1385] hmac module violates RFC for some hash functions, e.g. sha512

2007-11-05 Thread Gregory P. Smith

Gregory P. Smith added the comment:

option 1 sounds best.  i'll take care of this.  thanks for noticing this
and providing suggestions and a patch.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1385] hmac module violates RFC for some hash functions, e.g. sha512

2007-11-05 Thread Gregory P. Smith

Changes by Gregory P. Smith:


--
components: +Library (Lib) -None
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



[issue1390] toxml generates output that is not well formed

2007-11-05 Thread Thomas Conway

Thomas Conway added the comment:

Hi Martin,

toxml() is not part of the DOM, so it could be changed to throw an
exception.

However, I suggest doing nothing, for the moment - I've posted to the
dom mailing list at w3, so I'll see what wisdom we get from its members.

cheers,
Tom

__
Tracker <[EMAIL PROTECTED]>

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



[issue1390] toxml generates output that is not well formed

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

Martin v. Löwis added the comment:

I'm not willing to change minidom unless there is precedence of how to
deal with this case. So can you find DOM implementations in other
languages that meet the DOM spec an still reject your code?

__
Tracker <[EMAIL PROTECTED]>

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



[issue1384] Windows fix for inspect tests

2007-11-05 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc added the comment:

A slightly modified patch, which uses os.path.normcase before comparing
file names.

--
nosy: +amaury.forgeotdarc
Added file: http://bugs.python.org/file8700/py3k_inspect_2.diff

__
Tracker <[EMAIL PROTECTED]>

__

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



[issue1384] Windows fix for inspect tests

2007-11-05 Thread Christian Heimes

Christian Heimes added the comment:

Ah, os.path has a method for the job. I should have checked the module
before reinventing the wheel ... 

For some unknown and mysterious reasons the inspect tests are passing
again on my machine. I've purged the pyc files before I run the
unpatched test suite. Should I apply the patch anyway?

__
Tracker <[EMAIL PROTECTED]>

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



[issue1395] py3k: duplicated line endings when using read(1)

2007-11-05 Thread Amaury Forgeot d'Arc

New submission from Amaury Forgeot d'Arc:

When reading a Windows text file one byte at a time, \r\n get split into
two function calls, and the user receives two \n.

The following test fails (put it somewhere in test_io.py, inside
TextIOWrapperTest for example)

def testReadOneByOne(self):
txt = io.TextIOWrapper(io.BytesIO(b"AA\r\nBB"))
reads = ""
while True:
c = txt.read(1)
if not c:
break
reads += c
self.assertEquals(reads, "AA\nBB")
# AssertionError: 'AA\n\nBB' != 'AA\nBB'

Note that replacing read(1) by read(2) gives the correct result.

This problem is why test_netrc fails on Windows. It may also be the root
cause for issue 1142 (when \r\n position is just a multiple of the
_CHUNK_SIZE).
It also possible that the correction to this problem will have good
effects on test_mailbox, which uses tell() and seek() intensively.

--
messages: 57147
nosy: amaury.forgeotdarc, gvanrossum, tiran
severity: normal
status: open
title: py3k: duplicated line endings when using read(1)
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



[issue1385] hmac module violates RFC for some hash functions, e.g. sha512

2007-11-05 Thread Gregory P. Smith

Gregory P. Smith added the comment:

Fixed in trunk (2.6) svn revision 58868 with rfc 4231 unit tests and
tests for the new warnings.

The fix parts of that diff should be backported to 2.5.  I'm leaving the
Python 2.5 flag on the bug until that happens.

I'm leaving Python 3.0 and py3k tags on this bug for now until someone
merges it into that tree.

--
keywords: +py3k -patch
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



[issue1385] hmac module violates RFC for some hash functions, e.g. sha512

2007-11-05 Thread Gregory P. Smith

Gregory P. Smith added the comment:

Fixed in release25-maint branch in svn r58870.

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



[issue1384] Windows fix for inspect tests

2007-11-05 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc added the comment:

Yes, the patch is needed.
The problem arises when you run the python executable in different ways
WITHOUT deleting the .pyc files.

Example on my machine: Note that the exact path to run python is not the
same:

>cd C:\dev\python\py3k\PCbuild8
>del /s ..\*.pyc
>c:\dev\python\py3k\PCbuild8\win32debug\python_d.exe -E -tt
../lib/test/regrtest.py -v test_inspect
[test OK]
>C:\dev\python\py3k\PCbuild8\win32debug\python_d.exe -E -tt
../lib/test/regrtest.py -v test_inspect
[test FAILED]

If I always use the same path the tests succeed.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1389] py3k-pep3137: struct module is leaking references

2007-11-05 Thread Guido van Rossum

Guido van Rossum added the comment:

Committed revision 58871.
Finding this took me half a day.
It was not a real leak; it was just filling the character cache in
stringobject.c slowly with random data.

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



[issue1395] py3k: duplicated line endings when using read(1)

2007-11-05 Thread Guido van Rossum

Guido van Rossum added the comment:

Wow, thanks!
This is not just a bug on Windows -- it is a bug in the TextIOWrapper
code that is just more likely on Windows. It is easily reproduced on
Linux too:

>>> f = open("@", "wb")>>> f.write(b"a\r\n")
6
>>> f.close()
>>> f = open("@", "r")
>>> f.read(1)
'a'
>>> f.read(1)
'\n'
>>>

--
priority:  -> high

__
Tracker <[EMAIL PROTECTED]>

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



[issue1392] py3k-pep3137: str(bytes()) and str(buffer()) should raise TypeError patch

2007-11-05 Thread Christian Heimes

Christian Heimes added the comment:

Pfff! I've written my best code after having one or two beers :)

Updates:
* Added class BytesWarning(Warning)
* Added -b/-bb command line args and Py_BytesWarningFlag
* issue PyErr_WarnEx(PyExc_BytesWarning) when Py_BytesWarningFlag is set.
* Added warning filter for BytesWarning that raises an exception if
Py_BytesWarningFlag > 1

Open questions:
* the warning filter isn't set when the initializer cannot load the
warning module (e.g. frozen apps). W/o the warning module Python is
screwed anyway and frozen apps would never add the -b argument.
* the warnings are only enabled with -b. They can't be enabled by
modifying the warnings.filters. Is this fine with you?

Added file: 
http://bugs.python.org/file8701/py3k-pep3137_str_bytes_warning2.patch

__
Tracker <[EMAIL PROTECTED]>

__Index: Python/pythonrun.c
===
--- Python/pythonrun.c	(Revision 58873)
+++ Python/pythonrun.c	(Arbeitskopie)
@@ -75,6 +75,7 @@
 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
 int Py_InspectFlag; /* Needed to determine whether to exit at SystemError */
 int Py_NoSiteFlag; /* Suppress 'import site' */
+int Py_BytesWarningFlag; /* Warn on str(bytes) and str(buffer) */
 int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */
 int Py_FrozenFlag; /* Needed by getpath.c */
 int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */
@@ -262,9 +263,29 @@
 #endif /* WITH_THREAD */
 
 	warnings_module = PyImport_ImportModule("warnings");
-	if (!warnings_module)
+	if (!warnings_module) {
 		PyErr_Clear();
+	}
+	else {
+		PyObject *o;
+		char *action[8];
 
+		if (Py_BytesWarningFlag > 1)
+			*action = "error";
+		else if (Py_BytesWarningFlag)
+			*action = "default";
+		else
+			*action = "ignore";
+
+		o = PyObject_CallMethod(warnings_module,
+	"simplefilter", "sO",
+	*action, PyExc_BytesWarning);
+		if (o == NULL)
+			Py_FatalError("Py_Initialize: can't initialize"
+  "warning filter for BytesWarning.");
+		Py_DECREF(o);
+}
+
 #if defined(HAVE_LANGINFO_H) && defined(CODESET)
 	/* On Unix, set the file system encoding according to the
 	   user's preference, if the CODESET names a well-known
Index: Include/pydebug.h
===
--- Include/pydebug.h	(Revision 58873)
+++ Include/pydebug.h	(Arbeitskopie)
@@ -11,6 +11,7 @@
 PyAPI_DATA(int) Py_InspectFlag;
 PyAPI_DATA(int) Py_OptimizeFlag;
 PyAPI_DATA(int) Py_NoSiteFlag;
+PyAPI_DATA(int) Py_BytesWarningFlag;
 PyAPI_DATA(int) Py_UseClassExceptionsFlag;
 PyAPI_DATA(int) Py_FrozenFlag;
 PyAPI_DATA(int) Py_TabcheckFlag;
Index: Include/pyerrors.h
===
--- Include/pyerrors.h	(Revision 58873)
+++ Include/pyerrors.h	(Arbeitskopie)
@@ -165,6 +165,7 @@
 PyAPI_DATA(PyObject *) PyExc_FutureWarning;
 PyAPI_DATA(PyObject *) PyExc_ImportWarning;
 PyAPI_DATA(PyObject *) PyExc_UnicodeWarning;
+PyAPI_DATA(PyObject *) PyExc_BytesWarning;
 
 
 /* Convenience functions */
Index: Objects/bytesobject.c
===
--- Objects/bytesobject.c	(Revision 58873)
+++ Objects/bytesobject.c	(Arbeitskopie)
@@ -917,6 +917,17 @@
 }
 
 static PyObject *
+bytes_str(PyObject *op)
+{
+	if (Py_BytesWarningFlag) {
+		if (PyErr_WarnEx(PyExc_BytesWarning,
+ "str() on a buffer instance", 1))
+			return NULL;
+	}
+	return bytes_repr((PyBytesObject*)op);
+}
+
+static PyObject *
 bytes_richcompare(PyObject *self, PyObject *other, int op)
 {
 Py_ssize_t self_size, other_size;
@@ -930,6 +941,12 @@
error, even if the comparison is for equality. */
 if (PyObject_IsInstance(self, (PyObject*)&PyUnicode_Type) ||
 PyObject_IsInstance(other, (PyObject*)&PyUnicode_Type)) {
+if (Py_BytesWarningFlag && op == Py_EQ) {
+if (PyErr_WarnEx(PyExc_BytesWarning,
+"Comparsion between buffer and string", 1))
+return NULL;
+}
+
 Py_INCREF(Py_NotImplemented);
 return Py_NotImplemented;
 }
@@ -3082,7 +3099,7 @@
 &bytes_as_mapping,  /* tp_as_mapping */
 0,  /* tp_hash */
 0,  /* tp_call */
-(reprfunc)bytes_repr,   /* tp_str */
+bytes_str,  /* tp_str */
 PyObject_GenericGetAttr,/* tp_getattro */
 0,  /* tp_setattro */
 &bytes_as_buffer,   /* tp_as_buffer */
Index: Objects/exceptions.c
===
--- Objects/exceptions.c	(Revision 58873)
+++ Objects/exceptions.c	(Arbeitskopie)
@@ -1740,7 +1740,15 @@
 "Base class for warnings about Unicode related probl

[issue1345] Fix for test_netrc on Windows

2007-11-05 Thread Christian Heimes

Changes by Christian Heimes:


--
keywords: +py3k
resolution:  -> invalid
status: open -> closed
superseder:  -> py3k: duplicated line endings when using read(1)

__
Tracker <[EMAIL PROTECTED]>

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



[issue1392] py3k-pep3137: str(bytes()) and str(buffer()) should raise TypeError patch

2007-11-05 Thread Guido van Rossum

Guido van Rossum added the comment:

> Updates:
> * Added class BytesWarning(Warning)
> * Added -b/-bb command line args and Py_BytesWarningFlag
> * issue PyErr_WarnEx(PyExc_BytesWarning) when Py_BytesWarningFlag is set.
> * Added warning filter for BytesWarning that raises an exception if
> Py_BytesWarningFlag > 1
>
> Open questions:
> * the warning filter isn't set when the initializer cannot load the
> warning module (e.g. frozen apps). W/o the warning module Python is
> screwed anyway and frozen apps would never add the -b argument.
> * the warnings are only enabled with -b. They can't be enabled by
> modifying the warnings.filters. Is this fine with you?

Yes, this is is all fine with me. Feel free to submit overnight.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1395] py3k: duplicated line endings when using read(1)

2007-11-05 Thread Raghuram Devarakonda

Raghuram Devarakonda added the comment:

I think the solution is to do the translation on a bigger chunk than on
the string being returned in each read call. For example, the following
patch correctly returns "a" and "\n" (instead of "a" and two "\n"s). 

Index: Lib/io.py
===
--- Lib/io.py   (revision 58874)
+++ Lib/io.py   (working copy)
@@ -1253,8 +1253,9 @@
 res += pending
 if not readahead:
 break
+res = self._replacenl(res)
 self._pending = res[n:]
-return self._replacenl(res[:n])
+return res[:n]

 def __next__(self):
 self._telling = False

-

Of course, we need to take care of the case when the last character in
"res" is "\r" to be followed by "\n" in the next read. I just wanted to
see if I am on the right track and if so, I can spend more time on this.

--
nosy: +draghuram

__
Tracker <[EMAIL PROTECTED]>

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



[issue1394] simple patch, improving unreachable bytecode removing

2007-11-05 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



[issue1385] hmac module violates RFC for some hash functions, e.g. sha512

2007-11-05 Thread Georg Brandl

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