[issue1244] Error on 'raise' does not show correct line number and Traceback message

2007-10-08 Thread Georg Brandl

Georg Brandl added the comment:

The raise statement without any arguments re-raises the last raised
exception, complete with traceback, see
http://docs.python.org/dev/reference/simple_stmts.html#the-raise-statement. 

Therefore your usage of the raise statement is incorrect; you should
always use

raise SomeException("some message")

--
nosy: +georg.brandl
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



[issue1244] Error on 'raise' does not show correct line number and Traceback message

2007-10-08 Thread Alexander Shirokov

Alexander Shirokov added the comment:

Dear Georg,

Thank you for reply. Sorry, I thought it was a real bug.

Best Regards,
Alex

On Mon, 8 Oct 2007, Georg Brandl wrote:

>
> Georg Brandl added the comment:
>
> The raise statement without any arguments re-raises the last raised
> exception, complete with traceback, see
> http://docs.python.org/dev/reference/simple_stmts.html#the-raise-statement.
>
> Therefore your usage of the raise statement is incorrect; you should
> always use
>
> raise SomeException("some message")
>
> --
> nosy: +georg.brandl
> resolution:  -> invalid
> status: open -> closed
>
> __
> 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



[issue1245] Document PySys_* API functions

2007-10-08 Thread Georg Brandl

Georg Brandl added the comment:

To generalize, almost all public PySys_* functions aren't documented yet.

--
nosy: +georg.brandl
title: Document PySys_GetObject() -> Document PySys_* API functions

__
Tracker <[EMAIL PROTECTED]>

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



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

2007-10-08 Thread Georg Brandl

Georg Brandl added the comment:

This should now be fixed in r58368.

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



[issue1226] lib/sched.py superfluous code for removal

2007-10-08 Thread Georg Brandl

Georg Brandl added the comment:

Done as part of r58369.

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



[issue1243] option.dest not set when callback called with optparse

2007-10-08 Thread Chris Withers

Chris Withers added the comment:

I'm not sure I fully understand where the fix should go but I'll put a
note in to look into this.

In the meantime, a good workaround is to supply an explicit destination:

parser.add_option('--myopt',action='callback',callback=mycallback,dest='myopt')

__
Tracker <[EMAIL PROTECTED]>

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



[issue1228] 3.0 tutorial/datastructures.rst patch

2007-10-08 Thread Georg Brandl

Georg Brandl added the comment:

Applied in r58375, thanks!

--
nosy: +georg.brandl
resolution:  -> accepted
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



[issue1199] Documentation for tp_as_number... version 2.6

2007-10-08 Thread Georg Brandl

Georg Brandl added the comment:

Committed as r58376.

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



[issue1243] option.dest not set when callback called with optparse

2007-10-08 Thread Raghuram Devarakonda

Raghuram Devarakonda added the comment:

I have never used callbacks but went through the docs/code and I am not
sure if there is a bug here. 

_check_dest() creates 'dest' only if 'type' is specified for the
'callback' option. With callbacks, it can not guess the type as there is
no 'store' action. The document does say that without 'type', optparse
does not know how many arguments to consume. I added 'type' to your
example add_option() and all is well. 

Please correct me if I am missing some thing here.

--
nosy: +draghuram

__
Tracker <[EMAIL PROTECTED]>

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



[issue1243] option.dest not set when callback called with optparse

2007-10-08 Thread Chris Withers

Chris Withers added the comment:

But what type should I specify?

I was using a callback to get a datetime object as an option...

__
Tracker <[EMAIL PROTECTED]>

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



[issue1243] option.dest not set when callback called with optparse

2007-10-08 Thread Raghuram Devarakonda

Raghuram Devarakonda added the comment:

>
> But what type should I specify?
>
> I was using a callback to get a datetime object as an option...
>

If you are looking for a new type of option than what are already
supported (string, int, long, choice, float and complex), you need to
extend optparse (there is a section for that). I personally prefer a
simple approach where the option value is taken as a string and any
processing is done on the value to convert to what ever type of object
one wants. For example, in this case, you can convert a string, say,
2007-10-8, internally to a datetime object.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1247] PEP 3137 patch (repr, names, parser)

2007-10-08 Thread Christian Heimes

New submission from 
Christian Heimes
:

The patches changes:

