[issue1307] smtpd.SMTPServer throws exception on MAIL command with no arg

2007-10-21 Thread Georg Brandl

Changes by Georg Brandl:


--
keywords: +patch

__
Tracker <[EMAIL PROTECTED]>

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



[issue1267] Py3K cannot run as ``python -S``

2007-10-21 Thread Guido van Rossum

Guido van Rossum added the comment:

Do you have access to Windows? I believe it doesn't have dup(). :-(

__
Tracker <[EMAIL PROTECTED]>

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



[issue1263] PEP 3137 patch - str8/str comparison should return false

2007-10-21 Thread Guido van Rossum

Guido van Rossum added the comment:

> Guido, what do you want to do about the struct module for the various
> string formats (i.e., c, s, p)?  Should they return str8 or Unicode?

Oh, tough call. I think they should return str8 (i.e. bytes after the
rename) because the encoding isn't known. Even though this will break
more code, since I'm sure there's lots of code out there that assumes
they return "text".

__
Tracker <[EMAIL PROTECTED]>

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



[issue1267] Py3K cannot run as ``python -S``

2007-10-21 Thread Christian Heimes

Christian Heimes added the comment:

Guido van Rossum wrote:
> Guido van Rossum added the comment:
> 
> Do you have access to Windows? I believe it doesn't have dup(). :-(

I've an old laptop with Win2k at my disposal but it has no VS yet. Can
you point me to a set of instruction how to install VS 2003? I've just
VS .NET 2005 available.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1267] Py3K cannot run as ``python -S``

2007-10-21 Thread Guido van Rossum

Guido van Rossum added the comment:

> > Do you have access to Windows? I believe it doesn't have dup(). :-(
>
> I've an old laptop with Win2k at my disposal but it has no VS yet. Can
> you point me to a set of instruction how to install VS 2003? I've just
> VS .NET 2005 available.

Sorry, I'm as green as you when it comes to these. :-(

But I believe I was mistaken about dup() not existing on Windows;
dup() can't be used to duplicate sockets, but that's irrelevant here.
So the dup()-based solution is fine.

Alas, my family won't let me use the computer for more than a minute
at a time today, so I won't be able to review any code... :-)

__
Tracker <[EMAIL PROTECTED]>

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



[issue1745035] DoS smtpd vulnerability

2007-10-21 Thread billiejoex

billiejoex added the comment:

> What does this do when a line longer than 4096 bytes 
> is found?  Does it report an error to the SMTP client?  
> That's my only concern.

Sorry for replying so late. 
No, it does not report the error and this is bad.
I've searched through RFCs and I found that RFC 821 and RFC 2821 at
chapter 4.2.2 say that a 500 "Syntax error, command unrecognized"
response could be used to report errors such as command lines too long.

Modified smtpd.py in attachment. It should be definitively fine for
inclusion now.

--
severity: normal -> urgent
type:  -> security
Added file: http://bugs.python.org/file8586/smtpd.py

_
Tracker <[EMAIL PROTECTED]>

_#! /usr/bin/env python
"""An RFC 2821 smtp proxy.

Usage: %(program)s [options] [localhost:localport [remotehost:remoteport]]

Options:

--nosetuid
-n
This program generally tries to setuid `nobody', unless this flag is
set.  The setuid call will fail if this program is not run as root (in
which case, use this flag).

--version
-V
Print the version number and exit.

--class classname
-c classname
Use `classname' as the concrete SMTP proxy class.  Uses `PureProxy' by
default.

--debug
-d
Turn on debugging prints.

--help
-h
Print this message and exit.

Version: %(__version__)s

If localhost is not given then `localhost' is used, and if localport is not
given then 8025 is used.  If remotehost is not given then `localhost' is used,
and if remoteport is not given, then 25 is used.
"""


# Overview:
#
# This file implements the minimal SMTP protocol as defined in RFC 821.  It
# has a hierarchy of classes which implement the backend functionality for the
# smtpd.  A number of classes are provided:
#
#   SMTPServer - the base class for the backend.  Raises NotImplementedError
#   if you try to use it.
#
#   DebuggingServer - simply prints each message it receives on stdout.
#
#   PureProxy - Proxies all messages to a real smtpd which does final
#   delivery.  One known problem with this class is that it doesn't handle
#   SMTP errors from the backend server at all.  This should be fixed
#   (contributions are welcome!).
#
#   MailmanProxy - An experimental hack to work with GNU Mailman
#   .  Using this server as your real incoming smtpd, your
#   mailhost will automatically recognize and accept mail destined to Mailman
#   lists when those lists are created.  Every message not destined for a list
#   gets forwarded to a real backend smtpd, as with PureProxy.  Again, errors
#   are not handled correctly yet.
#
# Please note that this script requires Python 2.0
#
# Author: Barry Warsaw <[EMAIL PROTECTED]>
#
# TODO:
#
# - support mailbox delivery
# - alias files
# - ESMTP
# - handle error codes from the backend smtpd

