[issue1621] Python should compile with -Wstrict-overflow when using gcc

2007-12-16 Thread Alexandre Vassalotti

Alexandre Vassalotti added the comment:

I compiled Python using gcc 4.3.0 with the -Wstrict-overflow, and that's
the only warning I got:  

Objects/doubledigits.c: In function ‘_PyFloat_Digits’:
Objects/doubledigits.c:313: error: assuming signed overflow does not
occur when assuming that (X + c) < X is always false

I am sure yet how to interpret it, though. It says that the overflow
check is in _PyFloat_Digits(), line 313 is in the function add_big(). It
probably means that add_big() gets inlined. I tried to set
-finline-limit=0, but strangely the overflow warning disappears...

I will try to investigate this further, when I will have a bit more time
in my hands.

--
nosy: +alexandre.vassalotti

__
Tracker <[EMAIL PROTECTED]>

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



[issue1722225] Build on QNX

2007-12-16 Thread Vladimir Konjkov

Vladimir Konjkov added the comment:

willing you implement thread support for qnx6, or may be qnx4?

_
Tracker <[EMAIL PROTECTED]>

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



[issue1636] Execfile unable to take arguments beyond 255!

2007-12-16 Thread Jack Atkinson

Jack Atkinson added the comment:

Error message from ipython console:
In [28]: mibBuilder2 = builder.MibBuilder().loadModules('ADTRAN-TC')
---
   Traceback (most recent call last)

C:\Documents and Settings\Jack Atkinson\ in ()

c:\python25\lib\site-packages\pysnmp\v4\smi\builder.py in
loadModules(self, *mod
Names)
 80 del self.__modPathsSeen[modPath]
 81 raise error.SmiError(
---> 82 'MIB module \"%s\" load error: %s' %
(modPath, why)
 83 )
 84

: MIB module
"c:\python25\lib\site-packages\p
ysnmp\v4\smi\mibs\ADTRAN-TC.py" load error: more than 255 arguments
(ADTRAN-TC.p
y, line 33)


Here's the code that loads it:
try:
execfile(modPath, g)
except StandardError,
why: del self.__modPathsSeen[modPath]
raise error.SmiError( 'MIB module \"%s\" load error: %s' % (modPath, why) )

Added file: http://bugs.python.org/file8968/builder.py

__
Tracker <[EMAIL PROTECTED]>

__# MIB modules loader
import os
from pysnmp.smi import error
try:
import pysnmp_mibs
except ImportError:
pysnmp_mibs = None
from pysnmp import debug

class MibBuilder:
def __init__(self):
self.lastBuildId = self._autoName = 0L
paths = (
os.path.join(os.path.split(error.__file__)[0], 'mibs','instances'),
os.path.join(os.path.split(error.__file__)[0], 'mibs')
)
if os.environ.has_key('PYSNMP_MIB_DIR'):
paths = paths + (
os.path.join(os.path.split(os.environ['PYSNMP_MIB_DIR'])[0]),
)
if pysnmp_mibs:
paths = paths + (
os.path.join(os.path.split(pysnmp_mibs.__file__)[0]),
)
self.mibSymbols = {}
self.__modSeen = {}
self.__modPathsSeen = {}
apply(self.setMibPath, paths)

# MIB modules management