- change PyString's repr() to return "b'...'"
- change PyBytes's repr() to return "buffer(b'...')"
- change parser so that b"..." returns PyString, not PyBytes
- rename bytes -> buffer, str8 -> bytes

The patch breaks some unit test because some of the infrastructure like
the new buffer() isn't in place yet. I'm not happy with bytes_repr() but
the for loop with *p++ was the easiest way to implement it. Every other
implementation I could think of was either too complicated or wouldn't
work (like memcpy).

--
components: Interpreter Core
files: pep3137.patch
messages: 56280
nosy: tiran
severity: major
status: open
title: PEP 3137 patch (repr, names, parser)
versions: Python 3.0

__
Tracker <[EMAIL PROTECTED]>

__Index: Python/compile.c
===
--- Python/compile.c	(revision 58324)
+++ Python/compile.c	(working copy)
@@ -787,8 +787,6 @@
 			return 1-oparg;
 		case BUILD_MAP:
 			return 1;
-		case MAKE_BYTES:
-			return 0;
 		case LOAD_ATTR:
 			return 0;
 		case COMPARE_OP:
@@ -3222,7 +3220,6 @@
 		break;
 	case Bytes_kind:
 		ADDOP_O(c, LOAD_CONST, e->v.Bytes.s, consts);
-		ADDOP(c, MAKE_BYTES);
 		break;
 	case Ellipsis_kind:
 		ADDOP_O(c, LOAD_CONST, Py_Ellipsis, consts);
