def unicode_charseq_strip(a, chars=None): if isinstance(a, types.UnicodeCharSeq): if is_nonelike(chars): def impl(a, chars=None): return str(a).strip() return impl elif isinstance(chars, types.UnicodeCharSeq): def impl(a, chars=None): return str(a).strip(str(chars)) return impl elif isinstance(chars, types.UnicodeType): def impl(a, chars=None): return str(a).strip(chars) return impl if isinstance(a, (types.CharSeq, types.Bytes)): if is_nonelike(chars): def impl(a, chars=None): return a._to_str().strip()._to_bytes() return impl elif isinstance(chars, (types.CharSeq, types.Bytes)): def impl(a, chars=None): return a._to_str().strip(chars._to_str())._to_bytes() return impl
def ol_list_sort(lst, key=None, reverse=False): _sort_check_key(key) _sort_check_reverse(reverse) if cgutils.is_nonelike(key): KEY = False sort_f = sort_forwards sort_b = sort_backwards elif isinstance(key, types.Dispatcher): KEY = True sort_f = arg_sort_forwards sort_b = arg_sort_backwards def impl(lst, key=None, reverse=False): if KEY is True: _lst = [key(x) for x in lst] else: _lst = lst if reverse is False or reverse == 0: tmp = sort_f(_lst) else: tmp = sort_b(_lst) if KEY is True: lst[:] = [lst[i] for i in tmp] return impl
def unicode_charseq_split(a, sep=None, maxsplit=-1): if not (maxsplit == -1 or isinstance( maxsplit, (types.Omitted, types.Integer, types.IntegerLiteral))): return None if isinstance(a, types.UnicodeCharSeq): if isinstance(sep, types.UnicodeCharSeq): def impl(a, sep=None, maxsplit=-1): return str(a).split(sep=str(sep), maxsplit=maxsplit) return impl if isinstance(sep, types.UnicodeType): def impl(a, sep=None, maxsplit=-1): return str(a).split(sep=sep, maxsplit=maxsplit) return impl if is_nonelike(sep): if is_default(maxsplit, -1): def impl(a, sep=None, maxsplit=-1): return str(a).split() else: def impl(a, sep=None, maxsplit=-1): return str(a).split(maxsplit=maxsplit) return impl if isinstance(a, (types.CharSeq, types.Bytes)): if isinstance(sep, (types.CharSeq, types.Bytes)): def impl(a, sep=None, maxsplit=-1): return _map_bytes(a._to_str().split(sep._to_str(), maxsplit=maxsplit)) return impl if is_nonelike(sep): if is_default(maxsplit, -1): def impl(a, sep=None, maxsplit=-1): return _map_bytes(a._to_str().split()) else: def impl(a, sep=None, maxsplit=-1): return _map_bytes(a._to_str().split(maxsplit=maxsplit)) return impl
def _sort_check_key(key): if isinstance(key, types.Optional): msg = ("Key must concretely be None or a Numba JIT compiled function, " "an Optional (union of None and a value) was found") raise errors.TypingError(msg) if not (cgutils.is_nonelike(key) or isinstance(key, types.Dispatcher)): msg = "Key must be None or a Numba JIT compiled function" raise errors.TypingError(msg)
def ol_list_sort(lst, key=None, reverse=False): # The following is mostly borrowed from listobj.ol_list_sort from numba.typed import List listobj._sort_check_key(key) listobj._sort_check_reverse(reverse) if cgutils.is_nonelike(key): KEY = False sort_f = listobj.sort_forwards sort_b = listobj.sort_backwards elif isinstance(key, types.Dispatcher): KEY = True sort_f = listobj.arg_sort_forwards sort_b = listobj.arg_sort_backwards def impl(lst, key=None, reverse=False): if KEY is True: # There's an unknown refct problem in reflected list. # Using an explicit loop with typedlist somehow "fixed" it. _lst = List() for x in lst: _lst.append(key(x)) else: _lst = lst if reverse is False or reverse == 0: tmp = sort_f(_lst) else: tmp = sort_b(_lst) if KEY is True: # There's an unknown refct problem in reflected list. # Using an explicit loop with typedlist somehow "fixed" it. ordered = List() for i in tmp: ordered.append(lst[i]) lst[:] = ordered return impl