def setMibPath(self, *mibPaths):
self.__mibPaths = map(os.path.normpath, mibPaths)
debug.logger & debug.flagBld and debug.logger('setMibPath: new MIB path 
%s' % (self.__mibPaths,))

def getMibPath(self): return tuple(self.__mibPaths)

def loadModules(self, *modNames):
# Build a list of available modules
if not modNames:
modNames = {}
for mibPath in self.__mibPaths:
try:
for modName in os.listdir(mibPath):
if modName == '__init__.py' or modName[-3:] != '.py':
continue
modNames[modName[:-3]] = None
except OSError:
continue
modNames = modNames.keys()
if not modNames:
raise error.SmiError(
'No MIB module to load at %s' % (self,)
)
for modName in modNames:
for mibPath in self.__mibPaths:
modPath = os.path.join(
mibPath, modName + '.py'
)

debug.logger & debug.flagBld and debug.logger('loadModules: 
trying %s' % modPath)

try:
open(modPath).close()
except IOError, why:
debug.logger & debug.flagBld and debug.logger('loadModules: 
open() %s' % why)
continue

if self.__modPathsSeen.has_key(modPath):
debug.logger & debug.flagBld and debug.logger('loadModules: 
seen %s' % modPath)
continue
else:
self.__modPathsSeen[modPath] = 1

g = { 'mibBuilder': self }

try:
execfile(modPath, g)
except StandardError, why:
del self.__modPathsSeen[modPath]
raise error.SmiError(
'MIB module \"%s\" load error: %s' % (modPath, why)
)

self.__modSeen[modName] = modPath

debug.logger & debug.flagBld and debug.logger('loadModules: 
loaded %s' % modPath)

break

if not self.__modSeen.has_key(modName):
raise error.SmiError(
'MIB file \"%s.py\" not found in search path' % modName
)

return self

def unloadModules(self, *modNames):
if not modNames:
modNames = self.mibSymbols.keys()
for modName in modNames:
if not self.mibSymbols.has_key(modName):
raise error.SmiError(
'No module %s at %s' % (modName, self)
)
self.unexportSymbols(modName)
del self.__modPathsSeen[self.__modSeen[modName]]
del self.__modSeen[modName]

   

[issue1632] email cannot be imported

2007-12-16 Thread Brett Cannon

Brett Cannon added the comment:

I just noticed that the directory you are executing from is Panda3D. 
Did you not download Python directly but are using the one from Panda3D?

__
Tracker <[EMAIL PROTECTED]>

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



[issue1600] str.format() produces different output on different platforms (Py30a2)

2007-12-16 Thread Mark Summerfield

Mark Summerfield added the comment:

On 2007-12-15, Christian Heimes wrote:
> Christian Heimes added the comment:
>
> Mark Summerfield wrote:
> > It seems to me that Python should provide consistent results across
> > platforms wherever possible and that this is a gratuitous inconsistency
> > that makes cross-platform testing less convenient than it need be.
> >
> > I'll take a look at those functions next week.
>
> It should be fixed in the trunk and merged into py3k. 2.6 suffers from
> the same problem.
>
> By the way I have another pending patch which adds consistent handling
> of "nan" and "inf" on all platforms to float.

Hi Christian,

I made two mistakes (that I know of)---(1) I forgot that 'g' format can
produce an exponent string, and (2) I did a wrong calculation to ensure
that I didn't overflow the buffer. (Even with those mistakes Python's
test_float and test_fpformat passed fine, as did my own tests.) Anyway,
here's the fixed and hopefully final block of code. The first correction
affects the first if statement, and the second correction affects the
third if statement.

/* Ensure that the exponent is at least 3 digits,
   providing the buffer is large enough for the extra zeros. */
if (format_char == 'e' || format_char == 'E' ||
format_char == 'g' || format_char == 'G') {
p = buffer;
while (*p && *p != 'e' && *p != 'E')
++p;
if (*p && (*(p + 1) == '-' || *(p + 1) == '+')) {
p += 2;
char *start = p;
int exponent_digit_count = 0;
while (*p && isdigit((unsigned char)*p)) {
++p;
++exponent_digit_count;
}
int zeros = 3 - exponent_digit_count;
if (exponent_digit_count && zeros > 0 &&
start + zeros + exponent_digit_count + 1
< buffer + buf_len) {
p = start;
memmove(p + zeros, p, exponent_digit_count + 1);
int i = 0;
for (; i < zeros; ++i)
*p++ = '0';
}
}
}

I've also attached the complete pystrtod.c file with the corrections.

Added file: http://bugs.python.org/file8967/pystrtod.c

__
Tracker <[EMAIL PROTECTED]>

__/* -*- Mode: C; c-file-style: "python" -*- */

#include 
#include 

/* ascii character tests (as opposed to locale tests) */
#define ISSPACE(c)  ((c) == ' ' || (c) == '\f' || (c) == '\n' || \
 (c) == '\r' || (c) == '\t' || (c) == '\v')
#define ISDIGIT(c)  ((c) >= '0' && (c) <= '9')
#define ISXDIGIT(c) (ISDIGIT(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))


/**
 * PyOS_ascii_strtod:
 * @nptr:the string to convert to a numeric value.
 * @endptr:  if non-%NULL, it returns the character after
 *   the last character used in the conversion.
 * 
 * Converts a string to a #gdouble value.
 * This function behaves like the standard strtod() function
 * does in the C locale. It does this without actually
 * changing the current locale, since that would not be
 * thread-safe.
 *
 * This function is typically used when reading configuration
 * files or other non-user input that should be locale independent.
 * To handle input from the user you should normally use the
 * locale-sensitive system strtod() function.
 *
 * If the correct value would cause overflow, plus or minus %HUGE_VAL
 * is returned (according to the sign of the value), and %ERANGE is
 * stored in %errno. If the correct value would cause underflow,
 * zero is returned and %ERANGE is stored in %errno.
 * If memory allocation fails, %ENOMEM is stored in %errno.
 * 
 * This function resets %errno before calling strtod() so that
 * you can reliably detect overflow and underflow.
 *
 * Return value: the #gdouble value.
 **/
double
PyOS_ascii_strtod(const char *nptr, char **endptr)
{
	char *fail_pos;
	double val = -1.0;
	struct lconv *locale_data;
	const char *decimal_point;
	size_t decimal_point_len;
	const char *p, *decimal_point_pos;
	const char *end = NULL; /* Silence gcc */

	assert(nptr != NULL);

	fail_pos = NULL;

	locale_data = localeconv();
	decimal_point = locale_data->decimal_point;
	decimal_point_len = strlen(decimal_point);

	assert(decimal_point_len != 0);

	decimal_point_pos = NULL;
	if (decimal_point[0] != '.' || 
	decimal_point[1] != 0)
	{
		p = nptr;
		  /* Skip leading space */
		while (ISSPACE(*p))
			p++;

		  /* Skip leading optional sign */
		if (*p == '+' || *p == '-')
			p++;

		while (ISDIGIT(*p))
			p++;

		if (*p == '.')
		{
			decimal_point_pos = p++;

			while (ISDIGIT(*p))
p++;

			if (*p == 'e' || *p == 'E')
p++;
			if (*p == '+' || *p == '-')
p++;
			while (ISDIGIT(*p))
p++;
			end = p;
		}
		else if (strncmp(p, decimal_point, de

[issue1632] email cannot be imported

2007-12-16 Thread Wubbulous

Wubbulous added the comment:

I have attempted the following separately: import email   import 
email.Utilsimport email.utils

they each return the error:
Traceback (most recent call last):

  File "C:\Panda3D-1.4.2\python\lib\smtplib.py", line 49, in ?
from email.base64MIME import encode as encode_base64
ImportError: No module named base64MIME

--
severity: major -> normal

__
Tracker <[EMAIL PROTECTED]>

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



[issue1638] %zd configure test fails on Linux

2007-12-16 Thread Hrvoje Nikšić

Hrvoje Nikšić added the comment:

Thanks for the quick review.  I considered guarding the include with
#ifdef as well, but I concluded it's not necessary for the following
reasons:

1. a large number of existing tests already simply include 
(the makedev test, sizeof(off_t) test, IPv6-related tests, and various
socket tests);

2. if sys/types.h doesn't exist, the test will fail, and Python will
conclude that %zd is not available.  This conclusion is almost certainly
correct, as I doubt that a system without sys/types.h has a working %zd
format.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1638] %zd configure test fails on Linux

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

Martin v. Löwis added the comment:

I think it should be backported.

--
nosy: +loewis

__
Tracker <[EMAIL PROTECTED]>

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



[issue1638] %zd configure test fails on Linux

2007-12-16 Thread Christian Heimes

Christian Heimes added the comment:

I fixed the bug in r59533 trunk with a modified patch:

#ifdef HAVE_SYS_TYPES_H
#include 
#endif

Should it be backported to 2.5? It will be merged into 3.0 automatically.

--
nosy: +tiran
priority:  -> normal
resolution:  -> fixed
status: open -> pending

__
Tracker <[EMAIL PROTECTED]>

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



[issue1638] %zd configure test fails on Linux

2007-12-16 Thread Hrvoje Nikšić

New submission from Hrvoje Nikšić:

The printf("%zd", ...) configure test fails on Linux, although it
supports the %zd format.  config.log reveals that the test tests for %zd
with Py_ssize_t, which is (within the test) typedeffed to ssize_t.  But
the appropriate system header is not included by the test, and ssize_t
is not defined.  This results in Py_ssize_t not being correctly defined,
and the test failing.

According to http://tinyurl.com/3dhbbm/, ssize_t is defined in
.  Adding #include  manually to the test fixes
the test for me.  A patch like the one attached should fix the problem.

--
files: patch
messages: 58675
nosy: hniksic
severity: normal
status: open
title: %zd configure test fails on Linux
versions: Python 2.5
Added file: http://bugs.python.org/file8966/patch

__
Tracker <[EMAIL PROTECTED]>

__

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



[issue1600] str.format() produces different output on different platforms (Py30a2)

2007-12-16 Thread Mark Summerfield

Mark Summerfield added the comment:

On 2007-12-15, Christian Heimes wrote:
> Christian Heimes added the comment:
>
> Mark Summerfield wrote:
> > It seems to me that Python should provide consistent results across
> > platforms wherever possible and that this is a gratuitous inconsistency
> > that makes cross-platform testing less convenient than it need be.
> >
> > I'll take a look at those functions next week.
>
> It should be fixed in the trunk and merged into py3k. 2.6 suffers from
> the same problem.
>
> By the way I have another pending patch which adds consistent handling
> of "nan" and "inf" on all platforms to float.

Hi Christian,

I've added some code to pystrtod.c's PyOS_ascii_formatd() function that
ensures that the exponent is always at least 3 digits, so long as the
buffer passed in has room.

Although I have svn access, this was granted to me by Georg Brandl only
for doing documentation edits, so I don't feel that I can submit code
patches myself---and in any case my C is rusty, so I would prefer my
code was peer reviewed anyway. Would you be willing to add the patch for
me, assuming you are happy with it?

I've attached my modified pystrtod.c and also pystrtod.diff which shows
the diff against Python 30a2. My code is at the end of the function all
in one lump so it is easy to see what I've done. (I've assumed ANSI C,
so have declared some local variables in my code block rather than at
the top of the function: start, exponent_digit_count, and zeros; they
could all be moved if necessary.)

I hope this helps:-)

Added file: http://bugs.python.org/file8964/pystrtod.diff
Added file: http://bugs.python.org/file8965/pystrtod.c

__
Tracker <[EMAIL PROTECTED]>

__*** Python/pystrtod.c	2007-12-16 18:00:29.0 +
--- Python/pystrtod.c.orig	2007-12-16 17:16:30.0 +
***
*** 238,270 
  		}
  	}
  
- /* Ensure that the exponent is at least 3 digits,
- 	   providing the buffer is large enough for the extra zeros. */
- if (format_char == 'e' || format_char == 'E') {
- p = buffer;
- while (*p && *p != 'e' && *p != 'E')
- ++p;
- if (*p && (*(p + 1) == '-' || *(p + 1) == '+')) {
- 		p += 2;
- char *start = p;
- int exponent_digit_count = 0;
- while (*p && isdigit((unsigned char)*p)) {
- ++p;
- ++exponent_digit_count;
- }
- int zeros = 3 - exponent_digit_count;
- if (exponent_digit_count && zeros > 0 &&
- 		p + zeros + exponent_digit_count + 1
- 		< buffer + buf_len) {
- p = start;
- memmove(p + zeros, p, exponent_digit_count + 1);
- int i = 0;
- for (; i < zeros; ++i)
- *p++ = '0';
- }
- }
- }
- 
  	return buffer;
  }
  
--- 238,243 

/* -*- Mode: C; c-file-style: "python" -*- */

#include 
#include 

/* ascii character tests (as opposed to locale tests) */
#define ISSPACE(c)  ((c) == ' ' || (c) == '\f' || (c) == '\n' || \
 (c) == '\r' || (c) == '\t' || (c) == '\v')