import sys
import os
import errno
import getopt
import time
import socket
import asyncore
import asynchat

__all__ = ["SMTPServer","DebuggingServer","PureProxy","MailmanProxy"]

program = sys.argv[0]
__version__ = 'Python SMTP proxy version 0.2'


class Devnull:
def write(self, msg): pass
def flush(self): pass


DEBUGSTREAM = Devnull()
NEWLINE = '\n'
EMPTYSTRING = ''
COMMASPACE = ', '



def usage(code, msg=''):
print >> sys.stderr, __doc__ % globals()
if msg:
print >> sys.stderr, msg
sys.exit(code)



class SMTPChannel(asynchat.async_chat):
COMMAND = 0
DATA = 1

def __init__(self, server, conn, addr):
asynchat.async_chat.__init__(self, conn)
self.__server = server
self.__conn = conn
self.__addr = addr
self.__line = []
self.__in_buffer_len = 0
self.__state = self.COMMAND
self.__greeting = 0
self.__mailfrom = None
self.__rcpttos = []
self.__data = ''
self.__fqdn = socket.getfqdn()
self.__peer = conn.getpeername()
print >> DEBUGSTREAM, 'Peer:', repr(self.__peer)
self.push('220 %s %s' % (self.__fqdn, __version__))
self.set_terminator('\r\n')

# Overrides base class for convenience
def push(self, msg):
asynchat.async_chat.push(self, msg + '\r\n')

# Implementation of base class abstract method
def collect_incoming_data(self, data):
self.__line.append(data)
self.__in_buffer_len += len(data)
if self.__in_buffer_len > 998:
self.push('500 Line too long')
self.__line = []
self.__in_buffer_len = 0

# Implementation of base class abstract method
def found_terminator(self):
line = EMPTYSTRING.join(self.__line)
print >> DEBUGSTREAM, 'Data:', repr(line)
self.__line = []
self.__in_buffer_len = 0
if self.__state == self.COMMAND:
if not line:
self.push('500 Error: bad syntax')
retur

[issue1745035] DoS smtpd vulnerability

2007-10-21 Thread billiejoex

Changes by billiejoex:


Added file: http://bugs.python.org/file8587/smtpd.diff

_
Tracker <[EMAIL PROTECTED]>

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



[issue1308] unicode(None) anomaly

2007-10-21 Thread James G. sack (jim)

New submission from James G. sack (jim):

'2.5 (r25:51908, Apr 10 2007, 10:27:40) \n[GCC 4.1.2 20070403 (Red Hat 
4.1.2-8)]'

unicode(None)
u'None'

This doesn't seem right, ;-)

Regards,
,,jim

--
components: Unicode
messages: 56628
nosy: jgsack
severity: normal
status: open
title: unicode(None) anomaly
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



[issue1308] unicode(None) anomaly

2007-10-21 Thread Martin v. Löwis

Martin v. Löwis added the comment:

What answer did you expect instead?

--
nosy: +loewis

__
Tracker <[EMAIL PROTECTED]>

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



[issue1308] unicode(None) anomaly

2007-10-21 Thread James G. sack (jim)

James G. sack (jim) added the comment:

(aside: Wow! that was a fast response to my posting!)

I'm not really sure what makes the most sense,
possibly:
 - an exception
 - u''
 - None

but not u'None'; not a string of length 4. That's quite unexpected!

Regards,
..jim

PS: I don't understand why I couldn't reply via email. I got an autoresponse

  You are not a registered user. Please register at:

http://bugs.python.org/[EMAIL PROTECTED]

...before sending mail to the tracker.

Unknown address: jgsack...

I tried the registration, but that failed. I thought I _was_ registered.

Oh, well. :-[
..jim

__
Tracker <[EMAIL PROTECTED]>

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



[issue1267] Py3K cannot run as ``python -S``

2007-10-21 Thread Guido van Rossum

Changes by Guido van Rossum:


--
resolution: accepted -> 
status: closed -> open

__
Tracker <[EMAIL PROTECTED]>

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



[issue1267] Py3K cannot run as ``python -S``

2007-10-21 Thread Guido van Rossum

Guido van Rossum added the comment:

OK, checked in.

You might want to compare what I checked in to your patch; I did a few
style cleanups.  I also moved the lseek() call into import.c, where it
seems more appropriate.

Committed revision 58587.

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



[issue1309] windows build fix

2007-10-21 Thread Christian Heimes

New submission from Christian Heimes:

bytes_methods.c isn't in PCbuild/pythoncore.vcproj

--
components: Windows
files: py3k_pcbuild_bytes.patch
messages: 56632
nosy: tiran
severity: normal
status: open
title: windows build fix
type: compile error
versions: Python 3.0
Added file: http://bugs.python.org/file8588/py3k_pcbuild_bytes.patch

__
Tracker <[EMAIL PROTECTED]>

__Index: PCbuild/pythoncore.vcproj
===
--- PCbuild/pythoncore.vcproj	(Revision 58587)
+++ PCbuild/pythoncore.vcproj	(Arbeitskopie)
@@ -440,8 +440,11 @@
 			RelativePath="..\Objects\boolobject.c">
 		
 		
+			RelativePath="..\Objects\bytes_methods.c">
 		
+
+
 		
 		
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1267] Py3K cannot run as ``python -S``

