summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/language/python/compile.scm11
-rw-r--r--modules/language/python/module/_posixsubprocess.scm12
-rw-r--r--modules/language/python/module/selectors.py4
-rw-r--r--modules/language/python/module/subprocess.py17
-rw-r--r--modules/language/python/module/warnings.scm4
-rw-r--r--modules/language/python/try.scm5
6 files changed, 31 insertions, 22 deletions
diff --git a/modules/language/python/compile.scm b/modules/language/python/compile.scm
index 378138c..5dbd3e6 100644
--- a/modules/language/python/compile.scm
+++ b/modules/language/python/compile.scm
@@ -1048,19 +1048,18 @@
(#:try
((_ x (or #f ()) #f . fin)
(if fin
- `(,(T 'try) ,(exp vs x) #:finally (lambda () fin))
- (exp vs x)))
-
+ `(,(T 'try) (lambda () ,(exp vs x)) #:finally (lambda () fin))
+ `(,(T 'try) (lambda () ,(exp vs x)))))
((_ x exc else . fin)
`(,(T 'try) (lambda () ,(exp vs x))
- ,@(let lp ((exc exc) (r (if else (exp vs else) '())))
+ ,@(let lp ((exc exc) (r '()))
(match exc
((((test . #f) code) . exc)
(lp exc (cons `(#:except ,(exp vs test) ,(exp vs code)) r)))
(((#f code) . exc)
- (lp exc (cons `(#:except ,(exp vs code)) r)))
+ (lp exc (cons `(#:except #t ,(exp vs code)) r)))
((((test . as) code) . exc)
(let ((l (gensym "l")))
@@ -1071,6 +1070,8 @@
r))))
(()
(reverse r))))
+
+ ,@(if else `((#:except #t ,(exp vs else))) '())
,@(if fin `(#:finally (lambda () ,(exp vs fin))) '()))))
(#:subexpr
diff --git a/modules/language/python/module/_posixsubprocess.scm b/modules/language/python/module/_posixsubprocess.scm
index ce2bdc9..b625a8a 100644
--- a/modules/language/python/module/_posixsubprocess.scm
+++ b/modules/language/python/module/_posixsubprocess.scm
@@ -2,10 +2,10 @@
#:use-module (language python for)
#:use-module (language python try)
#:use-module (language python module python)
- #:use-module (language python module bool)
+ #:use-module (language python bool)
#:use-module (language python module os)
#:use-module (language python module errno)
- #:use-module (language python module list)
+ #:use-module (language python list)
#:use-module (language python exceptions)
#:export (fork_exec))
@@ -68,7 +68,7 @@
(let ((argv (to-list argv))
(envp (if (bool envp) (to-list envp) envp)))
- (for ((e : exec_array)) ((e #f))
+ (for ((e : exec_array)) ((ep #f))
(try
(lambda ()
(if (bool envp)
@@ -81,11 +81,11 @@
(set! execmsg
(+ execmsg + (format #f " exec error: ~a~%" x))))))
(let ((er (errno)))
- (if (and (not (= er ENOENT)) (not (= er ENOTDIR)) (not e))
+ (if (and (not (= er ENOENT)) (not (= er ENOTDIR)) (not ep))
er
- e))
+ ep))
#:final
- (if e (set_errno e) (set_errno 0))))
+ (if ep (set_errno ep) (set_errno 0))))
(if errwrite
(write errpipe_write errwrite))
diff --git a/modules/language/python/module/selectors.py b/modules/language/python/module/selectors.py
index 5e8f3e2..41d70ba 100644
--- a/modules/language/python/module/selectors.py
+++ b/modules/language/python/module/selectors.py
@@ -449,5 +449,7 @@ __all__ = [ 'BaseSelector' ,
'DefaultSelector' ,
'EpollSelector' ,
'PollSelector' ,
- 'SelectSelector' ]
+ 'SelectSelector' ,
+ 'EventRead' ,
+ 'EventWrite' ]
diff --git a/modules/language/python/module/subprocess.py b/modules/language/python/module/subprocess.py
index d4dd259..cfbc4e4 100644
--- a/modules/language/python/module/subprocess.py
+++ b/modules/language/python/module/subprocess.py
@@ -132,12 +132,12 @@ else:
import threading
except ImportError:
import dummy_threading as threading
- pk(1)
+
# When select or poll has indicated that the file is writable,
# we can write up to _PIPE_BUF bytes without risk of blocking.
# POSIX defines PIPE_BUF as >= 512.
_PIPE_BUF = getattr(select, 'PIPE_BUF', 512)
- pk(2)
+
# poll/select have the advantage of not requiring any extra file
# descriptor, contrarily to epoll/kqueue (also, they require a single
# syscall).
@@ -654,9 +654,7 @@ class Popen(object):
# are -1 when not using PIPEs. The child objects are -1
# when not redirecting.
- (p2cread, p2cwrite,
- c2pread, c2pwrite,
- errread, errwrite) = self._get_handles(stdin, stdout, stderr)
+ p2cread, p2cwrite,c2pread, c2pwrite,errread, errwrite = self._get_handles(stdin, stdout, stderr)
# We wrap OS handles *before* launching the child, otherwise a
# quickly terminating child could make our fds unwrappable
@@ -1393,15 +1391,14 @@ class Popen(object):
def _try_wait(self, wait_flags):
"""All callers to this function MUST hold self._waitpid_lock."""
try:
- (pid, sts) = os.waitpid(self.pid, wait_flags)
+ pid, sts = os.waitpid(self.pid, wait_flags)
except ChildProcessError:
# This happens if SIGCLD is set to be ignored or waiting
# for child processes has otherwise been disabled for our
# process. This child is dead, we can't get the status.
pid = self.pid
sts = 0
- return (pid, sts)
-
+ return pid, sts
def wait(self, timeout=None, endtime=None):
"""Wait for child process to terminate. Returns returncode
@@ -1429,7 +1426,7 @@ class Popen(object):
try:
if self.returncode is not None:
break # Another thread waited.
- (pid, sts) = self._try_wait(os.WNOHANG)
+ pid, sts = self._try_wait(os.WNOHANG)
assert pid == self.pid or pid == 0
if pid == self.pid:
self._handle_exitstatus(sts)
@@ -1446,7 +1443,7 @@ class Popen(object):
with self._waitpid_lock:
if self.returncode is not None:
break # Another thread waited.
- (pid, sts) = self._try_wait(0)
+ pid, sts = self._try_wait(0)
# Check the pid and loop as waitpid has been known to
# return 0 even without WNOHANG in odd situations.
# http://bugs.python.org/issue14396.
diff --git a/modules/language/python/module/warnings.scm b/modules/language/python/module/warnings.scm
new file mode 100644
index 0000000..fc05415
--- /dev/null
+++ b/modules/language/python/module/warnings.scm
@@ -0,0 +1,4 @@
+(define-module (language python module warnings)
+ #:export (warn))
+
+(define (warn . l) ((@ (guile) warn) l))
diff --git a/modules/language/python/try.scm b/modules/language/python/try.scm
index 68a9b5d..50ca23f 100644
--- a/modules/language/python/try.scm
+++ b/modules/language/python/try.scm
@@ -56,6 +56,11 @@
(apply c k l)))))
(define-syntax handler
+ (lambda (x)
+ (syntax-case x ()
+ ((_ . l) #'(handler_ . l)))))
+
+(define-syntax handler_
(syntax-rules (=>)
((handler ecx)
(m