[issue1442] pythonstartup addition of minor error checking

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



[issue1432] Strange behavior of urlparse.urljoin

2007-11-14 Thread Senthil

Senthil added the comment:

Not really.
RFC 1808, on which urlparse module is based, defines the following for
the PATH component when joining the relative URL to Base URL.


   Step 6: The last segment of the base URL's path (anything
   following the rightmost slash "/", or the entire path if no
   slash is present) is removed and the embedded URL's path is
   appended in its place. 

So, what is happening is As per design and as per RFC1808. This bug
report can be closed as Working as designed.

--
nosy: +orsenthil

__
Tracker <[EMAIL PROTECTED]>

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



[issue1134] Parsing a simple script eats all of your memory

2007-11-14 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc added the comment:

fp_readl is indeed broken in several ways:
- decoding_buffer should be reset to NULL when all data has been read
(buflen <= size).
- the (buflen > size) case will cause an error on the next pass, since
the function cannot handle PyBytesObject.

IOW, the function is always wrong ;-)

I have a correction ready (jafo's patch already addresses the first
case), but cannot access svn here. I will try to provide a patch + test
cases later tonight.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1134] Parsing a simple script eats all of your memory

2007-11-14 Thread Viktor Ferenczi

Viktor Ferenczi added the comment:

In response to Guido:

According to pythonmeister's post (2007-09-10):

"Same under Linux with Python 3.0a1.
Eats all cpu + memory"

I found the bug with this version:

[EMAIL PROTECTED]:~$ python3.0 --version
Python 3.0a1

AFAIK it is the latest alpha released.
I did not try the SVN trunk, but may be
buggy with high probability, since this
issue has not been closed yet.

Viktor (complex)

__
Tracker <[EMAIL PROTECTED]>

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



[issue1432] Strange behavior of urlparse.urljoin

2007-11-14 Thread yan

yan added the comment:

Not really, it's just for PATH component. But the QUERY and PARAMETER
are not the same.
just check the RFC1808. 
5.1. Normal Examples
Base: http://a/b/c/d;p?q#f>
?y = http://a/b/c/d;p?y>
;x = http://a/b/c/d;x>

__
Tracker <[EMAIL PROTECTED]>

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



[issue1442] pythonstartup addition of minor error checking

2007-11-14 Thread Christian Heimes

Christian Heimes added the comment:

Good idea!

Errors in the startup file are already reported by PyRun_*

--
nosy: +tiran
priority:  -> low
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



[issue1442] pythonstartup addition of minor error checking

2007-11-14 Thread Christian Heimes

Christian Heimes added the comment:

I've a far better patch that uses Python's infrastructure to report the
error:

Index: Modules/main.c
===
--- Modules/main.c  (Revision 58966)
+++ Modules/main.c  (Arbeitskopie)
@@ -132,6 +132,16 @@
(void) PyRun_SimpleFileExFlags(fp, startup, 0, cf);
PyErr_Clear();
fclose(fp);
+   } else {
+   int save_errno;
+
+   save_errno = errno;
+   PySys_WriteStderr("Could not open PYTHONSTARTUP\n");
+   errno = save_errno;
+   PyErr_SetFromErrnoWithFilename(PyExc_IOError,
+   startup);
+   PyErr_Print();
+   PyErr_Clear();
}
}
 }


$ ./python
Python 3.0a1+ (py3k:58966M, Nov 14 2007, 17:17:06)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Could not open PYTHONSTARTUP
IOError: [Errno 2] No such file or directory:
'/home/heimes/.python/startup.py'
>>>  

Fixed in r58969 (py3k)

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



[issue1440] Checks for PySys_GetObject("std???") == Py_None

2007-11-14 Thread Guido van Rossum

Guido van Rossum added the comment:

The patch looks okay, but I just thought of something -- why not make
sys.stdout and friends be undefined (i.e. NULL) instead of setting them
to None?  That way this patch isn't necessary and you only need one
small change to builtin_print() -- which you need anyway (Try deleting
sys.stdout and then printing something.)