2007-10-21 Thread Christian Heimes

Christian Heimes added the comment:

Guido van Rossum wrote:
> You might want to compare what I checked in to your patch; I did a few
> style cleanups.  I also moved the lseek() call into import.c, where it
> seems more appropriate.

Ah I see that you prefer to keep assignment and check against NULL/-1 on
two separate lines.

I had the lseek() in PyTokenizer_FindEncoding() because I prefer
functions that restore their environment. I find it less surprising when
it restores the position of the file descriptor.

By the way I got Windows, VS 2003 and several SDKs installed in VMWare
today. It's annoying and it takes hours. Most unit tests are passing.
http://wiki.python.org/moin/Building_Python_with_the_free_MS_C_Toolkit

__
Tracker <[EMAIL PROTECTED]>

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



[issue1308] unicode(None) anomaly

2007-10-21 Thread James G. sack (jim)

James G. sack (jim) added the comment:

Here's more:

>>> unicode(object)
u""

There seems to be an call to repr() somewhere in the process.

This seems, at least to me, to violate the principle of least surprise, and 
I'm thinking that unicode(x) ought to return UnicodeDecodeError if x is not 
a string. 

Maybe this is argueable. If so, I'd like to be educated. :-)

Regards,
..jim

__
Tracker <[EMAIL PROTECTED]>

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



[issue1302] Fixes for profile/cprofile

2007-10-21 Thread Alexandre Vassalotti

Alexandre Vassalotti added the comment:

I don't think it's possible to add shortcuts in PyUnicode_Decode for
UTF-16 and UTF-32 because the byte-order can be different depending of
the platform. So, these two need to pass through the codecs module.

I am sure if it's better, but I factored out the normalization routine
into its own function.

Added file: http://bugs.python.org/file8589/py3k_profile_fix-3.patch

__
Tracker <[EMAIL PROTECTED]>

__Index: Objects/unicodeobject.c
===
--- Objects/unicodeobject.c	(revision 58587)
+++ Objects/unicodeobject.c	(working copy)
@@ -1049,29 +1049,55 @@
 return NULL;
 }
 
+static char *
+normalize(const char *enc)
+{
+register size_t i;
+size_t len = strlen(enc);
+char *p;
+
+p = PyMem_Malloc(len + 1);
+if (p == NULL)
+return NULL;
+for (i = 0; i < len; i++) {
+register char ch = enc[i];
+if (ch == ' ')
+ch = '-';
+else
+ch = tolower(Py_CHARMASK(ch));
+}
+p[i] = '\0';
+return p;
+}
+
 PyObject *PyUnicode_Decode(const char *s,
-			   Py_ssize_t size,
-			   const char *encoding,
-			   const char *errors)
+   Py_ssize_t size,
+   const char *encoding,
+   const char *errors)
 {
 PyObject *buffer = NULL, *unicode;
 Py_buffer info;
+char *enc;
 
 if (encoding == NULL)
-	encoding = PyUnicode_GetDefaultEncoding();
+encoding = PyUnicode_GetDefaultEncoding();
 
+enc = normalize(encoding);
+
 /* Shortcuts for common default encodings */
-if (strcmp(encoding, "utf-8") == 0)
+if (strcmp(enc, "utf-8") == 0)
 return PyUnicode_DecodeUTF8(s, size, errors);
-else if (strcmp(encoding, "latin-1") == 0)
+else if (strcmp(enc, "latin-1") == 0)
 return PyUnicode_DecodeLatin1(s, size, errors);
 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
-else if (strcmp(encoding, "mbcs") == 0)
+else if (strcmp(enc, "mbcs") == 0)
 return PyUnicode_DecodeMBCS(s, size, errors);
 #endif
-else if (strcmp(encoding, "ascii") == 0)
+else if (strcmp(enc, "ascii") == 0)
 return PyUnicode_DecodeASCII(s, size, errors);
 
+PyMem_Free(enc);
+
 /* Decode via the codec registry */
 buffer = NULL;
 if (PyBuffer_FillInfo(&info, (void *)s, size, 1, PyBUF_SIMPLE) < 0)
Index: Lib/test/regrtest.py
===
--- Lib/test/regrtest.py	(revision 58587)
+++ Lib/test/regrtest.py	(working copy)
@@ -1119,6 +1119,15 @@
 if not os.path.supports_unicode_filenames:
 self.expected.add('test_pep277')
 
+# doctest, profile and cProfile tests fail when the encoding
+# of the filesystem is not built-in, because of the extra calls
+# to the codecs module.
+builtin_enc = ("utf-8", "latin-1", "ascii", "mbcs")
+if sys.getfilesystemencoding().lower() not in builtin_enc:
+self.expected.add('test_profile')
+self.expected.add('test_cProfile')
+self.expected.add('test_doctest')
+
 try:
 from test import test_socket_ssl
 except ImportError:
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1286] fileinput, StringIO, and cStringIO do not support the with protocol

2007-10-21 Thread Alexandre Vassalotti

Alexandre Vassalotti added the comment:

Do you have a use-case for this? In Py3k, I don't think adding support
for the 'with' statement to StringIO makes any sense, since the close()
method does nothing.

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



[issue1302] Fixes for profile/cprofile

2007-10-21 Thread Christian Heimes

Christian Heimes added the comment:

Alexandre Vassalotti wrote:
> I don't think it's possible to add shortcuts in PyUnicode_Decode for
> UTF-16 and UTF-32 because the byte-order can be different depending of
> the platform. So, these two need to pass through the codecs module.

utf-16 and utf-32 are the the names for the native codecs. The explicit
names are e.g. utf-16-be or utf-32-le. The last argument 0 also means
"native byte order".

I used a shorter algorithm to optimize the normalization for the special
cases of the strcmp() shortcuts. Your version is fine but takes several
CPU cycles longer. I don't think it has a large performance impact. ;)

Christian

__
Tracker <[EMAIL PROTECTED]>

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



[issue1310] tempfile breaks on Windows

2007-10-21 Thread Christian Heimes

New submission from Christian Heimes:

tempfile breaks on Windows because exception objectss no longer support
e[0]. The fix is simple and short:

Index: Lib/tempfile.py
===
--- Lib/tempfile.py (Revision 58587)
+++ Lib/tempfile.py (Arbeitskopie)
@@ -201,7 +201,7 @@
 del fp, fd
 return dir
 except (OSError, IOError) as e:
-if e[0] != _errno.EEXIST:
+if e.args[0] != _errno.EEXIST:
 break # no point trying more names in this directory
 pass

--
components: Library (Lib)
messages: 56638
nosy: tiran
severity: normal
status: open
title: tempfile breaks on Windows
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



[issue708374] add offset to mmap

2007-10-21 Thread Travis Oliphant

Travis Oliphant added the comment:

I think this patch can be committed to SVN.  Paul Moore has tested it on
Windows and I (Travis Oliphant) have tested it on UNIX (Mac OS X).  The
patch also includes documentation updates and tests.

--
nosy: +teoliphant


Tracker <[EMAIL PROTECTED]>


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



[issue1308] unicode(None) anomaly

2007-10-21 Thread Martin v. Löwis

Martin v. Löwis added the comment:

Ok. This is not a bug, but by design. unicode(X)==unicode(str(X)) for
most things, and str(X)==repr(X) for most things. repr(None)=='None',
hence the result you see. Closing as invalid.

P.S. To respond via email, you have to add your email address to Your
Details (you need to add all email addresses you want to use as From
addresses).

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



[issue1309] windows build fix

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



[issue1310] tempfile breaks on Windows

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



[issue1308] unicode(None) anomaly

2007-10-21 Thread James G. sack (jim)

James G. sack (jim) added the comment:

Martin v. Löwis wrote:
> Martin v. Löwis added the comment:
> 
> Ok. This is not a bug, but by design. unicode(X)==unicode(str(X)) for
> most things, and str(X)==repr(X) for most things. repr(None)=='None',
> hence the result you see. Closing as invalid.
> 
> P.S. To respond via email, you have to add your email address to Your
> Details (you need to add all email addresses you want to use as From
> addresses).
> 
> --
> resolution:  -> invalid
> status: open -> closed
> 
> __
> Tracker <[EMAIL PROTECTED]>
> 
> __
> 

OK, thanks Martin.

Now that I think about it, I do understand.

My difficulty (and source of my surprise) was in mistakenly thinking of
unicode() as performing a string translation operation (that is, an
operation on strings).

I would now say that it is better thought of as a representation
function quite parallel to the str() function.

With that mindset, there is no surprise.

Thanks again, for your prompt attention and useful replies.

Regards,
..jim

__
Tracker <[EMAIL PROTECTED]>

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