From f9a1bd1d49e15d54a6a3e3d0184d636bad4cf5e0 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Tue, 6 Aug 2024 12:58:11 +0800 Subject: [PATCH] ... --- include/pocketpy/common/_generated.h | 1 - python/colorsys.py | 171 --------------------------- src/common/_generated.c | 2 - tests/70_base64.py | 21 ---- tests/80_csv.py | 50 -------- 5 files changed, 245 deletions(-) delete mode 100644 python/colorsys.py delete mode 100644 tests/70_base64.py delete mode 100644 tests/80_csv.py diff --git a/include/pocketpy/common/_generated.h b/include/pocketpy/common/_generated.h index 2e2eb1d6..2429f556 100644 --- a/include/pocketpy/common/_generated.h +++ b/include/pocketpy/common/_generated.h @@ -14,7 +14,6 @@ extern const char kPythonLibs_bisect[]; extern const char kPythonLibs_builtins[]; extern const char kPythonLibs_cmath[]; extern const char kPythonLibs_collections[]; -extern const char kPythonLibs_colorsys[]; extern const char kPythonLibs_datetime[]; extern const char kPythonLibs_functools[]; extern const char kPythonLibs_heapq[]; diff --git a/python/colorsys.py b/python/colorsys.py deleted file mode 100644 index aea51f19..00000000 --- a/python/colorsys.py +++ /dev/null @@ -1,171 +0,0 @@ -"""Conversion functions between RGB and other color systems. - -This modules provides two functions for each color system ABC: - - rgb_to_abc(r, g, b) --> a, b, c - abc_to_rgb(a, b, c) --> r, g, b - -All inputs and outputs are triples of floats in the range [0.0...1.0] -(with the exception of I and Q, which covers a slightly larger range). -Inputs outside the valid range may cause exceptions or invalid outputs. - -Supported color systems: -RGB: Red, Green, Blue components -YIQ: Luminance, Chrominance (used by composite video signals) -HLS: Hue, Luminance, Saturation -HSV: Hue, Saturation, Value -""" - -# References: -# http://en.wikipedia.org/wiki/YIQ -# http://en.wikipedia.org/wiki/HLS_color_space -# http://en.wikipedia.org/wiki/HSV_color_space - -__all__ = ["rgb_to_yiq","yiq_to_rgb","rgb_to_hls","hls_to_rgb", - "rgb_to_hsv","hsv_to_rgb"] - -# Some floating point constants - -ONE_THIRD = 1.0/3.0 -ONE_SIXTH = 1.0/6.0 -TWO_THIRD = 2.0/3.0 - -# YIQ: used by composite video signals (linear combinations of RGB) -# Y: perceived grey level (0.0 == black, 1.0 == white) -# I, Q: color components -# -# There are a great many versions of the constants used in these formulae. -# The ones in this library uses constants from the FCC version of NTSC. - -def rgb_to_yiq(r, g, b): - y = 0.30*r + 0.59*g + 0.11*b - i = 0.74*(r-y) - 0.27*(b-y) - q = 0.48*(r-y) + 0.41*(b-y) - return (y, i, q) - -def yiq_to_rgb(y, i, q): - # r = y + (0.27*q + 0.41*i) / (0.74*0.41 + 0.27*0.48) - # b = y + (0.74*q - 0.48*i) / (0.74*0.41 + 0.27*0.48) - # g = y - (0.30*(r-y) + 0.11*(b-y)) / 0.59 - - r = y + 0.9468822170900693*i + 0.6235565819861433*q - g = y - 0.27478764629897834*i - 0.6356910791873801*q - b = y - 1.1085450346420322*i + 1.7090069284064666*q - - if r < 0.0: - r = 0.0 - if g < 0.0: - g = 0.0 - if b < 0.0: - b = 0.0 - if r > 1.0: - r = 1.0 - if g > 1.0: - g = 1.0 - if b > 1.0: - b = 1.0 - return (r, g, b) - - -# HLS: Hue, Luminance, Saturation -# H: position in the spectrum -# L: color lightness -# S: color saturation - -def rgb_to_hls(r, g, b): - maxc = max(r, g, b) - minc = min(r, g, b) - sumc = (maxc+minc) - rangec = (maxc-minc) - l = sumc/2.0 - if minc == maxc: - return 0.0, l, 0.0 - if l <= 0.5: - s = rangec / sumc - else: - s = rangec / (2.0-maxc-minc) # Not always 2.0-sumc: gh-106498. - rc = (maxc-r) / rangec - gc = (maxc-g) / rangec - bc = (maxc-b) / rangec - if r == maxc: - h = bc-gc - elif g == maxc: - h = 2.0+rc-bc - else: - h = 4.0+gc-rc - # h = (h/6.0) % 1.0 - h = h / 6.0 - h = h - int(h) - return h, l, s - -def hls_to_rgb(h, l, s): - if s == 0.0: - return l, l, l - if l <= 0.5: - m2 = l * (1.0+s) - else: - m2 = l+s-(l*s) - m1 = 2.0*l - m2 - return (_v(m1, m2, h+ONE_THIRD), _v(m1, m2, h), _v(m1, m2, h-ONE_THIRD)) - -def _v(m1, m2, hue): - # hue = hue % 1.0 - hue = hue - int(hue) - if hue < ONE_SIXTH: - return m1 + (m2-m1)*hue*6.0 - if hue < 0.5: - return m2 - if hue < TWO_THIRD: - return m1 + (m2-m1)*(TWO_THIRD-hue)*6.0 - return m1 - - -# HSV: Hue, Saturation, Value -# H: position in the spectrum -# S: color saturation ("purity") -# V: color brightness - -def rgb_to_hsv(r, g, b): - maxc = max(r, g, b) - minc = min(r, g, b) - rangec = (maxc-minc) - v = maxc - if minc == maxc: - return 0.0, 0.0, v - s = rangec / maxc - rc = (maxc-r) / rangec - gc = (maxc-g) / rangec - bc = (maxc-b) / rangec - if r == maxc: - h = bc-gc - elif g == maxc: - h = 2.0+rc-bc - else: - h = 4.0+gc-rc - # h = (h/6.0) % 1.0 - h = h / 6.0 - h = h - int(h) - return h, s, v - -def hsv_to_rgb(h, s, v): - if s == 0.0: - return v, v, v - i = int(h*6.0) # XXX assume int() truncates! - f = (h*6.0) - i - p = v*(1.0 - s) - q = v*(1.0 - s*f) - t = v*(1.0 - s*(1.0-f)) - i = i%6 - if i == 0: - return v, t, p - if i == 1: - return q, v, p - if i == 2: - return p, v, t - if i == 3: - return p, q, v - if i == 4: - return t, p, v - if i == 5: - return v, p, q - # Cannot get here \ No newline at end of file diff --git a/src/common/_generated.c b/src/common/_generated.c index d5531c60..4981d95e 100644 --- a/src/common/_generated.c +++ b/src/common/_generated.c @@ -8,7 +8,6 @@ const char kPythonLibs_bisect[] = "\"\"\"Bisection algorithms.\"\"\"\n\ndef inso const char kPythonLibs_builtins[] = "from pkpy import next as __builtins_next\n\ndef all(iterable):\n for i in iterable:\n if not i:\n return False\n return True\n\ndef any(iterable):\n for i in iterable:\n if i:\n return True\n return False\n\ndef enumerate(iterable, start=0):\n n = start\n for elem in iterable:\n yield n, elem\n n += 1\n\ndef sum(iterable):\n res = 0\n for i in iterable:\n res += i\n return res\n\ndef map(f, iterable):\n for i in iterable:\n yield f(i)\n\ndef filter(f, iterable):\n for i in iterable:\n if f(i):\n yield i\n\ndef zip(a, b):\n a = iter(a)\n b = iter(b)\n while True:\n ai = __builtins_next(a)\n bi = __builtins_next(b)\n if ai is StopIteration or bi is StopIteration:\n break\n yield ai, bi\n\ndef reversed(iterable):\n a = list(iterable)\n a.reverse()\n return a\n\ndef sorted(iterable, key=None, reverse=False):\n a = list(iterable)\n a.sort(key=key, reverse=reverse)\n return a\n\n##### str #####\ndef __format_string(self: str, *args, **kwargs) -> str:\n def tokenizeString(s: str):\n tokens = []\n L, R = 0,0\n \n mode = None\n curArg = 0\n # lookingForKword = False\n \n while(R int:\n n = 0\n for item in self:\n if item == x:\n n += 1\n return n\n \n def extend(self, iterable: Iterable[T]):\n for x in iterable:\n self.append(x)\n\n def extendleft(self, iterable: Iterable[T]):\n for x in iterable:\n self.appendleft(x)\n \n def pop(self) -> T:\n if self._head == self._tail:\n raise IndexError(\"pop from an empty deque\")\n self._tail = (self._tail - 1 + self._capacity) % self._capacity\n return self._data[self._tail]\n \n def popleft(self) -> T:\n if self._head == self._tail:\n raise IndexError(\"pop from an empty deque\")\n x = self._data[self._head]\n self._head = (self._head + 1) % self._capacity\n return x\n \n def clear(self):\n i = self._head\n while i != self._tail:\n self._data[i] = None\n i = (i + 1) % self._capacity\n self._head = 0\n self._tail = 0\n\n def rotate(self, n: int = 1):\n if len(self) == 0:\n return\n if n > 0:\n n = n % len(self)\n for _ in range(n):\n self.appendleft(self.pop())\n elif n < 0:\n n = -n % len(self)\n for _ in range(n):\n self.append(self.popleft())\n\n def __len__(self) -> int:\n return (self._tail - self._head + self._capacity) % self._capacity\n\n def __contains__(self, x: object) -> bool:\n for item in self:\n if item == x:\n return True\n return False\n \n def __iter__(self):\n i = self._head\n while i != self._tail:\n yield self._data[i]\n i = (i + 1) % self._capacity\n\n def __eq__(self, other: object) -> bool:\n if not isinstance(other, deque):\n return False\n if len(self) != len(other):\n return False\n for x, y in zip(self, other):\n if x != y:\n return False\n return True\n \n def __repr__(self) -> str:\n return f\"deque({list(self)!r})\"\n\n"; -const char kPythonLibs_colorsys[] = "\"\"\"Conversion functions between RGB and other color systems.\n\nThis modules provides two functions for each color system ABC:\n\n rgb_to_abc(r, g, b) --> a, b, c\n abc_to_rgb(a, b, c) --> r, g, b\n\nAll inputs and outputs are triples of floats in the range [0.0...1.0]\n(with the exception of I and Q, which covers a slightly larger range).\nInputs outside the valid range may cause exceptions or invalid outputs.\n\nSupported color systems:\nRGB: Red, Green, Blue components\nYIQ: Luminance, Chrominance (used by composite video signals)\nHLS: Hue, Luminance, Saturation\nHSV: Hue, Saturation, Value\n\"\"\"\n\n# References:\n# http://en.wikipedia.org/wiki/YIQ\n# http://en.wikipedia.org/wiki/HLS_color_space\n# http://en.wikipedia.org/wiki/HSV_color_space\n\n__all__ = [\"rgb_to_yiq\",\"yiq_to_rgb\",\"rgb_to_hls\",\"hls_to_rgb\",\n \"rgb_to_hsv\",\"hsv_to_rgb\"]\n\n# Some floating point constants\n\nONE_THIRD = 1.0/3.0\nONE_SIXTH = 1.0/6.0\nTWO_THIRD = 2.0/3.0\n\n# YIQ: used by composite video signals (linear combinations of RGB)\n# Y: perceived grey level (0.0 == black, 1.0 == white)\n# I, Q: color components\n#\n# There are a great many versions of the constants used in these formulae.\n# The ones in this library uses constants from the FCC version of NTSC.\n\ndef rgb_to_yiq(r, g, b):\n y = 0.30*r + 0.59*g + 0.11*b\n i = 0.74*(r-y) - 0.27*(b-y)\n q = 0.48*(r-y) + 0.41*(b-y)\n return (y, i, q)\n\ndef yiq_to_rgb(y, i, q):\n # r = y + (0.27*q + 0.41*i) / (0.74*0.41 + 0.27*0.48)\n # b = y + (0.74*q - 0.48*i) / (0.74*0.41 + 0.27*0.48)\n # g = y - (0.30*(r-y) + 0.11*(b-y)) / 0.59\n\n r = y + 0.9468822170900693*i + 0.6235565819861433*q\n g = y - 0.27478764629897834*i - 0.6356910791873801*q\n b = y - 1.1085450346420322*i + 1.7090069284064666*q\n\n if r < 0.0:\n r = 0.0\n if g < 0.0:\n g = 0.0\n if b < 0.0:\n b = 0.0\n if r > 1.0:\n r = 1.0\n if g > 1.0:\n g = 1.0\n if b > 1.0:\n b = 1.0\n return (r, g, b)\n\n\n# HLS: Hue, Luminance, Saturation\n# H: position in the spectrum\n# L: color lightness\n# S: color saturation\n\ndef rgb_to_hls(r, g, b):\n maxc = max(r, g, b)\n minc = min(r, g, b)\n sumc = (maxc+minc)\n rangec = (maxc-minc)\n l = sumc/2.0\n if minc == maxc:\n return 0.0, l, 0.0\n if l <= 0.5:\n s = rangec / sumc\n else:\n s = rangec / (2.0-maxc-minc) # Not always 2.0-sumc: gh-106498.\n rc = (maxc-r) / rangec\n gc = (maxc-g) / rangec\n bc = (maxc-b) / rangec\n if r == maxc:\n h = bc-gc\n elif g == maxc:\n h = 2.0+rc-bc\n else:\n h = 4.0+gc-rc\n # h = (h/6.0) % 1.0\n h = h / 6.0\n h = h - int(h)\n return h, l, s\n\ndef hls_to_rgb(h, l, s):\n if s == 0.0:\n return l, l, l\n if l <= 0.5:\n m2 = l * (1.0+s)\n else:\n m2 = l+s-(l*s)\n m1 = 2.0*l - m2\n return (_v(m1, m2, h+ONE_THIRD), _v(m1, m2, h), _v(m1, m2, h-ONE_THIRD))\n\ndef _v(m1, m2, hue):\n # hue = hue % 1.0\n hue = hue - int(hue)\n if hue < ONE_SIXTH:\n return m1 + (m2-m1)*hue*6.0\n if hue < 0.5:\n return m2\n if hue < TWO_THIRD:\n return m1 + (m2-m1)*(TWO_THIRD-hue)*6.0\n return m1\n\n\n# HSV: Hue, Saturation, Value\n# H: position in the spectrum\n# S: color saturation (\"purity\")\n# V: color brightness\n\ndef rgb_to_hsv(r, g, b):\n maxc = max(r, g, b)\n minc = min(r, g, b)\n rangec = (maxc-minc)\n v = maxc\n if minc == maxc:\n return 0.0, 0.0, v\n s = rangec / maxc\n rc = (maxc-r) / rangec\n gc = (maxc-g) / rangec\n bc = (maxc-b) / rangec\n if r == maxc:\n h = bc-gc\n elif g == maxc:\n h = 2.0+rc-bc\n else:\n h = 4.0+gc-rc\n # h = (h/6.0) % 1.0\n h = h / 6.0\n h = h - int(h)\n return h, s, v\n\ndef hsv_to_rgb(h, s, v):\n if s == 0.0:\n return v, v, v\n i = int(h*6.0) # XXX assume int() truncates!\n f = (h*6.0) - i\n p = v*(1.0 - s)\n q = v*(1.0 - s*f)\n t = v*(1.0 - s*(1.0-f))\n i = i%6\n if i == 0:\n return v, t, p\n if i == 1:\n return q, v, p\n if i == 2:\n return p, v, t\n if i == 3:\n return p, q, v\n if i == 4:\n return t, p, v\n if i == 5:\n return v, p, q\n # Cannot get here"; const char kPythonLibs_datetime[] = "from time import localtime\n\nclass timedelta:\n def __init__(self, days=0, seconds=0):\n self.days = days\n self.seconds = seconds\n\n def __repr__(self):\n return f\"datetime.timedelta(days={self.days}, seconds={self.seconds})\"\n\n def __eq__(self, other: 'timedelta') -> bool:\n if type(other) is not timedelta:\n return NotImplemented\n return (self.days, self.seconds) == (other.days, other.seconds)\n\n def __lt__(self, other: 'timedelta') -> bool:\n if type(other) is not timedelta:\n return NotImplemented\n return (self.days, self.seconds) < (other.days, other.seconds)\n\n def __le__(self, other: 'timedelta') -> bool:\n if type(other) is not timedelta:\n return NotImplemented\n return (self.days, self.seconds) <= (other.days, other.seconds)\n\n def __gt__(self, other: 'timedelta') -> bool:\n if type(other) is not timedelta:\n return NotImplemented\n return (self.days, self.seconds) > (other.days, other.seconds)\n\n def __ge__(self, other: 'timedelta') -> bool:\n if type(other) is not timedelta:\n return NotImplemented\n return (self.days, self.seconds) >= (other.days, other.seconds)\n\n\nclass date:\n def __init__(self, year: int, month: int, day: int):\n self.year = year\n self.month = month\n self.day = day\n\n @staticmethod\n def today():\n t = localtime()\n return date(t.tm_year, t.tm_mon, t.tm_mday)\n\n def __eq__(self, other: 'date') -> bool:\n if type(other) is not date:\n return NotImplemented\n return (self.year, self.month, self.day) == (other.year, other.month, other.day)\n\n def __lt__(self, other: 'date') -> bool:\n if type(other) is not date:\n return NotImplemented\n return (self.year, self.month, self.day) < (other.year, other.month, other.day)\n\n def __le__(self, other: 'date') -> bool:\n if type(other) is not date:\n return NotImplemented\n return (self.year, self.month, self.day) <= (other.year, other.month, other.day)\n\n def __gt__(self, other: 'date') -> bool:\n if type(other) is not date:\n return NotImplemented\n return (self.year, self.month, self.day) > (other.year, other.month, other.day)\n\n def __ge__(self, other: 'date') -> bool:\n if type(other) is not date:\n return NotImplemented\n return (self.year, self.month, self.day) >= (other.year, other.month, other.day)\n\n def __str__(self):\n return f\"{self.year}-{self.month:02}-{self.day:02}\"\n\n def __repr__(self):\n return f\"datetime.date({self.year}, {self.month}, {self.day})\"\n\n\nclass datetime(date):\n def __init__(self, year: int, month: int, day: int, hour: int, minute: int, second: int):\n super().__init__(year, month, day)\n # Validate and set hour, minute, and second\n if not 0 <= hour <= 23:\n raise ValueError(\"Hour must be between 0 and 23\")\n self.hour = hour\n if not 0 <= minute <= 59:\n raise ValueError(\"Minute must be between 0 and 59\")\n self.minute = minute\n if not 0 <= second <= 59:\n raise ValueError(\"Second must be between 0 and 59\")\n self.second = second\n\n def date(self) -> date:\n return date(self.year, self.month, self.day)\n\n @staticmethod\n def now():\n t = localtime()\n tm_sec = t.tm_sec\n if tm_sec == 60:\n tm_sec = 59\n return datetime(t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, tm_sec)\n\n def __str__(self):\n return f\"{self.year}-{self.month:02}-{self.day:02} {self.hour:02}:{self.minute:02}:{self.second:02}\"\n\n def __repr__(self):\n return f\"datetime.datetime({self.year}, {self.month}, {self.day}, {self.hour}, {self.minute}, {self.second})\"\n\n def __eq__(self, other) -> bool:\n if type(other) is not datetime:\n return NotImplemented\n return (self.year, self.month, self.day, self.hour, self.minute, self.second) ==\x5c\n (other.year, other.month, other.day,\n other.hour, other.minute, other.second)\n\n def __lt__(self, other) -> bool:\n if type(other) is not datetime:\n return NotImplemented\n return (self.year, self.month, self.day, self.hour, self.minute, self.second) <\x5c\n (other.year, other.month, other.day,\n other.hour, other.minute, other.second)\n\n def __le__(self, other) -> bool:\n if type(other) is not datetime:\n return NotImplemented\n return (self.year, self.month, self.day, self.hour, self.minute, self.second) <=\x5c\n (other.year, other.month, other.day,\n other.hour, other.minute, other.second)\n\n def __gt__(self, other) -> bool:\n if type(other) is not datetime:\n return NotImplemented\n return (self.year, self.month, self.day, self.hour, self.minute, self.second) >\x5c\n (other.year, other.month, other.day,\n other.hour, other.minute, other.second)\n\n def __ge__(self, other) -> bool:\n if type(other) is not datetime:\n return NotImplemented\n return (self.year, self.month, self.day, self.hour, self.minute, self.second) >=\x5c\n (other.year, other.month, other.day,\n other.hour, other.minute, other.second)\n\n def timestamp(self) -> float:\n raise NotImplementedError\n\n"; const char kPythonLibs_functools[] = "class cache:\n def __init__(self, f):\n self.f = f\n self.cache = {}\n\n def __call__(self, *args):\n if args not in self.cache:\n self.cache[args] = self.f(*args)\n return self.cache[args]\n \ndef reduce(function, sequence, initial=...):\n it = iter(sequence)\n if initial is ...:\n try:\n value = next(it)\n except StopIteration:\n raise TypeError(\"reduce() of empty sequence with no initial value\")\n else:\n value = initial\n for element in it:\n value = function(value, element)\n return value\n\nclass partial:\n def __init__(self, f, *args, **kwargs):\n self.f = f\n if not callable(f):\n raise TypeError(\"the first argument must be callable\")\n self.args = args\n self.kwargs = kwargs\n\n def __call__(self, *args, **kwargs):\n kwargs.update(self.kwargs)\n return self.f(*self.args, *args, **kwargs)\n\n"; const char kPythonLibs_heapq[] = "# Heap queue algorithm (a.k.a. priority queue)\ndef heappush(heap, item):\n \"\"\"Push item onto heap, maintaining the heap invariant.\"\"\"\n heap.append(item)\n _siftdown(heap, 0, len(heap)-1)\n\ndef heappop(heap):\n \"\"\"Pop the smallest item off the heap, maintaining the heap invariant.\"\"\"\n lastelt = heap.pop() # raises appropriate IndexError if heap is empty\n if heap:\n returnitem = heap[0]\n heap[0] = lastelt\n _siftup(heap, 0)\n return returnitem\n return lastelt\n\ndef heapreplace(heap, item):\n \"\"\"Pop and return the current smallest value, and add the new item.\n\n This is more efficient than heappop() followed by heappush(), and can be\n more appropriate when using a fixed-size heap. Note that the value\n returned may be larger than item! That constrains reasonable uses of\n this routine unless written as part of a conditional replacement:\n\n if item > heap[0]:\n item = heapreplace(heap, item)\n \"\"\"\n returnitem = heap[0] # raises appropriate IndexError if heap is empty\n heap[0] = item\n _siftup(heap, 0)\n return returnitem\n\ndef heappushpop(heap, item):\n \"\"\"Fast version of a heappush followed by a heappop.\"\"\"\n if heap and heap[0] < item:\n item, heap[0] = heap[0], item\n _siftup(heap, 0)\n return item\n\ndef heapify(x):\n \"\"\"Transform list into a heap, in-place, in O(len(x)) time.\"\"\"\n n = len(x)\n # Transform bottom-up. The largest index there's any point to looking at\n # is the largest with a child index in-range, so must have 2*i + 1 < n,\n # or i < (n-1)/2. If n is even = 2*j, this is (2*j-1)/2 = j-1/2 so\n # j-1 is the largest, which is n//2 - 1. If n is odd = 2*j+1, this is\n # (2*j+1-1)/2 = j so j-1 is the largest, and that's again n//2-1.\n for i in reversed(range(n//2)):\n _siftup(x, i)\n\n# 'heap' is a heap at all indices >= startpos, except possibly for pos. pos\n# is the index of a leaf with a possibly out-of-order value. Restore the\n# heap invariant.\ndef _siftdown(heap, startpos, pos):\n newitem = heap[pos]\n # Follow the path to the root, moving parents down until finding a place\n # newitem fits.\n while pos > startpos:\n parentpos = (pos - 1) >> 1\n parent = heap[parentpos]\n if newitem < parent:\n heap[pos] = parent\n pos = parentpos\n continue\n break\n heap[pos] = newitem\n\ndef _siftup(heap, pos):\n endpos = len(heap)\n startpos = pos\n newitem = heap[pos]\n # Bubble up the smaller child until hitting a leaf.\n childpos = 2*pos + 1 # leftmost child position\n while childpos < endpos:\n # Set childpos to index of smaller child.\n rightpos = childpos + 1\n if rightpos < endpos and not heap[childpos] < heap[rightpos]:\n childpos = rightpos\n # Move the smaller child up.\n heap[pos] = heap[childpos]\n pos = childpos\n childpos = 2*pos + 1\n # The leaf at pos is empty now. Put newitem there, and bubble it up\n # to its final resting place (by sifting its parents down).\n heap[pos] = newitem\n _siftdown(heap, startpos, pos)"; @@ -24,7 +23,6 @@ const char* load_kPythonLib(const char* name) { if (strcmp(name, "builtins") == 0) return kPythonLibs_builtins; if (strcmp(name, "cmath") == 0) return kPythonLibs_cmath; if (strcmp(name, "collections") == 0) return kPythonLibs_collections; - if (strcmp(name, "colorsys") == 0) return kPythonLibs_colorsys; if (strcmp(name, "datetime") == 0) return kPythonLibs_datetime; if (strcmp(name, "functools") == 0) return kPythonLibs_functools; if (strcmp(name, "heapq") == 0) return kPythonLibs_heapq; diff --git a/tests/70_base64.py b/tests/70_base64.py deleted file mode 100644 index 488afd4f..00000000 --- a/tests/70_base64.py +++ /dev/null @@ -1,21 +0,0 @@ -a = '测试 123' -a = a.encode() - -import base64 - -b = base64.b64encode(a) -c = base64.b64decode(b) - -assert a == c - - -data = [66, 110, 145, 18, 176, 13, 255, 202, 173, 109, 178, 194, 171, 198, 143, 24, 113, 46, 70, 94, 71, 140, 159, 191, 134, 230, 190, 224, 223, 94, 217, 20, 241, 138, 104, 120, 249, 91, 134, 48, 108, 49, 0, 249, 235, 225, 228, 190, 63, 204, 216, 102, 153, 51, 79, 221, 234, 252, 231, 156, 74, 23, 131, 161, 172, 157, 26, 15, 88, 28, 21, 170, 86, 177, 177, 249, 111, 230, 35, 180, 61, 140, 33, 14, 74, 238, 253, 19, 177, 76, 249, 21, 35, 105, 24, 136, 187, 121, 71, 202, 239, 235, 71, 126, 60, 37, 83, 186, 102, 114, 95, 212, 81, 48, 102, 167, 208, 66, 250, 132, 199, 137, 141, 231, 126, 219, 125, 1, 86, 87, 132, 161, 55, 166, 192, 27, 95, 27, 237, 225, 32, 240, 234, 160, 247, 143, 241, 232, 195, 117, 83, 133, 69, 178, 239, 123, 144, 172, 34, 43, 56, 136, 184, 68, 65, 70, 61, 164, 109, 134, 142, 153, 125, 154, 62, 117, 166, 86, 234, 39, 73, 207, 67, 91, 88, 220, 43, 148, 201, 185, 128, 93, 151, 210, 167, 82, 87, 246, 171, 125, 210, 46, 60, 156, 4, 173, 219, 149, 24, 226, 63, 176, 92, 103, 126, 201, 254, 6, 186, 233, 165, 169, 237, 141, 252, 0, 195, 212, 222, 186, 103, 15, 137, 41, 251, 16, 163, 22, 177, 232, 205, 58, 50, 205, 89, 249, 38, 45, 98, 42, 155, 33, 225, 232, 16, 157, 91, 246, 207, 164, 150, 214, 76, 151, 179, 203, 67, 194, 213, 83, 2, 106, 109, 254, 15, 110, 168, 19, 114, 185, 174, 20, 106, 141, 116, 222, 205, 135, 222, 110, 90, 27, 61, 6, 118, 50, 155, 6, 224, 213, 109, 98, 252, 84, 166, 77, 124, 187, 187, 113, 173, 45, 17, 232, 208, 126, 248, 239, 18, 33, 205, 117, 44, 32, 223, 1, 221, 210, 41, 67, 28, 218, 218, 161, 209, 11, 93, 250, 96, 2, 43, 157, 217, 134, 183, 24, 105, 177, 74, 214, 18, 114, 191, 64, 195, 94, 194, 19, 115, 211, 103, 49, 218, 87, 8, 199, 50, 225, 174, 222, 75, 23, 159, 76, 56, 208, 224, 172, 48, 197, 126, 159, 191, 80, 216, 148, 30, 114, 231, 142, 100, 159, 67, 77, 190, 64, 182, 21, 108, 4, 232, 73, 145, 247, 196, 220, 197, 234, 55, 241, 212, 115, 115, 142, 172, 248, 132, 117, 115, 107, 176, 230, 130, 189, 160, 150, 63, 79, 253, 240, 113, 61, 222, 46, 102, 118, 100, 208, 170, 0, 60, 154, 102, 168, 241, 159, 146, 71, 55, 244, 123, 82, 49, 64, 231, 190, 49, 51, 16, 111, 153, 209, 208, 116, 19, 68, 139, 208, 105, 248, 80, 12, 237, 29, 63, 80, 127, 1, 118, 22, 39, 83, 25, 220, 75, 31, 152, 16, 94, 254, 141, 55, 6, 89, 45, 247, 229, 209, 239, 223, 226, 124, 50, 51, 219, 110, 100, 251, 122, 53, 166, 63, 43, 116, 190, 114, 169, 72, 18, 190, 55, 4, 249, 3, 200, 99, 0, 37, 94, 50, 58, 37, 56, 154, 18, 154, 127, 123, 187, 123, 110, 131, 14, 185, 76, 193, 11, 227, 36, 184, 88, 3, 222, 126, 32, 143, 125, 180, 104, 142, 84, 22, 53, 2, 38, 188, 187, 51, 163, 189, 25, 215, 94, 190, 196, 213, 155, 23, 84, 206, 237, 125, 76, 185, 12, 111, 201, 249, 101, 50, 217, 32, 3, 37, 49, 177, 4, 10, 123, 29, 126, 106, 108, 246, 89, 42, 182, 135, 11, 152, 122, 12, 23, 159, 212, 53, 44, 244, 48, 251, 130, 109, 191, 76, 148, 226, 83, 55, 225, 100, 196, 166, 171, 108, 91, 67, 226, 207, 143, 73, 81, 95, 69, 92, 141, 150, 108, 168, 235, 1, 33, 160, 158, 62, 149, 0, 200, 228, 176, 38, 112, 18, 253, 239, 107, 214, 17, 22, 112, 255, 117, 155, 248, 59, 113, 100, 145, 101, 245, 113, 230, 167, 58, 232, 195, 51, 76, 26, 7, 94, 201, 198, 96, 93, 8, 231, 60, 139, 37, 191, 37, 101, 155, 83, 246, 181, 109, 149, 241, 96, 168, 126, 232, 54, 230, 197, 179, 214, 148, 79, 13, 27, 195, 164, 146, 183, 129, 82, 82, 177, 2, 255, 8, 85, 214, 83, 244, 237, 143, 104, 107, 28, 215, 178, 46, 71, 175, 186, 77, 191, 93, 13, 204, 154, 234, 193, 231, 49, 27, 7, 66, 53, 170, 63, 3, 172, 177, 176, 255, 249, 116, 172, 165, 78, 64, 218, 147, 214, 206, 68, 42, 186, 119, 75, 28, 141, 187, 117, 21, 89, 69, 96, 79, 211, 1, 141] -data = bytes(data) -encoded = base64.b64encode(data) - -res = 'Qm6RErAN/8qtbbLCq8aPGHEuRl5HjJ+/hua+4N9e2RTximh4+VuGMGwxAPnr4eS+P8zYZpkzT93q/OecSheDoaydGg9YHBWqVrGx+W/mI7Q9jCEOSu79E7FM+RUjaRiIu3lHyu/rR348JVO6ZnJf1FEwZqfQQvqEx4mN537bfQFWV4ShN6bAG18b7eEg8Oqg94/x6MN1U4VFsu97kKwiKziIuERBRj2kbYaOmX2aPnWmVuonSc9DW1jcK5TJuYBdl9KnUlf2q33SLjycBK3blRjiP7BcZ37J/ga66aWp7Y38AMPU3rpnD4kp+xCjFrHozToyzVn5Ji1iKpsh4egQnVv2z6SW1kyXs8tDwtVTAmpt/g9uqBNyua4Uao103s2H3m5aGz0GdjKbBuDVbWL8VKZNfLu7ca0tEejQfvjvEiHNdSwg3wHd0ilDHNraodELXfpgAiud2Ya3GGmxStYScr9Aw17CE3PTZzHaVwjHMuGu3ksXn0w40OCsMMV+n79Q2JQecueOZJ9DTb5AthVsBOhJkffE3MXqN/HUc3OOrPiEdXNrsOaCvaCWP0/98HE93i5mdmTQqgA8mmao8Z+SRzf0e1IxQOe+MTMQb5nR0HQTRIvQafhQDO0dP1B/AXYWJ1MZ3EsfmBBe/o03Blkt9+XR79/ifDIz225k+3o1pj8rdL5yqUgSvjcE+QPIYwAlXjI6JTiaEpp/e7t7boMOuUzBC+MkuFgD3n4gj320aI5UFjUCJry7M6O9GddevsTVmxdUzu19TLkMb8n5ZTLZIAMlMbEECnsdfmps9lkqtocLmHoMF5/UNSz0MPuCbb9MlOJTN+FkxKarbFtD4s+PSVFfRVyNlmyo6wEhoJ4+lQDI5LAmcBL972vWERZw/3Wb+DtxZJFl9XHmpzrowzNMGgdeycZgXQjnPIslvyVlm1P2tW2V8WCofug25sWz1pRPDRvDpJK3gVJSsQL/CFXWU/Ttj2hrHNeyLkevuk2/XQ3MmurB5zEbB0I1qj8DrLGw//l0rKVOQNqT1s5EKrp3SxyNu3UVWUVgT9MBjQ==' -assert encoded.decode() == res - -decoded = base64.b64decode(encoded) -assert decoded == data - diff --git a/tests/80_csv.py b/tests/80_csv.py deleted file mode 100644 index 7e13ba29..00000000 --- a/tests/80_csv.py +++ /dev/null @@ -1,50 +0,0 @@ -import csv -def test(data: str, expected): - ret = list(csv.reader(data.splitlines())) - assert ret==expected, f"Expected {expected}, got {ret}" - -test("""a,b,c -1,2,3 -""", [['a', 'b', 'c'], ['1', '2', '3']]) - -test("""a,b,c -1,2,"3" -""", [['a', 'b', 'c'], ['1', '2', '3']]) - -test("""a,b,c -1,2,"3,," -""", [['a', 'b', 'c'], ['1', '2', '3,,']]) - -test("""a,b,c -1,2,'3' -""", [['a', 'b', 'c'], ['1', '2', '\'3\'']]) - -test('''a,b,c -1,2,"123""" -''', [['a', 'b', 'c'], ['1', '2', '123"']]) - -test("""a,b,c, -1,2,3, -""", [['a', 'b', 'c', ''], ['1', '2', '3', '']]) - -test("""a,b ,c, -1,"22""33",3 -""", [['a', 'b ', 'c', ''], ['1', '22"33', '3']]) - -# newline -test('''a,b,c -1,2,"3, - 4" -5,"a,"" -b",7 -''', [['a', 'b', 'c'], ['1', '2', '3,\n 4'], ['5', 'a,"\nb', '7']]) - -ret = csv.DictReader("""a,b,c -1,2,3 -"4",5,6 -""".splitlines()) - -assert list(ret)==[ - {'a': '1', 'b': '2', 'c': '3'}, - {'a': '4', 'b': '5', 'c': '6'}, -]