__
Tracker <[EMAIL PROTECTED]>

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



[issue1439] proposed 3000 patch for socket.py - "socket GC worries"

2007-11-14 Thread Guido van Rossum

Guido van Rossum added the comment:

Crys, can you test this on Windows and if it does, assign back to me?

--
assignee: gvanrossum -> tiran
nosy: +tiran

__
Tracker <[EMAIL PROTECTED]>

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



[issue1378] fromfd() and dup() for _socket on WIndows

2007-11-14 Thread Guido van Rossum

Guido van Rossum added the comment:

Never mind. I must've searched for fromdf.  Crys, I think this is good
to go into 2.6 and be merged into 3.0.  Then in 3.0 we can simplify Bill
Janssen's patch further.

--
assignee:  -> tiran

__
Tracker <[EMAIL PROTECTED]>

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



[issue619475] C3 MRO algorithm implementation

2007-11-14 Thread Guido van Rossum

Guido van Rossum added the comment:

BTW for reference, see http://www.python.org/download/releases/2.3/mro/


Tracker <[EMAIL PROTECTED]>


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



[issue1378] fromfd() and dup() for _socket on WIndows

2007-11-14 Thread Guido van Rossum

Guido van Rossum added the comment:

I'd like to see this applied, HOWEVER I'm confused.  I don't see any
mention of fromfd in the patch except in a comment.  Now, in 3.0,
fromfd() is implemented in socket.py using os.dup(); but in 2.6 i don't
see it there either.  What's going in?

I am hoping that this will help issue 1439 along as well.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1440] Checks for PySys_GetObject("std???") == Py_None

2007-11-14 Thread Guido van Rossum

Guido van Rossum added the comment:

Go for it.

On Nov 14, 2007 10:39 AM, Christian Heimes <[EMAIL PROTECTED]> wrote:
>
> Christian Heimes added the comment:
>
> Guido van Rossum wrote:
> > The patch looks okay, but I just thought of something -- why not make
> > sys.stdout and friends be undefined (i.e. NULL) instead of setting them
> > to None?  That way this patch isn't necessary and you only need one
> > small change to builtin_print() -- which you need anyway (Try deleting
> > sys.stdout and then printing something.)
>
> I prefer "if sys.stdout is None" over "if hasattr(sys, 'stdout'):" and
> "sys.stdout = None" over "del sys.stdout". I can't put words to it but
> it feels more natural to set the stream to None (NULL) than to
> incinerate the stream.
>
> IMO the problem warrants a short poll at Python 3000 dev.
>
> Christian
>
>
> __
> 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



[issue1378] fromfd() and dup() for _socket on WIndows

2007-11-14 Thread Christian Heimes

Christian Heimes added the comment:

Neal, Thomas, what do you think about the patch? Your knowledge of the
Windows API is greater than mine. Is the duplicate_socket() function ok?
I don't want to apply a patch I don't fully understand.

+#ifdef MS_WINDOWS
+/* On Windows a socket is really a handle not an fd */
+static SOCKET
+duplicate_socket(SOCKET handle)
+{
+   HANDLE newhandle;
+
+   if (!DuplicateHandle(GetCurrentProcess(), (HANDLE)handle,
+GetCurrentProcess(), &newhandle,
+0, FALSE, DUPLICATE_SAME_ACCESS))
+   {
+   WSASetLastError(WSAEBADF);
+   return INVALID_SOCKET;
+   }
+   return (SOCKET)newhandle;
+}
+#define dup(fd) duplicate_socket(fd)
+#define SOCKETCLOSE closesocket
+#define NO_MAKEFILE /* socket handles can't be treated like file handles */
+#endif

--
nosy: +nnorwitz, theller

__
Tracker <[EMAIL PROTECTED]>

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



[issue1401] urllib2 302 POST

2007-11-14 Thread Jim Jewett

Jim Jewett added the comment:

> But you said that #2 solution was more RFC compliant... 
> Could you please quote the RFC part that describes this behaviour?

RFD2616
http://www.faqs.org/rfcs/rfc2616.html

section 4.3 Message Body ...

   The presence of a message-body in a request is signaled by the
   inclusion of a Content-Length or Transfer-Encoding header field in
   the request's message-headers. A message-body MUST NOT be included in
   a request if the specification of the request method (section 5.1.1)
   does not allow sending an entity-body in requests.

[I couldn't actually find a quote saying that GET has no body, but ... it 
doesn't.]

Section 10.3 Redirection 3xx says 

   The action
   required MAY be carried out by the user agent without interaction
   with the user if and only if the method used in the second request is
   GET or HEAD.

In other words, changing it to GET may not be quite pure, but leaving it as 
POST would technically mean that the user MUST confirm that the redirect is 
OK.  This MUST NOT becomes more explicit later, such as in 10.3.2 (301 Moved 
Permanently).  Section 10.3.3 (302 Found) says that 307 was added 
specifically to insist on keeping it a POST, and even 307 says it MUST NOT 
automatically redirect unless it can be confirmed by the user.

Which is why user agents change redirects to a GET and try that...

--
components: +XML -None
nosy: +jimjjewett

__
Tracker <[EMAIL PROTECTED]>

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



[issue1440] Checks for PySys_GetObject("std???") == Py_None

2007-11-14 Thread Christian Heimes

Christian Heimes added the comment:

Guido van Rossum wrote:
> The patch looks okay, but I just thought of something -- why not make
> sys.stdout and friends be undefined (i.e. NULL) instead of setting them
> to None?  That way this patch isn't necessary and you only need one
> small change to builtin_print() -- which you need anyway (Try deleting
> sys.stdout and then printing something.)

I prefer "if sys.stdout is None" over "if hasattr(sys, 'stdout'):" and
"sys.stdout = None" over "del sys.stdout". I can't put words to it but
it feels more natural to set the stream to None (NULL) than to
incinerate the stream.

IMO the problem warrants a short poll at Python 3000 dev.

Christian

__
Tracker <[EMAIL PROTECTED]>

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



[issue1443] Magic class member variable initialization with lists

2007-11-14 Thread neoone

New submission from neoone:

Initialization of member variables with lists leads to strange 
behavior.

The list object is common to each instance of that class.

File attached results in:
[] [] <__main__.Proof instance at 0x00BA7120>
['STICKYARRAY'] [] <__main__.Proof instance at 0x00BA7148>

So the initialized list a is the same in both instances.
Behaviour has been tested on 2.3 and 2.5

--
components: Interpreter Core
files: test.py
messages: 57500
nosy: neoone
severity: normal
status: open
title: Magic class member variable initialization with lists
type: behavior
versions: Python 2.5
Added file: http://bugs.python.org/file8745/test.py

__
Tracker <[EMAIL PROTECTED]>

__

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



[issue1439] proposed 3000 patch for socket.py - "socket GC worries"

2007-11-14 Thread Christian Heimes

Christian Heimes added the comment:

Hi Janssen!

The patch at http://bugs.python.org/issue1378 adds suport for
_socket.socket.dup() on Windows. It can't dup file descriptors but it
can dup socket handlers. Would it make your patch easier?

__
Tracker <[EMAIL PROTECTED]>

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



[issue1378] fromfd() and dup() for _socket on WIndows

2007-11-14 Thread Thomas Heller

Thomas Heller added the comment:

Christian Heimes schrieb:
> Neal, Thomas, what do you think about the patch? Your knowledge of the
> Windows API is greater than mine. Is the duplicate_socket() function ok?
> I don't want to apply a patch I don't fully understand.
> 
> +#ifdef MS_WINDOWS
> +/* On Windows a socket is really a handle not an fd */
> +static SOCKET
> +duplicate_socket(SOCKET handle)
> +{
> +   HANDLE newhandle;
> +
> +   if (!DuplicateHandle(GetCurrentProcess(), (HANDLE)handle,
> +GetCurrentProcess(), &newhandle,
> +0, FALSE, DUPLICATE_SAME_ACCESS))
> +   {
> +   WSASetLastError(WSAEBADF);
> +   return INVALID_SOCKET;
> +   }
> +   return (SOCKET)newhandle;
> +}
> +#define dup(fd) duplicate_socket(fd)
> +#define SOCKETCLOSE closesocket
> +#define NO_MAKEFILE /* socket handles can't be treated like file handles */
> +#endif

Not much time, so only one comment:
Is it wise to call WSASetLastError(WSAEBADF) instead of calling GetLastError()?

Thomas

__
Tracker <[EMAIL PROTECTED]>

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



[issue1378] fromfd() and dup() for _socket on WIndows

2007-11-14 Thread Guido van Rossum

Guido van Rossum added the comment:

I'm disappointed that this doesn't implement socket.fromfd() properly.
Perhaps fromfd() needs to be implemented in socketmodule.c?

Also, the whole mess with the _base slot can be gotten rid of;
accept() can use the dup() method instead.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1443] Magic class member variable initialization with lists

2007-11-14 Thread Guido van Rossum

Guido van Rossum added the comment:

Go ask on c.l.py why this is not a bug.

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



[issue1378] fromfd() and dup() for _socket on WIndows

2007-11-14 Thread Christian Heimes

Christian Heimes added the comment:

Port of the socket_fromfd.patch to py3k

Added file: http://bugs.python.org/file8746/py3k_socket_fromfd.patch

__
Tracker <[EMAIL PROTECTED]>

__Index: Lib/socket.py
===
--- Lib/socket.py	(Revision 58966)
+++ Lib/socket.py	(Arbeitskopie)
@@ -111,10 +111,10 @@
 
 
 # True if os.dup() can duplicate socket descriptors.
-# (On Windows at least, os.dup only works on files)
 _can_dup_socket = hasattr(_socket.socket, "dup")
 
-if _can_dup_socket:
+# On Windows _socket.socket.dup() doesn't accept a file descriptor
+if _can_dup_socket and os.name != 'nt':
 def fromfd(fd, family=AF_INET, type=SOCK_STREAM, proto=0):
 nfd = os.dup(fd)
 return socket(family, type, proto, fileno=nfd)
Index: Lib/test/test_socket.py
===
--- Lib/test/test_socket.py	(Revision 58966)
+++ Lib/test/test_socket.py	(Arbeitskopie)
@@ -566,7 +566,7 @@
 def testFromFd(self):
 # Testing fromfd()
 if not hasattr(socket, "fromfd"):
-return # On Windows, this doesn't exist
+return # On BeOS, OS/2 and RiscOS this doesn't exist
 fd = self.cli_conn.fileno()
 sock = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM)
 msg = sock.recv(1024)
@@ -575,6 +575,15 @@
 def _testFromFd(self):
 self.serv_conn.send(MSG)
 
+def testDup(self):
+# Testing dup()
+sock = self.cli_conn.dup()
+msg = sock.recv(1024)
+self.assertEqual(msg, MSG)
+
+def _testDup(self):
+self.serv_conn.send(MSG)
+
 def testShutdown(self):
 # Testing shutdown()
 msg = self.cli_conn.recv(1024)
Index: Modules/socketmodule.c
===
--- Modules/socketmodule.c	(Revision 58966)
+++ Modules/socketmodule.c	(Arbeitskopie)
@@ -324,10 +324,25 @@
 #include "getnameinfo.c"
 #endif
 
-#if defined(MS_WINDOWS)
-/* seem to be a few differences in the API */
+#ifdef MS_WINDOWS
+/* On Windows a socket is really a handle not an fd */
+static SOCKET
+duplicate_socket(SOCKET handle)
+{
+	HANDLE newhandle;
+
+	if (!DuplicateHandle(GetCurrentProcess(), (HANDLE)handle,
+			 GetCurrentProcess(), &newhandle,
+			 0, FALSE, DUPLICATE_SAME_ACCESS))
+	{
+		WSASetLastError(WSAEBADF);
+		return INVALID_SOCKET;
+	}
+	return (SOCKET)newhandle;
+}
+#define dup(fd) duplicate_socket(fd)
 #define SOCKETCLOSE closesocket
-#define NO_DUP /* Actually it exists on NT 3.5, but what the heck... */
+#define NO_MAKEFILE /* socket handles can't be treated like file handles */
 #endif
 
 #ifdef MS_WIN32
@@ -344,6 +359,10 @@
 #define SOCKETCLOSE close
 #endif
 
+#ifdef NO_DUP
+#define NO_MAKEFILE
+#endif
+
 #if defined(HAVE_BLUETOOTH_H) || defined(HAVE_BLUETOOTH_BLUETOOTH_H)
 #define USE_BLUETOOTH 1
 #if defined(__FreeBSD__)
@@ -1978,8 +1997,13 @@
 	PyObject *sock;
 
 	newfd = dup(s->sock_fd);
-	if (newfd < 0)
+#ifdef MS_WINDOWS
+	if (newfd == INVALID_SOCKET) {
+#else
+	if (newfd < 0) {
+#endif
 		return s->errorhandler();
+	}
 	sock = (PyObject *) new_sockobject(newfd,
 	   s->sock_family,
 	   s->sock_type,
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1378] fromfd() and dup() for _socket on WIndows

2007-11-14 Thread Christian Heimes

Christian Heimes added the comment:

> I'm disappointed that this doesn't implement socket.fromfd() properly.
> Perhaps fromfd() needs to be implemented in socketmodule.c?

On Windows socket.fromfd() is not possible. Socket handlers and file
descriptors are different types using different API methods. Other
examples for the discrepancy are select.select() and select.poll(). On
Windows they don't work on file.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1439] proposed 3000 patch for socket.py - "socket GC worries"

2007-11-14 Thread Christian Heimes

Christian Heimes added the comment:

I've checked the patch on Windows. I've run the regression tests with
-R:: for test_urllib2 test_urllib2net test_urllib test_urllibnet
test_socket. The tests are passing and no ref leak shows up.

--
assignee: tiran -> gvanrossum

__
Tracker <[EMAIL PROTECTED]>

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



[issue1378] fromfd() and dup() for _socket on WIndows

2007-11-14 Thread Guido van Rossum

Guido van Rossum added the comment:

> On Windows socket.fromfd() is not possible. Socket handlers and file
> descriptors are different types using different API methods. Other
> examples for the discrepancy are select.select() and select.poll(). On
> Windows they don't work on file.

I know, but, I was thinking of it taking the fileno() of some other
socket object as argument.

In any case I think the test should not be based on whether os.name ==
'nt' but on the presence of something in the _socket module.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1440] Checks for PySys_GetObject("std???") == Py_None

2007-11-14 Thread Guido van Rossum

Guido van Rossum added the comment:

I take it back. You can check this in.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1439] proposed 3000 patch for socket.py - "socket GC worries"

2007-11-14 Thread Guido van Rossum

Guido van Rossum added the comment:

Committed revision 58970 (with slight changes).

Bill, you can now submit your SSL code for review.

--
assignee: gvanrossum -> tiran
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



[issue1234] semaphore errors on AIX 5.2

2007-11-14 Thread Marc-Andre Lemburg

Marc-Andre Lemburg added the comment:

The problem is also present in Python 2.4 and 2.3. Confirmed on AIX 5.3.

--
nosy: +lemburg
versions: +Python 2.3, Python 2.4

__
Tracker <[EMAIL PROTECTED]>

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



[issue1378] fromfd() and dup() for _socket on WIndows

2007-11-14 Thread Guido van Rossum

Guido van Rossum added the comment:

Crys, did you actually run the tests for the 3.0 port of the patch? I
think accept() is broken, as it checks for _can_dup_socket and will
attempt to call os.dup().

