summaryrefslogtreecommitdiff
path: root/modules/language
diff options
context:
space:
mode:
Diffstat (limited to 'modules/language')
-rw-r--r--modules/language/python/bytes.scm51
-rw-r--r--modules/language/python/compile.scm15
-rw-r--r--modules/language/python/dict.scm7
-rw-r--r--modules/language/python/exceptions.scm3
-rw-r--r--modules/language/python/module/copy.scm9
-rw-r--r--modules/language/python/module/gettext.py32
-rw-r--r--modules/language/python/module/struct.scm3
-rw-r--r--modules/language/python/string.scm67
8 files changed, 119 insertions, 68 deletions
diff --git a/modules/language/python/bytes.scm b/modules/language/python/bytes.scm
index d9ccab2..494fd28 100644
--- a/modules/language/python/bytes.scm
+++ b/modules/language/python/bytes.scm
@@ -1369,4 +1369,55 @@
(pylist-sort! l)
l))
+(define (_in x y n)
+ (let lp ((i 0))
+ (if (< i n)
+ (if (= (b-ref y i) x)
+ #t
+ (lp (+ i 1)))
+ #f)))
+
+(define (_in2 x y n)
+ (let lp ((i 0))
+ (if (< i n)
+ (let lp2 ((j i) (r x))
+ (if (null? r)
+ #t
+ (if (< j n)
+ (if (= (b-ref y j) (car r))
+ (lp2 (+ j 1) (cdr r))
+ (lp (+ i 1)))
+ #f)))
+ #f)))
+
+(define-method (in (x <integer>) (b <bytevector>))
+ (_in x b (len b)))
+(define-method (in (x <integer>) (b <py-bytes>))
+ (_in x (slot-ref b 'bytes) (len b)))
+(define-method (in (x <integer>) (b <py-bytearray>))
+ (_in x (slot-ref b 'vec) (len b)))
+
+(define-method (in (x <pair>) (b <bytevector>))
+ (_in2 x b (len b)))
+(define-method (in (x <pair>) (b <py-bytes>))
+ (_in2 x (slot-ref b 'bytes) (len b)))
+(define-method (in (x <pair>) (b <py-bytearray>))
+ (_in2 x (slot-ref b 'vec) (len b)))
+
+(define-method (in (x <bytevector>) b)
+ (in (b->list x) b))
+(define-method (in (x <py-bytes>) b)
+ (in (b->list x) b))
+(define-method (in (x <py-bytearray>) b)
+ (in (b->list x) b))
+
+
(set! (@@ (language python string) bytes) bytes)
+(set! (@@ (language python string) b?)
+ (lambda (x)
+ (or (is-a? x <bytevector>)
+ (is-a? x <py-bytes>)
+ (is-a? x <py-bytearray>))))
+(set! (@@ (language python string) b-decode) py-decode)
+
+(define b-enc #f)
diff --git a/modules/language/python/compile.scm b/modules/language/python/compile.scm
index 087d227..5f27706 100644
--- a/modules/language/python/compile.scm
+++ b/modules/language/python/compile.scm
@@ -1773,9 +1773,11 @@
#'(if (pair? a)
(let/ec break-ret
(let lp ((l a))
+ (pk 'l l)
(if (pair? l)
(begin
(set! x (car l))
+ (pk 'x x)
(with-sp ((continue (values))
(break (break-ret)))
code)
@@ -1787,12 +1789,13 @@
(let/ec break-ret
(let lp ((l a))
(if (pair? l)
- (let/ec continue-ret
- (set! x (car l))
- (with-sp ((continue (continue-ret))
- (break (break-ret)))
- code))
- (lp (cdr l)))))
+ (begin
+ (let/ec continue-ret
+ (set! x (car l))
+ (with-sp ((continue (continue-ret))
+ (break (break-ret)))
+ code))
+ (lp (cdr l))))))
(for/adv1 (x) (a) code #f #t)))
((_ (x) (a) code next #f)
diff --git a/modules/language/python/dict.scm b/modules/language/python/dict.scm
index 1d825b6..194da2d 100644
--- a/modules/language/python/dict.scm
+++ b/modules/language/python/dict.scm
@@ -429,9 +429,12 @@
(define-py (py-setdefault setdefault o k . l)
(<hashtable>
- (pylist-set! o k (apply py-get o k l)))
+ (pylist-set! o k (apply py-get o k l))
+ (apply py-get o k l))
+
(<py-hashtable>
- (pylist-set! o k (apply py-get o k l))))
+ (pylist-set! o k (apply py-get o k l))
+ (apply py-get o k l)))
(define update
(lam (o (* L) (** K))
diff --git a/modules/language/python/exceptions.scm b/modules/language/python/exceptions.scm
index 25c565f..60aff93 100644
--- a/modules/language/python/exceptions.scm
+++ b/modules/language/python/exceptions.scm
@@ -11,7 +11,7 @@
ModuleNotFoundError BlockingIOError
InterruptedError BaseException
ZeroDivisionError ArithmeticError
- OverflowError))
+ OverflowError RecursionError))
(define-syntax-rule (aif it p x y) (let ((it p)) (if it x y)))
@@ -48,6 +48,7 @@
(define StopIteration 'StopIteration)
(define GeneratorExit 'GeneratorExit)
(define-er OverflowError 'OverflowError)
+(define-er RecursionError 'RecursionError)
(define-er ArithmeticError 'ArithmeticError)
(define-er BaseException 'BaseException)
(define-er ZeroDivisionError 'ZeroDivisionError)
diff --git a/modules/language/python/module/copy.scm b/modules/language/python/module/copy.scm
index 2673e7e..795fff1 100644
--- a/modules/language/python/module/copy.scm
+++ b/modules/language/python/module/copy.scm
@@ -1,7 +1,12 @@
(define-module (language python module copy)
+ #:use-module (ice-9 match)
#:export (Error copy deepcopy))
(define Error 'CopyError)
-(define (copy x) ((@@ (logic guile-log persistance) copy) x))
-(define (deepcopy x) ((@@ (logic guile-log persistance) deep-copy) x))
+(define (s x)
+ (match x
+ ((#:obj x) x)
+ (x x)))
+(define (copy x) (s ((@@ (logic guile-log persistance) copy) x)))
+(define (deepcopy x) (S ((@@ (logic guile-log persistance) deep-copy) x)))
diff --git a/modules/language/python/module/gettext.py b/modules/language/python/module/gettext.py
index 80a9ebe..0ea54aa 100644
--- a/modules/language/python/module/gettext.py
+++ b/modules/language/python/module/gettext.py
@@ -335,26 +335,18 @@ class GNUTranslations(NullTranslations):
def _parse(self, fp):
"""Override this method to support alternative .mo formats."""
- pk('_parse')
- unpack = pk('unpack',struct.unpack)
- pk(1)
+ unpack = struct.unpack
filename = getattr(fp, 'name', '')
- pk(2,filename)
# Parse the .mo file header, which consists of 5 little endian 32
# bit words.
self._catalog = catalog = {}
self.plural = lambda n: int(n != 1) # germanic plural by default
- pk(3)
buf = fp.read()
buflen = len(buf)
- pk(4,buf)
# Are we big endian or little endian?
magic = unpack('<I', buf[:4])[0]
- pk('magic')
- pk('magic',magic,'LE',self.LE_MAGIC,'BE',self.BE_MAGIC)
if magic == self.LE_MAGIC:
version, msgcount, masteridx, transidx = unpack('<4I', buf[4:20])
- pk(version,msgcount,masteridx,transidx)
ii = '<II'
elif magic == self.BE_MAGIC:
version, msgcount, masteridx, transidx = unpack('>4I', buf[4:20])
@@ -363,7 +355,6 @@ class GNUTranslations(NullTranslations):
raise OSError(0, 'Bad magic number', filename)
major_version, minor_version = self._get_versions(version)
- pk('version',major_version,self.VERSIONS)
if major_version not in self.VERSIONS:
raise OSError(0, 'Bad version number ' + str(major_version), filename)
@@ -379,15 +370,13 @@ class GNUTranslations(NullTranslations):
tmsg = buf[toff:tend]
else:
raise OSError(0, 'File is corrupt', filename)
- pk('msg',mlen,tlen,msg,tmsg)
+
# See if we're looking at GNU .mo conventions for metadata
if mlen == 0:
# Catalog description
lastk = None
- for b_item in pk('split',tmsg.split(b'\n')):
- pk('item',b_item)
+ for b_item in tmsg.split(b'\n'):
item = b_item.decode().strip()
- pk('decode',item)
if not item:
continue
k = v = None
@@ -395,20 +384,16 @@ class GNUTranslations(NullTranslations):
k, v = item.split(':', 1)
k = k.strip().lower()
v = v.strip()
- pk('pair',k,v)
self._info[k] = v
lastk = k
elif lastk:
self._info[lastk] += '\n' + item
- pk('lastk',lastk,self._info[lastk])
if k == 'content-type':
self._charset = v.split('charset=')[1]
- pk('charset',self._charset)
elif k == 'plural-forms':
v = v.split(';')
plural = v[1].split('plural=')[1]
self.plural = c2py(plural)
- pk('plural',self.plural)
# Note: we unconditionally convert both msgids and msgstrs to
# Unicode using the character encoding specified in the charset
# parameter of the Content-Type header. The gettext documentation
@@ -548,19 +533,16 @@ def translation(domain, localedir=None, languages=None,
# once.
result = None
for mofile in mofiles:
- pk('mofile',mofile)
- key = pk((class_, os.path.abspath(mofile)))
- t = pk('tr',_translations.get(key))
+ key = (class_, os.path.abspath(mofile))
+ t = _translations.get(key)
if t is None:
with open(mofile, 'rb') as fp:
- pk('process')
- t = _translations.setdefault(key, pk('cl',class_(fp)))
+ t = _translations.setdefault(key, class_(fp))
# Copy the translation object to allow setting fallbacks and
# output charset. All other instance data is shared with the
# cached object.
- pk('t1',t)
t = copy.copy(t)
- pk('t2',t)
+
if codeset:
t.set_output_charset(codeset)
if result is None:
diff --git a/modules/language/python/module/struct.scm b/modules/language/python/module/struct.scm
index 05b38f2..66496d3 100644
--- a/modules/language/python/module/struct.scm
+++ b/modules/language/python/module/struct.scm
@@ -102,7 +102,6 @@
(define c-i4
(lambda (k)
(lambda (bv i)
- (pk bv i)
(cons (bytevector-s32-ref bv i end)
(k bv (incr i 4))))))
@@ -252,7 +251,7 @@
(bv-scm bv) n))
(define (unpack format buffer)
- (unpacker (pk (analyze format)) buffer 0))
+ (unpacker (analyze format) buffer 0))
(define unpack_from
(lam (format buffer (= offset 0))
diff --git a/modules/language/python/string.scm b/modules/language/python/string.scm
index 7ed0193..7d5bdd7 100644
--- a/modules/language/python/string.scm
+++ b/modules/language/python/string.scm
@@ -377,29 +377,31 @@
(define bytes #f)
+(define (geterr errors)
+ (set! errors (py-lower (scm-str errors)))
+ (cond
+ ((equal? errors "strict")
+ 'error)
+ ((equal? errors "escape")
+ 'escape)
+ ((equal? errors "replace")
+ 'substitute)
+ ((equal? errors "ignore")
+ (warn
+ (string-append
+ "not possible to use ignore "
+ "encodong error strategy "
+ "using replace in stead"))
+ 'substitute)
+ (else
+ (warn
+ "not a correct encodong error strategy")
+ 'error)))
+
(define-py (py-encode encode s . l)
(apply (lam ((= encoding "UTF-8") (= errors "strict"))
- (set! errors (py-lower (scm-str errors)))
- (set! errors (cond
- ((equal? errors "strict")
- 'error)
- ((equal? errors "escape")
- 'escape)
- ((equal? errors "replace")
- 'substitute)
- ((equal? errors "ignore")
- (warn
- (string-append
- "not possible to use ignore "
- "encodong error strategy "
- "using replace in stead"))
- 'substitute)
- (else
- (warn
- "not a correct encodong error strategy")
- 'error)))
(set! encoding (py-upper (scm-str encoding)))
-
+ (set! errors (geterr errors))
(bytes (string->bytevector (scm-str s) encoding errors)))
l))
@@ -558,19 +560,24 @@
(lp (+ i 1))))
s))))
+(define b? #f)
+(define b-decode #f)
(define-python-class string (<py-string>)
(define __init__
(case-lambda
- ((self s)
- (cond
- ((is-a? s <py-string>)
- (slot-ref s 'str))
- ((is-a? s <string>)
- s)
- (else
- (aif it (ref s '__str__)
- (it)
- (__init__ self ((@ (guile) format) #f "~a" s))))))))
+ ((self s . l)
+ (cond
+ ((is-a? s <py-string>)
+ (slot-ref s 'str))
+ ((is-a? s <string>)
+ s)
+ ((b? s)
+ (apply b-decode s l))
+ (else
+ (aif it (ref s '__str__)
+ (it)
+ (__init__ self ((@ (guile) format) #f "~a" s))))))))
+
(define __new__
(lambda x