#define ISDIGIT(c)  ((c) >= '0' && (c) <= '9')
#define ISXDIGIT(c) (ISDIGIT(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))


/**
 * PyOS_ascii_strtod:
 * @nptr:the string to convert to a numeric value.
 * @endptr:  if non-%NULL, it returns the character after
 *   the last character used in the conversion.
 * 
 * Converts a string to a #gdouble value.
 * This function behaves like the standard strtod() function
 * does in the C locale. It does this without actually
 * changing the current locale, since that would not be
 * thread-safe.
 *
 * This function is typically used when reading configuration
 * files or other non-user input that should be locale independent.
 * To handle input from the user you should normally use the
 * locale-sensitive system strtod() function.
 *
 * If the correct value would cause overflow, plus or minus %HUGE_VAL
 * is returned (according to the sign of the value), and %ERANGE is
 * stored in %errno. If the correct value would cause underflow,
 * zero is returned and %ERANGE is stored in %errno.
 * If memory allocation fails, %ENOMEM is stored in %errno.
 * 
 * This function resets %errno before calling strtod() so that
 * you can reliably detect overflow and underflow.
 *
 * Return value: the #gdouble value.
 **/
double
PyOS_ascii_strtod(const char *nptr, char **endptr)
{
	char *fail_pos;
	double val = -1.0;
	struct lconv *locale_data;
	const char *decimal_point;
	size_t decimal_point_len;
	const char *p, *decimal_point_pos;
	const char *end = NULL; /* Silence gcc */

	assert(nptr != NULL);

	fail_pos = NULL;

	locale_data = localeconv();
	decimal_point = locale_data->decimal_point;
	de

[issue1637] urlparse.urlparse misparses URLs with query but no path

2007-12-16 Thread John Nagle

New submission from John Nagle:

urlparse.urlparse will mis-parse URLs which have a "/" after a "?".
>>
>> sa1 = 'http://example.com?blahblah=/foo'
>> sa2 = 'http://example.com?blahblah=foo'
>> print urlparse.urlparse(sa1)
>> ('http', 'example.com?blahblah=', '/foo', '', '', '') # WRONG
>> print urlparse.urlparse(sa2)
>> ('http', 'example.com', '', '', 'blahblah=foo', '') # RIGHT

That's wrong. RFC3896 ("Uniform Resource Identifier (URI): Generic
Syntax"), page 23 says

"The characters slash ("/") and question mark ("?") may represent data
within the query component.  Beware that some older, erroneous
implementations may not handle such data correctly when it is used as
the base URI for relative references (Section 5.1), apparently
because they fail to distinguish query data from path data when
looking for hierarchical separators."

 So "urlparse" is an "older, erroneous implementation".  Looking
 at the code for "urlparse", it references RFC1808 (1995), which
 was a long time ago, three revisions back.
>>
>> Here's the bad code:
>>
>> def _splitnetloc(url, start=0):
>> for c in '/?#': # the order is important!
>> delim = url.find(c, start)
>> if delim >= 0:
>> break
>> else:
>> delim = len(url)
>> return url[start:delim], url[delim:]
>>
>> That's just wrong.  The domain ends at the first appearance of
>> any character in '/?#', but that code returns the text before the
>> first '/' even if there's an earlier '?'.  A URL/URI doesn't
>> have to have a path, even when it has query parameters. 

OK, here's a fix to "urlparse", replacing _splitnetloc.  I didn't use
a regular expression because "urlparse" doesn't import "re", and I
didn't want to change that.

def _splitnetloc(url, start=0):
delim = len(url)# position of end of domain part of url, default is end
for c in '/?#':# look for delimiters; the order is NOT important   
wdelim = url.find(c, start)# find first of this delim
if wdelim >= 0:# if found
delim = min(delim, wdelim)# use earliest delim position
return url[start:delim], url[delim:]# return (domain, rest)

__
Tracker <[EMAIL PROTECTED]>

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



[issue1637] urlparse.urlparse misparses URLs with query but no path

2007-12-16 Thread John Nagle

Changes by John Nagle:


--
components: Library (Lib)
nosy: nagle
severity: normal
status: open
title: urlparse.urlparse misparses URLs with query but no path
type: behavior
versions: 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



[issue1519638] Unmatched Group issue

2007-12-16 Thread Brandon Mintern

Brandon Mintern added the comment:

This is still a problem which has just given me a headache, because
using re.sub now requires gymnastics instead of just using a simple
string as I did in Perl.

--
nosy: +BMintern

_
Tracker <[EMAIL PROTECTED]>

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



[issue1636] Execfile unable to take arguments beyond 255!

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

Martin v. Löwis added the comment:

Can you please be more specific? What code exactly are you executing,
and what is the exact error message that you get?

In the entire Python source code, the error message "Execfile unable to
take arguments beyond 255!" is never produced. Very few error messages
in Python include an exclamation mark at all.

--
nosy: +loewis

__
Tracker <[EMAIL PROTECTED]>

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