I'm thinking that we should change the C class to not create new objects
on accept() and dup() -- instead, there should be methods _accept() and
_dup() that return new file descriptors.  Then the subclass can
implement accept() and dup() properly without needing to call dup()
again, and the _base slot will no longer be needed.  Tell you what, I'll
try this and submit a patch for testing on Windows later.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1378] fromfd() and dup() for _socket on WIndows

2007-11-14 Thread Guido van Rossum

Guido van Rossum added the comment:

Here's a new version along the lines I described. Please test on
Windows. It works on Linux and OSX. What this includes:

- the dup-on-windows implementation by R Oudkerk, with the
GetLastError() suggestion from Thomas Heller.

- Replace the C implementations of dup() and accept() with _dup() and
_accept() that return file descriptors instead of socket objects.

- Implement accept() and dup() in Python using _accept() and _dup().

- Get rid of socket.fromfd(). You can use socket.socket(..., fileno=...)
instead (it doesn't dup though).

Added file: http://bugs.python.org/file8747/socket.diff

__
Tracker <[EMAIL PROTECTED]>

__Index: Doc/library/socket.rst
===
--- Doc/library/socket.rst	(revision 58970)
+++ Doc/library/socket.rst	(working copy)
@@ -299,19 +299,6 @@
Availability: Unix.
 
 
-.. function:: fromfd(fd, family, type[, proto])
-
-   Duplicate the file descriptor *fd* (an integer as returned by a file object's
-   :meth:`fileno` method) and build a socket object from the result.  Address
-   family, socket type and protocol number are as for the :func:`socket` function
-   above. The file descriptor should refer to a socket, but this is not checked ---
-   subsequent operations on the object may fail if the file descriptor is invalid.
-   This function is rarely needed, but can be used to get or set socket options on
-   a socket passed to a program as standard input or output (such as a server
-   started by the Unix inet daemon).  The socket is assumed to be in blocking mode.
-   Availability: Unix.
-
-
 .. function:: ntohl(x)
 
Convert 32-bit positive integers from network to host byte order.  On machines
Index: Lib/socket.py
===
--- Lib/socket.py	(revision 58970)
+++ Lib/socket.py	(working copy)
@@ -79,28 +79,14 @@
 __all__.append("errorTab")
 
 
-# True if os.dup() can duplicate socket descriptors.
-# (On Windows at least, os.dup only works on files)
-_can_dup_socket = hasattr(_socket.socket, "dup")
-
-if _can_dup_socket:
-def fromfd(fd, family=AF_INET, type=SOCK_STREAM, proto=0):
-nfd = os.dup(fd)
-return socket(family, type, proto, fileno=nfd)
-
 class socket(_socket.socket):
 
 """A subclass of _socket.socket adding the makefile() method."""
 
 __slots__ = ["__weakref__", "_io_refs", "_closed"]
-if not _can_dup_socket:
-__slots__.append("_base")
 
 def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None):
-if fileno is None:
-_socket.socket.__init__(self, family, type, proto)
-else:
-_socket.socket.__init__(self, family, type, proto, fileno)
+_socket.socket.__init__(self, family, type, proto, fileno)
 self._io_refs = 0
 self._closed = False
 
@@ -114,19 +100,15 @@
 s[7:])
 return s
 
+def dup(self):
+"""Wrap _dup() result in a socket object."""
+fd = self._dup()
+return self.__class__(self.family, self.type, self.proto, fileno=fd)
+
 def accept(self):
-"""Wrap accept() to give the connection the right type."""
-conn, addr = _socket.socket.accept(self)
-fd = conn.fileno()
-nfd = fd
-if _can_dup_socket:
-nfd = os.dup(fd)
-wrapper = socket(self.family, self.type, self.proto, fileno=nfd)
-if fd == nfd:
-wrapper._base = conn  # Keep the base alive
-else:
-conn.close()
-return wrapper, addr
+"""Wrap _accept() result in a socket object."""
+fd, addr = self._accept()
+return socket(self.family, self.type, self.proto, fileno=fd), addr
 
 def makefile(self, mode="r", buffering=None, *,
  encoding=None, newline=None):
@@ -184,21 +166,8 @@
 
 def close(self):
 self._closed = True
-if self._io_refs < 1:
-self._real_close()
-
-# _real_close calls close on the _socket.socket base class.
-
-if not _can_dup_socket:
-def _real_close(self):
+if self._io_refs <= 0:
 _socket.socket.close(self)
-base = getattr(self, "_base", None)
-if base is not None:
-self._base = None
-base.close()
-else:
-def _real_close(self):
-_socket.socket.close(self)
 
 
 class SocketIO(io.RawIOBase):
Index: Lib/test/test_socket.py
===
--- Lib/test/test_socket.py	(revision 58970)
+++ Lib/test/test_socket.py	(working copy)
@@ -563,16 +563,16 @@
 big_chunk = b'f' * 2048
 self.serv_conn.sendall(big_chunk)
 
-def testFromFd(self):
-# Testing fromfd()
-if not hasattr(socket, "fromfd"):

[issue1378] fromfd() and dup() for _socket on WIndows

2007-11-14 Thread Guido van Rossum

Changes by Guido van Rossum:


Removed file: http://bugs.python.org/file8747/socket.diff

__
Tracker <[EMAIL PROTECTED]>

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



[issue1378] fromfd() and dup() for _socket on WIndows

2007-11-14 Thread Guido van Rossum

Guido van Rossum added the comment:

New version of socket.diff.  The only change is better docstrings for
accept() and dup().

Added file: http://bugs.python.org/file8748/socket.diff

__
Tracker <[EMAIL PROTECTED]>

__Index: Doc/library/socket.rst
===
--- Doc/library/socket.rst	(revision 58970)
+++ Doc/library/socket.rst	(working copy)
@@ -299,19 +299,6 @@
Availability: Unix.
 
 
-.. function:: fromfd(fd, family, type[, proto])
-
-   Duplicate the file descriptor *fd* (an integer as returned by a file object's
-   :meth:`fileno` method) and build a socket object from the result.  Address
-   family, socket type and protocol number are as for the :func:`socket` function
-   above. The file descriptor should refer to a socket, but this is not checked ---
-   subsequent operations on the object may fail if the file descriptor is invalid.
-   This function is rarely needed, but can be used to get or set socket options on
-   a socket passed to a program as standard input or output (such as a server
-   started by the Unix inet daemon).  The socket is assumed to be in blocking mode.
-   Availability: Unix.
-
-
 .. function:: ntohl(x)
 
Convert 32-bit positive integers from network to host byte order.  On machines
Index: Lib/socket.py
===
--- Lib/socket.py	(revision 58970)
+++ Lib/socket.py	(working copy)
@@ -79,28 +79,14 @@
 __all__.append("errorTab")
 
 
-# True if os.dup() can duplicate socket descriptors.
-# (On Windows at least, os.dup only works on files)
-_can_dup_socket = hasattr(_socket.socket, "dup")
-
-if _can_dup_socket:
-def fromfd(fd, family=AF_INET, type=SOCK_STREAM, proto=0):
-nfd = os.dup(fd)
-return socket(family, type, proto, fileno=nfd)
-
 class socket(_socket.socket):
 
 """A subclass of _socket.socket adding the makefile() method."""
 
 __slots__ = ["__weakref__", "_io_refs", "_closed"]
-if not _can_dup_socket:
-__slots__.append("_base")
 
 def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None):
-if fileno is None:
-_socket.socket.__init__(self, family, type, proto)
-else:
-_socket.socket.__init__(self, family, type, proto, fileno)
+_socket.socket.__init__(self, family, type, proto, fileno)
 self._io_refs = 0
 self._closed = False
 
@@ -114,23 +100,27 @@
 s[7:])
 return s
 