Index: Objects/bytesobject.c
===
--- Objects/bytesobject.c	(revision 58324)
+++ Objects/bytesobject.c	(working copy)
@@ -889,9 +889,12 @@
 bytes_repr(PyBytesObject *self)
 {
 static const char *hexdigits = "0123456789abcdef";
-size_t newsize = 3 + 4 * Py_Size(self);
+static const char *quote_prefix = "buffer(b'";
+static const char *quote_postfix = "')";
+/* 9 prefix + 2 postfix */
+size_t newsize = 11 + 4 * Py_Size(self);
 PyObject *v;
-if (newsize > PY_SSIZE_T_MAX || newsize / 4 != Py_Size(self)) {
+if (newsize > PY_SSIZE_T_MAX || (newsize-11) / 4 != Py_Size(self)) {
 PyErr_SetString(PyExc_OverflowError,
 "bytes object is too large to make repr");
 return NULL;
@@ -904,17 +907,17 @@
 register Py_ssize_t i;
 register Py_UNICODE c;
 register Py_UNICODE *p;
-int quote = '\'';
 
 p = PyUnicode_AS_UNICODE(v);
-*p++ = 'b';
-*p++ = quote;
+for (i=0; i= 5);
 c = self->ob_bytes[i];
-if (c == quote || c == '\\')
+if (c == '\'' || c == '\\')
 *p++ = '\\', *p++ = c;
 else if (c == '\t')
 *p++ = '\\', *p++ = 't';
@@ -934,7 +937,9 @@
 *p++ = c;
 }
 assert(newsize - (p - PyUnicode_AS_UNICODE(v)) >= 1);
-*p++ = quote;
+for (i=0; i PY_SSIZE_T_MAX || newsize / 4 != Py_Size(op)) {
+	if (newsize > PY_SSIZE_T_MAX || (newsize-3) / 4 != Py_Size(op)) {
 		PyErr_SetString(PyExc_OverflowError,
 			"string is too large to make repr");
 	}
@@ -803,7 +803,7 @@
 			;
 		}
 
-		*p++ = 's', *p++ = quote;
+		*p++ = 'b', *p++ = quote;
 		for (i = 0; i < Py_Size(op); i++) {
 			/* There's at least enough room for a hex escape
 			   and a closing quote. */
@@ -875,7 +875,7 @@
 if (PyBytes_Check(bb))
 			return PyBytes_Concat((PyObject *)a, bb);
 		PyErr_Format(PyExc_TypeError,
-			 "cannot concatenate 'str8' and '%.200s' objects",
+			 "cannot concatenate 'bytes' and '%.200s' objects",
 			 Py_Type(bb)->tp_name);
 		return NULL;
 	}
@@ -3091,7 +3091,7 @@
 goto onError;
 if (!PyBytes_Check(v)) {
 PyErr_Format(PyExc_TypeError,
- "[str8] encoder did not return a bytes object "
+ "[bytes] encoder did not return a bytes object "
  "(type=%.400s)",
  Py_Type(v)->tp_name);
 Py_DECREF(v);
@@ -3865,7 +3865,7 @@
 
 PyTypeObject PyString_Type = {
 	PyVarObject_HEAD_INIT(&PyType_Type, 0)
-	"str8",
+	"bytes",
 	sizeof(PyStringObject),
 	sizeof(char),
  	string_dealloc, 			/* tp_dealloc */
Index: Lib/pickletools.py
===
--- Lib/pickletools.py	(revision 58324)
+++ Lib/pickletools.py	(working copy)
@@ -272,7 +272,7 @@
 >>> read_stringnl(io.BytesIO(b"\n"))
 Traceback (most recent call last):
 ...
-ValueError: no string quotes around b''
+ValueError: no string quotes around buffer(b'')
 
 >>> read_stringnl(io.BytesIO(b"\n"), stripquotes=False)
 ''
@@ -493,7 +493,7 @@
 >>> read_decimalnl_short(io.BytesIO(b"1234L\n56"))
 Traceback (most recent call last):
 ...
-ValueError: trailing 'L' not allowed in b'1234L'
+ValueError: trailing 'L' not allowed in buffer(b'1234L')
 """
 
 s = read_stringnl(f, decode=False, stripquotes=False)
Ind

[issue1247] PEP 3137 patch (repr, names, parser)

2007-10-08 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



[issue1248] ftplib needs a rewrite to use bytes/buffers

2007-10-08 Thread Brett Cannon

New submission from Brett Cannon:

For instance, ftplib.FTP reads from sockets using socket.makefile(), but
in text mode.  That's bad when the data could be in the format of ASCII
or binary data.

--
components: Library (Lib)
keywords: py3k
messages: 56281
nosy: brett.cannon
priority: normal
severity: major
status: open
title: ftplib needs a rewrite to use bytes/buffers
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



[issue1247] PEP 3137 patch (repr, names, parser)

2007-10-08 Thread Alexandre Vassalotti

Alexandre Vassalotti added the comment:

I am not sure how the parser work, so I can't comment if your change to
it is correct. It would probably a better idea to keep it for later,
when the semantic differences between str8 and bytes objects will be
resolved.

I think changing b'' to buffer(b''), in the tests, is not a good idea.
These tests will need to be changed again when bytes() will be changed
to str8().

Your changes to PyString and PyBytes look good to me. As I said on the
mailing list, I think the for-loops in bytes_repr() should be changed to:

while (*quote_prefix)
*p++ = *quote_prefix++;

I attached updated patches with the above change. I also replaced
bytes() for buffer() in PyBytes's docstrings.

--
nosy: +alexandre.vassalotti

__
Tracker <[EMAIL PROTECTED]>

__Index: Objects/bytesobject.c
===
--- Objects/bytesobject.c	(revision 58376)
+++ Objects/bytesobject.c	(working copy)
@@ -395,7 +395,7 @@
 if (i < 0)
 i += Py_Size(self);
 if (i < 0 || i >= Py_Size(self)) {
-PyErr_SetString(PyExc_IndexError, "bytes index out of range");
+PyErr_SetString(PyExc_IndexError, "buffer index out of range");
 return NULL;
 }
 return PyInt_FromLong((unsigned char)(self->ob_bytes[i]));
@@ -414,7 +414,7 @@
 i += PyBytes_GET_SIZE(self);
 
 if (i < 0 || i >= Py_Size(self)) {
-PyErr_SetString(PyExc_IndexError, "bytes index out of range");
+PyErr_SetString(PyExc_IndexError, "buffer index out of range");
 return NULL;
 }
 return PyInt_FromLong((unsigned char)(self->ob_bytes[i]));
@@ -451,7 +451,7 @@
 }
 }
 else {
-PyErr_SetString(PyExc_TypeError, "bytes indices must be integers");
+PyErr_SetString(PyExc_TypeError, "buffer indices must be integers");
 return NULL;
 }
 }
@@ -551,7 +551,7 @@
 i += Py_Size(self);
 
 if (i < 0 || i >= Py_Size(self)) {
-PyErr_SetString(PyExc_IndexError, "bytes index out of range");
+PyErr_SetString(PyExc_IndexError, "buffer index out of range");
 return -1;
 }
 
@@ -587,7 +587,7 @@
 i += PyBytes_GET_SIZE(self);
 
 if (i < 0 || i >= Py_Size(self)) {
-PyErr_SetString(PyExc_IndexError, "bytes index out of range");
+PyErr_SetString(PyExc_IndexError, "buffer index out of range");
 return -1;
 }
 
@@ -619,7 +619,7 @@
 }
 }
 else {
-PyErr_SetString(PyExc_TypeError, "bytes indices must be integer");
+PyErr_SetString(PyExc_TypeError, "buffer indices must be integer");
 return -1;
 }
 
@@ -889,11 +889,14 @@
 bytes_repr(PyBytesObject *self)
 {
 static const char *hexdigits = "0123456789abcdef";
-size_t newsize = 3 + 4 * Py_Size(self);
+const char *quote_prefix = "buffer(b'";
+const char *quote_postfix = "')";
+/* 9 prefix + 2 postfix */
+size_t newsize = 11 + 4 * Py_Size(self);
 PyObject *v;
-if (newsize > PY_SSIZE_T_MAX || newsize / 4 != Py_Size(self)) {
+if (newsize > PY_SSIZE_T_MAX || (newsize-11) / 4 != Py_Size(self)) {
 PyErr_SetString(PyExc_OverflowError,
-"bytes object is too large to make repr");
+"buffer object is too large to make repr");
 return NULL;
 }
 v = PyUnicode_FromUnicode(NULL, newsize);
@@ -904,17 +907,17 @@
 register Py_ssize_t i;
 register Py_UNICODE c;
 register Py_UNICODE *p;
-int quote = '\'';
 
 p = PyUnicode_AS_UNICODE(v);
-*p++ = 'b';
-*p++ = quote;
+while (*quote_prefix)
+*p++ = *quote_prefix++;
+
 for (i = 0; i < Py_Size(self); i++) {
 /* There's at least enough room for a hex escape
and a closing quote. */
 assert(newsize - (p - PyUnicode_AS_UNICODE(v)) >= 5);
 c = self->ob_bytes[i];
-if (c == quote || c == '\\')
+if (c == '\'' || c == '\\')
 *p++ = '\\', *p++ = c;
 else if (c == '\t')
 *p++ = '\\', *p++ = 't';
@@ -934,7 +937,9 @@
 *p++ = c;
 }
 assert(newsize - (p - PyUnicode_AS_UNICODE(v)) >= 1);
-*p++ = quote;
+while (*quote_postfix) {
+   *p++ = *quote_postfix++;
+}
 *p = '\0';
 if (PyUnicode_Resize(&v, (p - PyUnicode_AS_UNICODE(v {
 Py_DECREF(v);
@@ -2024,7 +2029,7 @@
 PyDoc_STRVAR(replace__doc__,
 "B.replace (old, new[, count]) -> bytes\n\
 \n\
-Return a copy of bytes B with all occurrences of subsection\n\
+Return a copy of B with all occurrences of subsection\n\
 old replaced by new.  If the optional argument count is\n\
 given, only the first count occurrences are replaced.");
 
@@ -2173,9 +2178,9 

[issue1247] PEP 3137 patch (repr, names, parser)

2007-10-08 Thread Alexandre Vassalotti

Changes by Alexandre Vassalotti:


__
Tracker <[EMAIL PROTECTED]>

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



[issue1247] PEP 3137 patch (repr, names, parser)

2007-10-08 Thread Alexandre Vassalotti

Changes by Alexandre Vassalotti:


__
Tracker <[EMAIL PROTECTED]>

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



[issue1631171] implement warnings module in C

2007-10-08 Thread Brett Cannon

Brett Cannon added the comment:

I have uploaded my touched up version of _warnings.c .  I also have a
new diff since the old one did not apply cleanly (test_warnings didn't
get patched nor did PCbuild8).  It also lacked the changes needed to
Modules/config.c .

It is still not complete, though.  Some things are missing from
_warnings.c and test_warnings is completely failing.  But I figured I
should get something uploaded so that other people can help if they want.

_
Tracker <[EMAIL PROTECTED]>

_#include "Python.h"
#include "frameobject.h"

#define MODULE_NAME "_warnings"
#define DEFAULT_ACTION_NAME "default_action"

PyDoc_STRVAR(warnings__doc__,
MODULE_NAME " provides basic warning filtering support.\n"
"It is a helper module to speed up interpreter start-up.");

/* Filters list, also used in warnings.py. */
static PyObject *_filters;  /* List */
static PyObject *_once_registry;  /* Dict */


static int
check_matched(PyObject *obj, PyObject *arg)
{
PyObject *result;
int rc;

if (obj == Py_None)
return 1;
result = PyObject_CallMethod(obj, "match", "O", arg);
if (result == NULL)
return -1;

rc = PyObject_IsTrue(result);
Py_DECREF(result);
return rc;
}

/* The item is a borrowed reference. */
static const char *
get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno,
   PyObject *module, PyObject **item)
{
PyObject *action, *m, *d;
Py_ssize_t i;

if (!PyList_Check(_filters)) {
PyErr_SetString(PyExc_ValueError,
MODULE_NAME ".filters must be a list");
return NULL;
}

/* _filters could change while we are iterating over it. */
for (i = 0; i < PyList_GET_SIZE(_filters); i++) {
PyObject *tmp_item, *action, *msg, *cat, *mod, *ln_obj;
Py_ssize_t ln;
int is_subclass, good_msg, good_mod;

tmp_item = *item = PyList_GET_ITEM(_filters, i);
if (PyTuple_Size(tmp_item) != 5) {
PyErr_Format(PyExc_ValueError,
 MODULE_NAME ".filters item %zd isn't a 5-tuple", i);
return NULL;
}

/* Python code: action, msg, cat, mod, ln = item */
action = PyTuple_GET_ITEM(tmp_item, 0);
msg = PyTuple_GET_ITEM(tmp_item, 1);
cat = PyTuple_GET_ITEM(tmp_item, 2);
mod = PyTuple_GET_ITEM(tmp_item, 3);
ln_obj = PyTuple_GET_ITEM(tmp_item, 4);

good_msg = check_matched(msg, text);
good_mod = check_matched(mod, module);
is_subclass = PyObject_IsSubclass(category, cat);
ln = PyInt_AsSsize_t(ln_obj);
if (good_msg == -1 || good_mod == -1 || is_subclass == -1 ||
(ln == -1 && PyErr_Occurred()))
return NULL;

if (good_msg && is_subclass && good_mod && (ln == 0 || lineno == ln))
return PyString_AsString(action);
}

m = PyImport_ImportModule(MODULE_NAME);
if (m == NULL)
return NULL;
d = PyModule_GetDict(m);
Py_DECREF(m);
if (d == NULL)
return NULL;
action = PyDict_GetItemString(d, DEFAULT_ACTION_NAME);
if (action != NULL)
return PyString_AsString(action);

PyErr_SetString(PyExc_ValueError,
MODULE_NAME "." DEFAULT_ACTION_NAME " not found");
return NULL;
}

static int
already_warned(PyObject *registry, PyObject *key, int should_set)
{
PyObject *already_warned;

if (key == NULL)
return -1;

already_warned = PyDict_GetItem(registry, key);
if (already_warned != NULL) {
int rc = PyObject_IsTrue(already_warned);
if (rc != 0)
return rc;
}

/* This warning wasn't found in the registry, set it. */
if (should_set)
return PyDict_SetItem(registry, key, Py_True);
return 0;
}

/* New reference. */
static PyObject *
normalize_module(PyObject *filename)
{
PyObject *module;
const char *mod_str;
Py_ssize_t len;

int rc = PyObject_IsTrue(filename);
if (rc == -1)
return NULL;
else if (rc == 0)
return PyString_FromString("");

mod_str = PyString_AsString(filename);
if (mod_str == NULL)
return NULL;
len = PyString_Size(filename);
if (len < 0)
return NULL;
if (len >= 3 &&
strncmp(mod_str + (len - 3), ".py", 3) == 0) {
module = PyString_FromStringAndSize(mod_str, len-3);
}
else {
module = filename;
Py_INCREF(module);
}
return module;
}

static int
update_registry(PyObject *registry, PyObject *text, PyObject *category,
int add_zero)
{
PyObject *altkey, *zero = NULL;
int rc;

if (add_zero) {
zero = PyInt_FromLong(0);
if (zero == NULL)
return -1;
altkey = PyTuple_Pack(3, text, category, zero);
}
else
altkey = PyTuple_Pack(2, text, category);

rc = already_warned

[issue1631171] implement warnings module in C

2007-10-08 Thread Brett Cannon

Changes by Brett Cannon:


_
Tracker <[EMAIL PROTECTED]>

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