diff options
Diffstat (limited to 'modules/language/python/module')
-rw-r--r-- | modules/language/python/module/binascii.scm | 2 | ||||
-rw-r--r-- | modules/language/python/module/string.scm | 72 | ||||
-rw-r--r-- | modules/language/python/module/urllib/request.py | 6 | ||||
-rw-r--r-- | modules/language/python/module/urllib/robotparser.py | 25 |
4 files changed, 68 insertions, 37 deletions
diff --git a/modules/language/python/module/binascii.scm b/modules/language/python/module/binascii.scm index 2fc0e62..12bdcac 100644 --- a/modules/language/python/module/binascii.scm +++ b/modules/language/python/module/binascii.scm @@ -386,7 +386,7 @@ (lp (+ i 2) (cons x r))) (bytes (reverse r))))))) -(define (id x) x) +(define-inlinable (id x) x) (define-syntax-rule (mkcrc crc_hqx high xor mask) (def (crc_hqx data (= value 0)) (let ((n (len data)) diff --git a/modules/language/python/module/string.scm b/modules/language/python/module/string.scm index c99344c..9c0d818 100644 --- a/modules/language/python/module/string.scm +++ b/modules/language/python/module/string.scm @@ -9,7 +9,9 @@ #:use-module (language python for) #:use-module (language python def) #:use-module (language python string) - #:use-module (parser stis-parser) + #:use-module (language python bytes) + #:use-module ((parser stis-parser) #:select (*whitespace* f-n f-m)) + #:use-module (parser stis-parser lang python3 tool) #:export (Formatter ascii_letters digits hexdigits)) (define digits "0123456789") @@ -239,17 +241,27 @@ (f-cons argName (ff* (f-or! (f-list #:attr "." attributeName) (f-list #:elem "[" elementIndex "]"))))) -(define replField +(define (replField fieldName1) (f-list #:field - (ff? (mk-token (f-scope fieldName )) None) + (ff? fieldName1 None) (ff? (f-seq "!" (mk-token (f-scope conversion))) None) (ff? (f-seq ":" (mk-token (f-scope formatSpec))) None))) -(define tag (f-seq (f-tag "{") replField (f-tag "}"))) +(define (tag fieldName1) + (f-seq (f-tag "{") (replField fieldName1) (f-tag "}"))) + (define nontag (f-list #:str - (mk-token (f+ (f-or! (f-tag! "{{") (f-not! tag)))))) -(define e (f-seq (ff* (f-or! tag nontag)) f-eof)) + (mk-token (f+ + (f-or! + (f-tag! "{{") + (f-not! (tag (mk-token + (f-scope + fieldName))))))))) + +(define e (f-seq (ff* (f-or! (tag fieldName) nontag)) f-eof)) + +(set! (@@ (parser stis-parser lang python3-parser) f-formatter) tag) (define mk-gen (make-generator (l) @@ -293,24 +305,40 @@ (lam (self format_string (* args) (** kwargs)) ((ref self 'vformat) format_string args kwargs))) + (define vformat2 + (lambda (self fn2 co fo) + (if (and (eq? fo None) (eq? co None)) + ((ref self 'convert_field) fn2 "r") + (let ((fn3 (if (eq? co None) + fn2 + ((ref self 'convert_field) + fn2 co)))) + (if (eq? fo None) + fn3 + ((ref self 'format_field ) fn3 fo)))))) + + (define vformat1 + (lambda (self s fn fo co ss args kwargs) + (if (eq? fn None) + (cons s ss) + (let* ((fn2 ((ref self 'get_field ) fn args kwargs)) + (fn3 (if (and (eq? fo None) (eq? co None)) + ((ref self 'convert_field) fn2 "r") + (let ((fn3 (if (eq? co None) + fn2 + ((ref self 'convert_field) + fn2 co)))) + (if (eq? fo None) + fn3 + ((ref self 'format_field ) + fn3 fo)))))) + (cons* fn3 s ss))))) + (define vformat (lambda (self format_string args kwargs) (set self '_args '()) (for ((s fn fo co : ((ref self 'parse) format_string))) ((ss '(""))) - (if (eq? fn None) - (cons s ss) - (let* ((fn2 ((ref self 'get_field ) fn args kwargs)) - (fn3 (if (and (eq? fo None) (eq? co None)) - ((ref self 'convert_field) fn2 "r") - (let ((fn3 (if (eq? co None) - fn2 - ((ref self 'convert_field) - fn2 co)))) - (if (eq? fo None) - fn3 - ((ref self 'format_field ) - fn3 fo)))))) - (cons* fn3 s ss))) + (vformat self s fn fo co ss args kwargs) #:final (begin ((ref self 'check_unused_args) (ref self '_args) args kwargs) @@ -376,4 +404,6 @@ (define (ascii x) (bytes x)) -(set! (@@ (language python string) formatter) (Formatter)) +(define formatter (Formatter)) +(set! (@@ (language python string) formatter) formatter) +(set! (@@ (language python compile) formatter) (ref formatter 'vformat2)) diff --git a/modules/language/python/module/urllib/request.py b/modules/language/python/module/urllib/request.py index ff79318..d5372e5 100644 --- a/modules/language/python/module/urllib/request.py +++ b/modules/language/python/module/urllib/request.py @@ -82,7 +82,7 @@ f = urllib.request.urlopen('http://www.python.org/') # Possible extensions: # complex proxies XXX not sure what exactly was meant by this # abstract factory for opener - +pk(1) import base64 import bisect import email @@ -100,7 +100,7 @@ import collections import tempfile import contextlib import warnings - +pk(2) from urllib.error import URLError, HTTPError, ContentTooShortError from urllib.parse import ( @@ -109,7 +109,7 @@ from urllib.parse import ( splitattr, splitquery, splitvalue, splittag, to_bytes, unquote_to_bytes, urlunparse) from urllib.response import addinfourl, addclosehook - +pk(3) # check for SSL try: import ssl diff --git a/modules/language/python/module/urllib/robotparser.py b/modules/language/python/module/urllib/robotparser.py index f110d80..cde8b47 100644 --- a/modules/language/python/module/urllib/robotparser.py +++ b/modules/language/python/module/urllib/robotparser.py @@ -1,4 +1,4 @@ -module(urllib.robotparser) +module(urllib,robotparser) """ robotparser.py @@ -13,8 +13,9 @@ module(urllib.robotparser) """ import collections -import urllib.parse -import urllib.request +import urllib.parse as uparse +import urllib.error as error +import urllib.request as request __all__ = ["RobotFileParser"] @@ -55,13 +56,13 @@ class RobotFileParser: def set_url(self, url): """Sets the URL referring to a robots.txt file.""" self.url = url - self.host, self.path = urllib.parse.urlparse(url)[1:3] + self.host, self.path = uparse.urlparse(url)[1:3] def read(self): """Reads the robots.txt URL and feeds it to the parser.""" try: - f = urllib.request.urlopen(self.url) - except urllib.error.HTTPError as err: + f = request.urlopen(self.url) + except error.HTTPError as err: if err.code in (401, 403): self.disallow_all = True elif err.code >= 400 and err.code < 500: @@ -112,7 +113,7 @@ class RobotFileParser: line = line.split(':', 1) if len(line) == 2: line[0] = line[0].strip().lower() - line[1] = urllib.parse.unquote(line[1].strip()) + line[1] = uparse.unquote(line[1].strip()) if line[0] == "user-agent": if state == 2: self._add_entry(entry) @@ -160,10 +161,10 @@ class RobotFileParser: return False # search for given user agent matches # the first match counts - parsed_url = urllib.parse.urlparse(urllib.parse.unquote(url)) - url = urllib.parse.urlunparse(('','',parsed_url.path, + parsed_url = uparse.urlparse(uparse.unquote(url)) + url = uparse.urlunparse(('','',parsed_url.path, parsed_url.params,parsed_url.query, parsed_url.fragment)) - url = urllib.parse.quote(url) + url = uparse.quote(url) if not url: url = "/" for entry in self.entries: @@ -202,8 +203,8 @@ class RuleLine: if path == '' and not allowance: # an empty value means allow all allowance = True - path = urllib.parse.urlunparse(urllib.parse.urlparse(path)) - self.path = urllib.parse.quote(path) + path = uparse.urlunparse(uparse.urlparse(path)) + self.path = uparse.quote(path) self.allowance = allowance def applies_to(self, filename): |