+def dup(self):
+"""dup() -> socket object
+
+Return a new socket object connected to the same system resource.
+"""
+fd = self._dup()
+return self.__class__(self.family, self.type, self.proto, fileno=fd)
+
 def accept(self):
-"""Wrap accept() to give the connection the right type."""
-conn, addr = _socket.socket.accept(self)
-fd = conn.fileno()
-nfd = fd
-if _can_dup_socket:
-nfd = os.dup(fd)
-wrapper = socket(self.family, self.type, self.proto, fileno=nfd)
-if fd == nfd:
-wrapper._base = conn  # Keep the base alive
-else:
-conn.close()
-return wrapper, addr
+"""accept() -> (socket object, address info)
 
+Wait for an incoming connection.  Return a new socket
+representing the connection, and the address of the client.
+For IP sockets, the address info is a pair (hostaddr, port).
+"""
+fd, addr = self._accept()
+return socket(self.family, self.type, self.proto, fileno=fd), addr
+
 def makefile(self, mode="r", buffering=None, *,
  encoding=None, newline=None):
-"""Return an I/O stream connected to the socket.
+"""makefile(...) -> an I/O stream connected to the socket
 
 The arguments are as for io.open() after the filename,
 except the only mode characters supported are 'r', 'w' and 'b'.
@@ -184,21 +174,8 @@
 
 def close(self):
 self._closed = True
-if self._io_refs < 1:
-self._real_close()
-
-# _real_close calls close on the _socket.socket base class.
-
-if not _can_dup_socket:
-def _real_close(self):
+if self._io_refs <= 0:
 _socket.socket.close(self)
-base = getattr(self, "_base", None)
-if base is not None:
-self._base = None
-base.close()
-else:
-def _real_close(self):
-_socket.socket.close(self)
 
 
 class SocketIO(io.RawIOBase):
Index: Lib/test/test_socket.py
===
--- Lib/test/test_socket.py	(revision 58970)
+++ Lib/test/test_socket.py	(working copy)
@@ -563,16 +563,16 @@
 big_chunk = b'f' * 2048
 self.serv_conn.sendall(big_chunk)
 

[issue1378] fromfd() and dup() for _socket on WIndows

2007-11-14 Thread Guido van Rossum

Guido van Rossum added the comment:

PS. socket.diff is for 3.0. I'll backport once this is accepted.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1378] fromfd() and dup() for _socket on WIndows

2007-11-14 Thread Christian Heimes

Christian Heimes added the comment:

I've reviewed your patch and merged it was some pending changes of my
own. The socket tests are passing on Windows. Great work :)

UPDATE:
* Added PyLong_FromSocket_t and PyLong_AsSocket_t to longobject.h to get
rid of some 64bit warnings
* Use name dup_socket() instead of dup(). For Windows developers it's
too confusing to name it dup().
* Readded fromfd, but this time in C again.

__
Tracker <[EMAIL PROTECTED]>

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



[issue1440] Checks for PySys_GetObject("std???") == Py_None

2007-11-14 Thread Christian Heimes

Christian Heimes added the comment:

Committed in r58974

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



[issue1439] proposed 3000 patch for socket.py - "socket GC worries"

2007-11-14 Thread Bill Janssen

Bill Janssen added the comment:

Once I've tried it again.

Bill

On Nov 14, 2007 2:32 PM, Guido van Rossum <[EMAIL PROTECTED]> wrote:
>
> Guido van Rossum added the comment:
>
> Committed revision 58970 (with slight changes).
>
> Bill, you can now submit your SSL code for review.
>
> --
> assignee: gvanrossum -> tiran
> resolution:  -> accepted
> 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



[issue1031213] Use correct encoding for printing SyntaxErrors

2007-11-14 Thread atsuo ishimoto

atsuo ishimoto added the comment:

In release25-maint, PyErr_Print() should be replaced with PyErr_Clear()
also.

_
Tracker <[EMAIL PROTECTED]>

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