Skip to content

Commit 7fa747a

Browse files
committed
Merge 'pycopy/master' into main
2 parents 33382b6 + 56ebf21 commit 7fa747a

File tree

91 files changed

+6524
-267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+6524
-267
lines changed

_boot/_boot.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@ def vars(obj):
88
def getrecursionlimit():
99
return 100
1010

11+
class Warning(Exception):
12+
pass
13+
class RuntimeWarning(Warning):
14+
pass
15+
1116

1217
def _setup():
1318
import builtins
1419

1520
builtins.vars = vars
1621
builtins.FileNotFoundError = OSError
22+
builtins.IOError = OSError
23+
builtins.Warning = Warning
24+
builtins.RuntimeWarning = RuntimeWarning
1725

1826
from micropython import writable_ns
1927
import sys
@@ -23,10 +31,10 @@ def _setup():
2331

2432
PATCHES = {
2533
str: (
26-
string, ("encode", "expandtabs", "isidentifier", "ljust", "translate"),
34+
string, ("capitalize", "encode", "expandtabs", "isalnum", "isidentifier", "ljust", "translate"),
2735
),
2836
bytes: (
29-
byteslib, ("fromhex", "hex"),
37+
byteslib, ("decode", "fromhex", "hex"),
3038
),
3139
set: (
3240
setlib, ("update", "union", "intersection_update", "intersection", "difference_update", "difference"),
@@ -44,6 +52,8 @@ def _setup():
4452
# to sys.stdout and friends. So, patch the module namespace directly.
4553
writable_ns(sys, True)
4654
sys.getrecursionlimit = getrecursionlimit
55+
sys.executable = "pycopy-dev"
56+
sys.warnoptions = []
4757
writable_ns(sys, False)
4858

4959

_boot/metadata.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
srctype = pycopy-lib
22
type = module
3-
version = 0.4
3+
version = 0.4.5
44
author = Paul Sokolovsky
55
desc = Bootstrapping module for pycopy-dev for CPython compatibility
66
dist_name = boot

argparse/argparse.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,25 +161,26 @@ def error(self, msg):
161161
sys.stderr.write("error: %s\n" % msg)
162162
sys.exit(2)
163163

164-
def parse_args(self, args=None):
165-
return self._parse_args_impl(args, False)
164+
def parse_args(self, args=None, namespace=None):
165+
return self._parse_args_impl(args, namespace, False)
166166

167-
def parse_known_args(self, args=None):
168-
return self._parse_args_impl(args, True)
167+
def parse_known_args(self, args=None, namespace=None):
168+
return self._parse_args_impl(args, namespace, True)
169169

170-
def _parse_args_impl(self, args, return_unknown):
170+
def _parse_args_impl(self, args, namespace, return_unknown):
171171
if args is None:
172172
args = sys.argv[1:]
173173
else:
174174
args = args[:]
175+
if namespace is None:
176+
namespace = Namespace()
175177
try:
176-
return self._parse_args(args, return_unknown)
178+
return self._parse_args(args, namespace, return_unknown)
177179
except _ArgError as e:
178180
self.usage(False)
179181
self.error(str(e))
180182

181-
def _parse_args(self, args, return_unknown):
182-
argholder = Namespace()
183+
def _parse_args(self, args, argholder, return_unknown):
183184
# add optional args with defaults
184185
for opt in self.opt:
185186
setattr(argholder, opt.dest, opt.default)

argparse/metadata.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
srctype = pycopy-lib
22
type = module
3-
version = 0.5.2
3+
version = 0.5.3
44
author = Damien George, Paul Sokolovsky

byteslib/byteslib.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
import ubinascii
3131

3232

33+
# In case it's overriden later
34+
_org_decode = bytes.decode
35+
def decode(b, encoding="utf-8", errors="strict"):
36+
assert encoding in ("utf-8", "ascii", "us-ascii"), "Unsupported encoding: %s" % encoding
37+
assert errors in ("strict", "surrogateescape", "surrogatepass"), "Unsupported errors param: %s" % errors
38+
return _org_decode(b, encoding, errors)
39+
40+
3341
def hex(s):
3442
s = ubinascii.hexlify(s)
3543
return pycopy.icast(s, str)

byteslib/metadata.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
srctype = pycopy-lib
22
type = module
3-
version = 0.1.1
3+
version = 0.1.2
44
author = Paul Sokolovsky
55
long_desc = Additional bytes methods (for CPython compatibility) represented as functions.

byteslib/test_byteslib.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@
2929
import byteslib
3030

3131

32-
byteslib.hex(b"\xab\xcd") == "abcd"
33-
byteslib.fromhex("abcd") == b"\xab\xcd"
32+
assert byteslib.hex(b"\xab\xcd") == "abcd"
33+
assert byteslib.fromhex("abcd") == b"\xab\xcd"
34+
assert byteslib.decode(b"1234") == "1234"
35+
assert byteslib.decode(b"1234", "ascii", "strict") == "1234"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class ChainMap:
2+
3+
def __init__(self, *maps):
4+
if maps:
5+
self.maps = list(maps)
6+
else:
7+
self.maps = [{}]
8+
9+
def __getitem__(self, k):
10+
for m in self.maps:
11+
if k in m:
12+
return m[k]
13+
raise KeyError(k)
14+
15+
def __setitem__(self, k, v):
16+
self.maps[0][k] = v
17+
18+
def __delitem__(self, k):
19+
del self.maps[0][k]
20+
21+
def items(self):
22+
seen = set()
23+
for m in self.maps:
24+
for k, v in m.items():
25+
if k not in seen:
26+
yield k, v
27+
seen.add(k)

collections.chainmap/metadata.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
srctype = pycopy-lib
2+
type = package
3+
version = 0.1.1
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from collections.chainmap import ChainMap
2+
3+
4+
cm = ChainMap({"k1": "v11", "k2": "v2"}, {"k1": "v12", "k3": "v3"})
5+
assert cm["k1"] == "v11"
6+
assert cm["k2"] == "v2"
7+
assert cm["k3"] == "v3"
8+
9+
items = sorted(list(cm.items()))
10+
assert items == [('k1', 'v11'), ('k2', 'v2'), ('k3', 'v3')]
11+
12+
del cm["k1"]
13+
assert cm["k1"] == "v12"
14+
cm["k1"] = "newv"
15+
assert cm["k1"] == "newv"
16+
del cm["k1"]
17+
assert cm["k1"] == "v12"

0 commit comments

Comments
 (0)