Author: Philip Jenvey <[email protected]>
Branch:
Changeset: r64657:1c11e438a8a4
Date: 2013-05-28 18:12 -0700
http://bitbucket.org/pypy/pypy/changeset/1c11e438a8a4/
Log: pep8/cleanup
diff --git a/pypy/module/_multiprocessing/__init__.py
b/pypy/module/_multiprocessing/__init__.py
--- a/pypy/module/_multiprocessing/__init__.py
+++ b/pypy/module/_multiprocessing/__init__.py
@@ -1,5 +1,6 @@
+import sys
+
from pypy.interpreter.mixedmodule import MixedModule
-import sys
class Module(MixedModule):
diff --git a/pypy/module/_multiprocessing/interp_connection.py
b/pypy/module/_multiprocessing/interp_connection.py
--- a/pypy/module/_multiprocessing/interp_connection.py
+++ b/pypy/module/_multiprocessing/interp_connection.py
@@ -1,17 +1,16 @@
-from __future__ import with_statement
-from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.typedef import TypeDef, GetSetProperty
-from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
-from pypy.interpreter.error import (
- OperationError, wrap_oserror, operationerrfmt)
-from rpython.rtyper.lltypesystem import rffi, lltype
-from rpython.rlib.rarithmetic import intmask
-from rpython.rlib import rpoll, rsocket
import sys
-READABLE = 1
-WRITABLE = 2
+from rpython.rlib import rpoll, rsocket
+from rpython.rlib.rarithmetic import intmask
+from rpython.rtyper.lltypesystem import lltype, rffi
+from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.error import (
+ OperationError, operationerrfmt, wrap_oserror)
+from pypy.interpreter.gateway import WrappedDefault, interp2app, unwrap_spec
+from pypy.interpreter.typedef import GetSetProperty, TypeDef
+
+READABLE, WRITABLE = range(1, 3)
PY_SSIZE_T_MAX = sys.maxint
PY_SSIZE_T_MIN = -sys.maxint - 1
@@ -46,10 +45,12 @@
raise NotImplementedError
def is_valid(self):
return False
- def do_send_string(self, space, buffer, offset, size):
+ def do_send_string(self, space, buf, offset, size):
raise NotImplementedError
def do_recv_string(self, space, buflength, maxlength):
raise NotImplementedError
+ def do_poll(self, space, timeout):
+ raise NotImplementedError
def close(self):
self.do_close()
@@ -70,9 +71,9 @@
raise OperationError(space.w_IOError,
space.wrap("connection is read-only"))
- @unwrap_spec(buffer='bufferstr', offset='index', size='index')
- def send_bytes(self, space, buffer, offset=0, size=PY_SSIZE_T_MIN):
- length = len(buffer)
+ @unwrap_spec(buf='bufferstr', offset='index', size='index')
+ def send_bytes(self, space, buf, offset=0, size=PY_SSIZE_T_MIN):
+ length = len(buf)
self._check_writable(space)
if offset < 0:
raise OperationError(space.w_ValueError,
@@ -90,7 +91,7 @@
raise OperationError(space.w_ValueError,
space.wrap("buffer length > offset + size"))
- self.do_send_string(space, buffer, offset, size)
+ self.do_send_string(space, buf, offset, size)
@unwrap_spec(maxlength='index')
def recv_bytes(self, space, maxlength=PY_SSIZE_T_MAX):
@@ -139,8 +140,8 @@
w_pickled = space.call_method(
w_picklemodule, "dumps", w_obj, w_protocol)
- buffer = space.bufferstr_w(w_pickled)
- self.do_send_string(space, buffer, 0, len(buffer))
+ buf = space.bufferstr_w(w_pickled)
+ self.do_send_string(space, buf, 0, len(buf))
def recv(self, space):
self._check_readable(space)
@@ -226,7 +227,8 @@
def __init__(self, space, fd, flags):
if fd == self.INVALID_HANDLE_VALUE or fd < 0:
- raise OperationError(space.w_IOError, space.wrap("invalid handle
%d" % fd))
+ raise OperationError(space.w_IOError,
+ space.wrap("invalid handle %d" % fd))
W_BaseConnection.__init__(self, flags)
self.fd = fd
@@ -249,8 +251,8 @@
self.CLOSE()
self.fd = self.INVALID_HANDLE_VALUE
- def do_send_string(self, space, buffer, offset, size):
- # Since str2charp copies the buffer anyway, always combine the
+ def do_send_string(self, space, buf, offset, size):
+ # Since str2charp copies the buf anyway, always combine the
# "header" and the "body" of the message and send them at once.
message = lltype.malloc(rffi.CCHARP.TO, size + 4, flavor='raw')
try:
@@ -259,7 +261,7 @@
rffi.cast(rffi.UINTP, message)[0] = length
i = size - 1
while i >= 0:
- message[4 + i] = buffer[offset + i]
+ message[4 + i] = buf[offset + i]
i -= 1
self._sendall(space, message, size + 4)
finally:
@@ -296,7 +298,7 @@
size -= count
message = rffi.ptradd(message, count)
- def _recvall(self, space, buffer, length):
+ def _recvall(self, space, buf, length):
length = intmask(length)
remaining = length
while remaining > 0:
@@ -313,9 +315,9 @@
"got end of file during message"))
# XXX inefficient
for i in range(count):
- buffer[i] = data[i]
+ buf[i] = data[i]
remaining -= count
- buffer = rffi.ptradd(buffer, count)
+ buf = rffi.ptradd(buf, count)
if sys.platform == 'win32':
def _check_fd(self):
@@ -330,10 +332,7 @@
"handle out of range in select()"))
r, w, e = rpoll.select([self.fd], [], [], timeout)
- if r:
- return True
- else:
- return False
+ return bool(r)
W_FileConnection.typedef = TypeDef(
'Connection', W_BaseConnection.typedef,
@@ -351,7 +350,8 @@
self.handle = handle
@unwrap_spec(readable=bool, writable=bool)
- def descr_new_pipe(space, w_subtype, w_handle, readable=True,
writable=True):
+ def descr_new_pipe(space, w_subtype, w_handle, readable=True,
+ writable=True):
from pypy.module._multiprocessing.interp_win32 import handle_w
handle = handle_w(space, w_handle)
flags = (readable and READABLE) | (writable and WRITABLE)
@@ -378,12 +378,12 @@
CloseHandle(self.handle)
self.handle = self.INVALID_HANDLE_VALUE
- def do_send_string(self, space, buffer, offset, size):
+ def do_send_string(self, space, buf, offset, size):
from pypy.module._multiprocessing.interp_win32 import (
_WriteFile, ERROR_NO_SYSTEM_RESOURCES)
from rpython.rlib import rwin32
- charp = rffi.str2charp(buffer)
+ charp = rffi.str2charp(buf)
written_ptr = lltype.malloc(rffi.CArrayPtr(rwin32.DWORD).TO, 1,
flavor='raw')
try:
diff --git a/pypy/module/_multiprocessing/interp_memory.py
b/pypy/module/_multiprocessing/interp_memory.py
--- a/pypy/module/_multiprocessing/interp_memory.py
+++ b/pypy/module/_multiprocessing/interp_memory.py
@@ -1,5 +1,6 @@
+from rpython.rtyper.lltypesystem import rffi
+
from pypy.interpreter.error import OperationError
-from rpython.rtyper.lltypesystem import rffi
from pypy.module.mmap.interp_mmap import W_MMap
def address_of_buffer(space, w_obj):
diff --git a/pypy/module/_multiprocessing/interp_semaphore.py
b/pypy/module/_multiprocessing/interp_semaphore.py
--- a/pypy/module/_multiprocessing/interp_semaphore.py
+++ b/pypy/module/_multiprocessing/interp_semaphore.py
@@ -1,23 +1,26 @@
-from __future__ import with_statement
+import errno
+import os
+import sys
+import time
+
+from rpython.rlib import rgc, rthread
+from rpython.rlib.rarithmetic import r_uint
+from rpython.rtyper.lltypesystem import rffi, lltype
+from rpython.rtyper.tool import rffi_platform as platform
+from rpython.translator.tool.cbuild import ExternalCompilationInfo
+
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.typedef import TypeDef, GetSetProperty
+from pypy.interpreter.error import OperationError, wrap_oserror
from pypy.interpreter.gateway import interp2app, unwrap_spec
-from pypy.interpreter.error import wrap_oserror, OperationError
-from rpython.rtyper.lltypesystem import rffi, lltype
-from rpython.rlib import rgc
-from rpython.rlib.rarithmetic import r_uint
-from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from rpython.rtyper.tool import rffi_platform as platform
-from rpython.rlib import rthread
+from pypy.interpreter.typedef import GetSetProperty, TypeDef
from pypy.module._multiprocessing.interp_connection import w_handle
-import sys, os, time, errno
RECURSIVE_MUTEX, SEMAPHORE = range(2)
if sys.platform == 'win32':
from rpython.rlib import rwin32
from pypy.module._multiprocessing.interp_win32 import (
- handle_w, _GetTickCount)
+ _GetTickCount, handle_w)
SEM_VALUE_MAX = sys.maxint
@@ -62,7 +65,8 @@
TIMEVALP = rffi.CArrayPtr(TIMEVAL)
TIMESPECP = rffi.CArrayPtr(TIMESPEC)
SEM_T = rffi.COpaquePtr('sem_t', compilation_info=eci)
- SEM_FAILED = config['SEM_FAILED'] # rffi.cast(SEM_T,
config['SEM_FAILED'])
+ # rffi.cast(SEM_T, config['SEM_FAILED'])
+ SEM_FAILED = config['SEM_FAILED']
SEM_VALUE_MAX = config['SEM_VALUE_MAX']
SEM_TIMED_WAIT = config['SEM_TIMED_WAIT']
SEM_T_SIZE = config['SEM_T_SIZE']
@@ -160,7 +164,8 @@
return -1
if SEM_TIMED_WAIT:
- _sem_timedwait = external('sem_timedwait', [SEM_T, TIMESPECP],
rffi.INT)
+ _sem_timedwait = external('sem_timedwait', [SEM_T, TIMESPECP],
+ rffi.INT)
else:
_sem_timedwait = _sem_timedwait_save
@@ -185,7 +190,8 @@
res = _gettimeofday(now, None)
if res < 0:
raise OSError(rposix.get_errno(), "gettimeofday failed")
- return rffi.getintfield(now[0], 'c_tv_sec'),
rffi.getintfield(now[0], 'c_tv_usec')
+ return (rffi.getintfield(now[0], 'c_tv_sec'),
+ rffi.getintfield(now[0], 'c_tv_usec'))
finally:
lltype.free(now, flavor='raw')
@@ -330,8 +336,8 @@
deadline = lltype.malloc(TIMESPECP.TO, 1, flavor='raw')
rffi.setintfield(deadline[0], 'c_tv_sec', now_sec + sec)
rffi.setintfield(deadline[0], 'c_tv_nsec', now_usec * 1000 + nsec)
- val = rffi.getintfield(deadline[0], 'c_tv_sec') + \
- rffi.getintfield(deadline[0], 'c_tv_nsec') /
1000000000
+ val = (rffi.getintfield(deadline[0], 'c_tv_sec') +
+ rffi.getintfield(deadline[0], 'c_tv_nsec') / 1000000000)
rffi.setintfield(deadline[0], 'c_tv_sec', val)
val = rffi.getintfield(deadline[0], 'c_tv_nsec') % 1000000000
rffi.setintfield(deadline[0], 'c_tv_nsec', val)
diff --git a/pypy/module/_multiprocessing/interp_win32.py
b/pypy/module/_multiprocessing/interp_win32.py
--- a/pypy/module/_multiprocessing/interp_win32.py
+++ b/pypy/module/_multiprocessing/interp_win32.py
@@ -1,11 +1,12 @@
-from pypy.interpreter.gateway import unwrap_spec, interp2app
-from pypy.interpreter.function import StaticMethod
-from pypy.interpreter.error import wrap_windowserror, OperationError
from rpython.rlib import rwin32
from rpython.rlib.rarithmetic import r_uint
-from rpython.rtyper.lltypesystem import rffi, lltype
+from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.rtyper.tool import rffi_platform
from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from rpython.rtyper.tool import rffi_platform
+
+from pypy.interpreter.error import OperationError, wrap_windowserror
+from pypy.interpreter.function import StaticMethod
+from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.module._multiprocessing.interp_connection import w_handle
CONSTANTS = """
@@ -130,10 +131,12 @@
if not _ConnectNamedPipe(handle, rffi.NULL):
raise wrap_windowserror(space, rwin32.lastWindowsError())
-def SetNamedPipeHandleState(space, w_handle, w_pipemode, w_maxinstances,
w_timeout):
+def SetNamedPipeHandleState(space, w_handle, w_pipemode, w_maxinstances,
+ w_timeout):
handle = handle_w(space, w_handle)
state = lltype.malloc(rffi.CArrayPtr(rffi.UINT).TO, 3, flavor='raw')
- statep = lltype.malloc(rffi.CArrayPtr(rffi.UINTP).TO, 3, flavor='raw',
zero=True)
+ statep = lltype.malloc(rffi.CArrayPtr(rffi.UINTP).TO, 3, flavor='raw',
+ zero=True)
try:
if not space.is_w(w_pipemode, space.w_None):
state[0] = space.uint_w(w_pipemode)
@@ -144,7 +147,8 @@
if not space.is_w(w_timeout, space.w_None):
state[2] = space.uint_w(w_timeout)
statep[2] = rffi.ptradd(state, 2)
- if not _SetNamedPipeHandleState(handle, statep[0], statep[1],
statep[2]):
+ if not _SetNamedPipeHandleState(handle, statep[0], statep[1],
+ statep[2]):
raise wrap_windowserror(space, rwin32.lastWindowsError())
finally:
lltype.free(state, flavor='raw')
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit