PK!4 Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. DO WHAT THE FUCK YOU WANT TO BUT IT'S NOT MY FAULT PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. You just DO WHAT THE FUCK YOU WANT TO. 1. Do not hold the author(s), creator(s), developer(s) or distributor(s) liable for anything that happens or goes wrong with your use of the work. PK!\}XX#pretty_simple_namespace/__init__.pyfrom .index import format, pprint, wrapWith __all__ = ["format", "pprint", "wrapWith"] PK!WU#pretty_simple_namespace/bfFormat.py# # README # - Per this SO post: https://stackoverflow.com/a/33704700/984407 # ...a breadth first (bf) traversal is more easily implemented iteratively # as opposed to recursively. I can attest to this because trying to turn my # initial recursive depth first traversal into breadth first was painful. # # What makes this especially complex is the need to traverse breadth first # while also needing to ensure strings are inserted in the correct order. # That is the reason for the LinkedList, queues and callbacks. # # ------- # # Imports # # ------- # from all_purpose_dict import ApDict from another_linked_list import LinkedList from all_purpose_set import ApSet from types import SimpleNamespace as o from .queue import Queue import os from .fns import ( assignAll, discard, getListOfCollectionKeys, iif, isEmpty, isLaden, joinWith, map_, mOrder, passThrough, ) # ---- # # Init # # ---- # placeholder = object() primitiveTypes = ApSet([int, float, bool, str, type(None)]) # ---- # # Main # # ---- # def bfFormat(something, style): def bfFormat_inner(ctx, something, key=None): ctx.result.append(placeholder) leadingStr = makeLeadingStr(ctx, key) if ctx.refs.has(something): pathToRef = ctx.refs.get(something) insertSimpleResultWhenDone(ctx, leadingStr + f"") return ctx if ctx.inArray: ctx.refPath[-1] = (True, key) elif ctx.hasKeys: ctx.refPath[-1] = (False, key) if not isPrimitive(something): ctx.refs.set(something, buildPathToRef(ctx.refPath)) if isinstance(something, list): if isEmpty(something): insertSimpleResultWhenDone(ctx, leadingStr + "[]") return ctx formatQueue.add(makeFormatList(ctx, something, leadingStr)) elif isinstance(something, o) or isinstance(something, dict): if isEmpty(something): insertSimpleResultWhenDone(ctx, leadingStr + "{}") return ctx formatQueue.add(makeFormatDict(ctx, something, leadingStr)) elif callable(something): line = f"{leadingStr}{something.__name__}()" insertSimpleResultWhenDone(ctx, line) elif isinstance(something, str): insertSimpleResultWhenDone(ctx, f"{leadingStr}'{something}'") elif isinstance(something, bool): lowerBool = str(something).lower() insertSimpleResultWhenDone(ctx, leadingStr + lowerBool) elif something is None: lowerBool = str(something).lower() insertSimpleResultWhenDone(ctx, leadingStr + "none") else: insertSimpleResultWhenDone(ctx, leadingStr + str(something)) return ctx def makeFormatRoot(ctx, something): def formatRoot(): return bfFormat_inner(ctx, something) return formatRoot # # Yes 'Dict' includes SimpleNamespace here, I just couldn't think of a # succinct term that encompassed both. And since SimpleNamespace is # pretty much a dict, this makes sense enough for me. # def makeFormatDict(ctx, aDict, leadingStr): nodeToInsertAt = ctx.result.lastNode dictCtx = createCtx(ctx, hasKeys=True) def formatDict(): nonlocal dictCtx dictCtx = reduce(bfFormat_inner, dictCtx)(aDict) insertResult = makeInsertCollectionResult( ctx, dictCtx, nodeToInsertAt, leadingStr, isList=False ) addToWhenDone(insertResult, ctx) return formatDict def makeFormatList(ctx, aList, leadingStr): nodeToInsertAt = ctx.result.lastNode listCtx = createCtx(ctx, inArray=True) def formatList(): nonlocal listCtx listCtx = reduce(bfFormat_inner, listCtx)(aList) insertResult = makeInsertCollectionResult( ctx, listCtx, nodeToInsertAt, leadingStr, isList=True ) addToWhenDone(insertResult, ctx) return formatList def createCtx(currentCtx, **kwargs): props = o(**kwargs) newCtx = assignAll.simpleNamespaces( [makeDefaultCtxProps(), props, style] ) if currentCtx: newCtx.refs = currentCtx.refs newCtx.indentLevel = currentCtx.indentLevel + 1 # # refPath holds an array of tuple pairs # (IsArrayIndex, key) # newCtx.refPath = currentCtx.refPath + [None] newCtx.refs = currentCtx.refs newCtx.indentStr = getIndentStr(newCtx) return newCtx def insertSimpleResultWhenDone(ctx, line): nodeToInsertAt = ctx.result.lastNode def insertSimpleResult(): ctx.result.insertAfter(nodeToInsertAt, line) addToWhenDone(insertSimpleResult, ctx) # # isList will have to change if more collections are added which have # different opening and closing notation # def makeInsertCollectionResult( ctx, nestedCtx, nodeToInsertAt, leadingStr, *, isList ): def insertCollectionResult(): open_ = iif(isList, "[", "{") close = iif(isList, "]", "}") nestedCtx.result.prepend(leadingStr + open_) nestedCtx.result.append(ctx.indentStr + close) ctx.result.insertAllAfter(nodeToInsertAt, nestedCtx.result) return insertCollectionResult def addToWhenDone(insertResult, ctx): key = ctx.indentLevel if key not in whenDoneDict: whenDoneDict[key] = Queue() whenDoneDict[key].add(insertResult) rootCtx = createCtx(None, refPath=[], refs=ApDict()) formatRoot = makeFormatRoot(rootCtx, something) formatQueue = Queue([formatRoot]) whenDoneDict = {} while isLaden(formatQueue): formatFn = formatQueue.pop() formatFn() whenDoneList = toOrderedListByKey(whenDoneDict) for whenDoneFnQueue in whenDoneList: while isLaden(whenDoneFnQueue): whenDoneFn = whenDoneFnQueue.pop() whenDoneFn() return passThrough( rootCtx.result.append(""), [list, discard(placeholder), joinWith(os.linesep)], ) # ------- # # Helpers # # ------- # def makeDefaultCtxProps(): return o(inArray=False, indentLevel=0, hasKeys=False, result=LinkedList()) def toOrderedListByKey(aDict): return passThrough( aDict, [getListOfCollectionKeys, mOrder("desc"), map_(toValueFrom(aDict))], ) def toValueFrom(aDict): def keyToValue_inner(aKey): return aDict[aKey] return keyToValue_inner def makeLeadingStr(ctx, key): keyStr = iif(ctx.hasKeys, str(key) + ": ", "") return ctx.indentStr + keyStr def getIndentStr(ctx): return " " * ctx.indent * ctx.indentLevel def buildPathToRef(refPath): result = ["root"] for isArrayIndex, key in refPath: if isArrayIndex: result.append(f"[{key}]") else: result.append(f".{key}") return "".join(result) def reduce(fn, initial): def reduceInner(something): result = initial if isinstance(something, dict): for key, value in something.items(): result = fn(result, value, key) elif isinstance(something, o): for key, value in something.__dict__.items(): result = fn(result, value, key) elif isinstance(something, list): for idx, value in enumerate(something): result = fn(result, value, idx) else: result = fn(result, something) return result return reduceInner def isPrimitive(something): return type(something) in primitiveTypes PK!i|UU'pretty_simple_namespace/fns/__init__.pyfrom .assignAll import assignAll from .discard import discard from .forEach import forEach from .getListOfCollectionKeys import getListOfCollectionKeys from .iif import iif from .invokeAttr import invokeAttr from .isEmpty import isEmpty from .isLaden import isLaden from .joinWith import joinWith from .mOrder import mOrder from .map_ import map_ from .passThrough import passThrough __all__ = [ "assignAll", "discard", "forEach", "getListOfCollectionKeys", "iif", "invokeAttr", "isEmpty", "isLaden", "joinWith", "mOrder", "map_", "passThrough", ] PK!C*(pretty_simple_namespace/fns/assignAll.py# # README # - Similar to javascript's Object.assign, this assigns properties right to # left, meaning objects to the right take precedence to those on the left # # ------- # # Imports # # ------- # from types import SimpleNamespace from .decorators.argIsListOfType import argIsListOfType from .internal.NotCallable import NotCallable # ---- # # Main # # ---- # @argIsListOfType(SimpleNamespace) def assignAll_simpleNamespace(aList): result = SimpleNamespace() for obj in aList: for key, val in obj.__dict__.items(): setattr(result, key, val) return result assignAll = NotCallable("assignAll", simpleNamespaces=assignAll_simpleNamespace) PK!2pretty_simple_namespace/fns/decorators/__init__.pyPK![`)gEE7pretty_simple_namespace/fns/decorators/argIsCallable.pyfrom inspect import signature import wrapt @wrapt.decorator def argIsCallable(fn, _instance, args, kwargs): if not callable(args[0]): argName = list(signature(fn).parameters)[0] fnName = fn.__name__ raise ValueError(f"{fnName} requires {argName} to be callable") return fn(*args, **kwargs) PK!waII4pretty_simple_namespace/fns/decorators/argIsClass.pyfrom inspect import isclass, signature import wrapt @wrapt.decorator def argIsClass(fn, _instance, args, kwargs): if not isclass(args[0]): argName = list(signature(fn).parameters)[0] fnName = fn.__name__ raise ValueError(f"{fnName} requires {argName} to be a class") return fn(*args, **kwargs) PK!WḲ7pretty_simple_namespace/fns/decorators/argIsInstance.pyfrom inspect import signature from ..internal.raise_ import raise_ import wrapt def argIsInstance(aType, fnName=None): @wrapt.decorator def wrapper(fn, _instance, args, kwargs): nonlocal fnName typePassed = type(args[0]) if not isinstance(typePassed, aType): argName = list(signature(fn).parameters)[0] fnName = fnName or fn.__name__ typeName = aType.__name__ raise_( ValueError, f""" {fnName} requires {argName} to be an instance of {typeName} type passed: {typePassed.__name__} """, ) return fn(*args, **kwargs) return wrapper PK!9pretty_simple_namespace/fns/decorators/argIsListOfType.pyfrom ordered_set import OrderedSet import wrapt from ..internal.discardWhen import discardWhen from ..internal.get import get from ..internal.getArgName import getArgName from ..internal.isLaden import isLaden from ..internal.isType import isType from ..internal.joinWith import joinWith from ..internal.map_ import map_ from ..internal.passThrough import passThrough from ..internal.raise_ import raise_ from ..internal.sort import sort from ..internal.toType import toType def argIsListOfType(aType): @wrapt.decorator def wrapper(fn, _instance, args, kwargs): typePassed = type(args[0]) fnName = fn.__name__ typeName = aType.__name__ if typePassed is not list: argName = getArgName(fn) raise_( ValueError, f"""\ {fnName} requires {argName} to have the type list type passed: {typePassed.__name__} """, ) invalidTypes = discardWhen(isType(aType))(args[0]) if isLaden(invalidTypes): argName = getArgName(fn) invalidTypeNames = passThrough( invalidTypes, [ map_(toType), OrderedSet, list, map_(get("__name__")), sort, joinWith(", "), ], ) raise_( ValueError, f"""\ {fnName} requires {argName} to be a list of {typeName} invalid types passed: {invalidTypeNames} """, ) return fn(*args, **kwargs) return wrapper PK!E3pretty_simple_namespace/fns/decorators/argIsType.pyfrom inspect import signature from ..internal.raise_ import raise_ import wrapt def argIsType(aType): @wrapt.decorator def wrapper(fn, _instance, args, kwargs): typePassed = type(args[0]) if typePassed is not aType: argName = list(signature(fn).parameters)[0] fnName = fn.__name__ typeName = aType.__name__ raise_( ValueError, f""" {fnName} requires {argName} to have the type {typeName} type passed: {typePassed.__name__} """, ) return fn(*args, **kwargs) return wrapper PK!DD&pretty_simple_namespace/fns/discard.py# ------- # # Imports # # ------- # from .internal.getTypedResult import getTypedResult # ---- # # Main # # ---- # def discard(el): def discard_inner(collection): typedDiscard = getTypedResult( collection, typeToDiscard, discard.__name__ ) return typedDiscard(el, collection) return discard_inner # ------- # # Helpers # # ------- # def discard_list(elToDiscard, aList): result = [] for el in aList: if el != elToDiscard: result.append(el) return result typeToDiscard = {list: discard_list} PK!`c??&pretty_simple_namespace/fns/forEach.py# ------- # # Imports # # ------- # from types import SimpleNamespace from .internal.makeGenericCallFn import makeGenericCallFn from .internal.getTypedResult import getTypedResult from .decorators.argIsCallable import argIsCallable # ---- # # Main # # ---- # @argIsCallable def forEach(fn): fnName = forEach.__name__ callFn = makeGenericCallFn(fn, 3, fnName) def forEach_inner(collection): typedForEach = getTypedResult(collection, typeToForEach, fnName) return typedForEach(callFn, collection) return forEach_inner # ------- # # Helpers # # ------- # def forEach_dict(callFn, aDict): for key, val in aDict.items(): callFn(val, key, aDict) return aDict def forEach_list(callFn, aList): for idx, el in enumerate(aList): callFn(el, idx, aList) return aList def forEach_simpleNamespace(callFn, aSimpleNamespace): forEach_dict(callFn, aSimpleNamespace.__dict__) return aSimpleNamespace typeToForEach = { dict: forEach_dict, list: forEach_list, SimpleNamespace: forEach_simpleNamespace, } PK!$6pretty_simple_namespace/fns/getListOfCollectionKeys.py# ------- # # Imports # # ------- # from types import SimpleNamespace from .internal.getTypedResult import getTypedResult # ---- # # Main # # ---- # def getListOfCollectionKeys(collection): fnName = getListOfCollectionKeys.__name__ typedKeys = getTypedResult(collection, typeToKeys, fnName) return typedKeys(collection) # ------- # # Helpers # # ------- # def getListOfCollectionKeys_dict(aDict): return list(aDict.keys()) def getListOfCollectionKeys_simpleNamespace(aSimpleNamespace): return list(aSimpleNamespace.__dict__.keys()) typeToKeys = { dict: getListOfCollectionKeys_dict, SimpleNamespace: getListOfCollectionKeys_simpleNamespace, } PK!R++"pretty_simple_namespace/fns/iif.pyfrom .internal.iif import iif # noqa f401 PK!B u3pretty_simple_namespace/fns/internal/NotCallable.pyfrom types import SimpleNamespace from .mAssignToSelf import mAssignToSelf from .raise_ import raise_ import os class NotCallable(SimpleNamespace): def __init__(self, fnName, **typeToFn): self._fnName = fnName self._typeToFn = typeToFn mAssignToSelf(typeToFn, self) def __call__(self, *args, **kwargs): availableKeys = list(self._typeToFn.keys()) fnName = self._fnName raise_( TypeError, f""" The utility '{fnName}' is not callable because it needs to know what to return in the case of an empty list. example usage: {fnName}.{availableKeys[0]}([...]) available keys: {os.linesep.join(availableKeys)} """, ) PK!0pretty_simple_namespace/fns/internal/__init__.pyPK!F3pretty_simple_namespace/fns/internal/discardWhen.py# ------- # # Imports # # ------- # from .getTypedResult import getTypedResult from .makeGenericCallFn import makeGenericCallFn from ..decorators.argIsCallable import argIsCallable # ---- # # Main # # ---- # @argIsCallable def discardWhen(predicate): fnName = discardWhen.__name__ shouldDiscard = makeGenericCallFn(predicate, 3, fnName) def discardWhen_inner(collection): typedDiscardWhen = getTypedResult(collection, typeToDiscardWhen, fnName) return typedDiscardWhen(shouldDiscard, collection) return discardWhen_inner # ------- # # Helpers # # ------- # def discardWhen_list(shouldDiscard, aList): result = [] for idx, el in enumerate(aList): if not shouldDiscard(el, idx, aList): result.append(el) return result def discardWhen_dict(shouldDiscard, aDict): result = {} for key, val in aDict.items(): if shouldDiscard(val, key, aDict): result[key] = val return result typeToDiscardWhen = {list: discardWhen_list, dict: discardWhen_dict} PK!ss+pretty_simple_namespace/fns/internal/get.pydef get(attrName): def get_inner(something): return getattr(something, attrName) return get_inner PK!)jj2pretty_simple_namespace/fns/internal/getArgName.pyfrom inspect import signature def getArgName(fn, idx=0): return list(signature(fn).parameters)[idx] PK!X6pretty_simple_namespace/fns/internal/getFnSignature.pyfrom inspect import signature from .raise_ import raise_ def getFnSignature(fn, callerName): try: return signature(fn) except Exception as e: raise_( ValueError, f"""\ '{callerName}' is unable to get the signature of the passed callable callable passed: {fn.__name__} one reason this could occur is the callable is written in c (e.g. the builtin 'str' callable). """, fromException=e, ) PK!k>pretty_simple_namespace/fns/internal/getNumPositionalParams.py# ------- # # Imports # # ------- # from inspect import Parameter from math import inf from .getFnSignature import getFnSignature from .iif import iif # ---- # # Init # # ---- # _nonVarPositionalParamKinds = { Parameter.POSITIONAL_ONLY, Parameter.POSITIONAL_OR_KEYWORD, } # ---- # # Main # # ---- # # # Returns a tuple # numRequired: number of required positional params # numAllowed: number of allowed positional params # def getNumPositionalParams(fn, callerName): sig = getFnSignature(fn, callerName) numAllowed = iif(_hasVarPositionalParam(sig), inf, 0) numRequired = 0 for p in sig.parameters.values(): if p.kind in _nonVarPositionalParamKinds: numAllowed += 1 if p.default is Parameter.empty: numRequired += 1 return (numRequired, numAllowed) # ------- # # Helpers # # ------- # def _hasVarPositionalParam(sig): for p in sig.parameters.values(): if p.kind is Parameter.VAR_POSITIONAL: return True PK!w<6pretty_simple_namespace/fns/internal/getTypedResult.py# # README # - I'm not sure what to call this. Its purpose is to centralize the type # validation, minimizing copy/paste. # # ------- # # Imports # # ------- # from .raise_ import raise_ from .get import get # ---- # # Init # # ---- # getName = get("__name__") # # we need a unique object here to ensure the 'typeToSomething' doesn't lead us # to a 'None' value # nothing = object() # ---- # # Main # # ---- # def getTypedResult(value, typeToSomething, fnName): valueType = type(value) result = typeToSomething.get(valueType, nothing) if _isSomething(result): return result supportedTypes = ", ".join(map(getName, typeToSomething.keys())) raise_( ValueError, f"""\ {fnName} doesn't support the type '{valueType.__name__}' supported types: {supportedTypes} """, ) # ------- # # Helpers # # ------- # def _isSomething(x): return x is not nothing PK!;||+pretty_simple_namespace/fns/internal/iif.pydef iif(condition, whenTruthy, whenFalsey): if condition: return whenTruthy else: return whenFalsey PK!ws{33/pretty_simple_namespace/fns/internal/isLaden.pydef isLaden(aList): return len(aList) is not 0 PK!Ȋ8pretty_simple_namespace/fns/internal/isOnlyWhitespace.pyimport re onlyWhitespaceRe = re.compile(r"\s*$") def isOnlyWhitespace(aString): return onlyWhitespaceRe.match(aString) is not None PK!f.pretty_simple_namespace/fns/internal/isType.pyfrom inspect import isclass def isType(aType): if not isclass(aType): raise ValueError("isType requires argument 'aType' to pass isclass") def isType_inner(something): return type(something) is aType return isType_inner PK!v_R*++0pretty_simple_namespace/fns/internal/joinWith.py# ------- # # Imports # # ------- # from ordered_set import OrderedSet from .getTypedResult import getTypedResult # ---- # # Main # # ---- # def joinWith(separator): def joinWith_inner(collection): typedJoinWith = getTypedResult(collection, typeToJoinWith, "joinWith") return typedJoinWith(separator, collection) return joinWith_inner # ------- # # Helpers # # ------- # def joinWith_iterable(separator, aList): return separator.join(aList) typeToJoinWith = {list: joinWith_iterable, OrderedSet: joinWith_iterable} PK!K5pretty_simple_namespace/fns/internal/mAssignToSelf.py# # assigns dict key-values onto self as attributes # return secondaryObj # ** mutates secondaryObj # def mAssignToSelf(aDict, aSelf): for k, v in aDict.items(): setattr(aSelf, k, v) return aSelf PK!K2pretty_simple_namespace/fns/internal/makeCallFn.py# ------- # # Imports # # ------- # from math import inf from .returnFirstArgument import returnFirstArgument as identity from .getNumPositionalParams import getNumPositionalParams # ---- # # Main # # ---- # def makeCallFn(fn, callerName, *, modifyResult=identity): (_, allowed) = getNumPositionalParams(fn, callerName) if allowed is inf: return lambda *args, **kwargs: modifyResult(fn(*args, **kwargs)) else: return lambda *args, **kwargs: modifyResult( fn(*args[:allowed], **kwargs) ) PK!T-9pretty_simple_namespace/fns/internal/makeGenericCallFn.py# ------- # # Imports # # ------- # from math import inf from .getNumPositionalParams import getNumPositionalParams from .raise_ import raise_ # ---- # # Main # # ---- # def makeGenericCallFn(fn, maxParams, callerName): required, allowed = getNumPositionalParams(fn, callerName) if allowed is inf: allowed = maxParams if required > maxParams: raise_( ValueError, f""" {callerName} can only take functions with up to {maxParams} positional params. The function '{fn.__name__}' requires {required} """, ) return lambda *args, **kwargs: fn(*args[:allowed], **kwargs) PK!G~,pretty_simple_namespace/fns/internal/map_.py# ------- # # Imports # # ------- # from .makeGenericCallFn import makeGenericCallFn from .getTypedResult import getTypedResult from ..decorators.argIsCallable import argIsCallable # ---- # # Main # # ---- # @argIsCallable def map_(mapperFn): fnName = map_.__name__ callMapperFn = makeGenericCallFn(mapperFn, 3, fnName) def map_inner(collection): typedMap = getTypedResult(collection, typeToMap, fnName) return typedMap(callMapperFn, collection) return map_inner # ------- # # Helpers # # ------- # def map_list(callMapperFn, aList): result = [] for idx, el in enumerate(aList): result.append(callMapperFn(el, idx, aList)) return result typeToMap = {list: map_list} PK!yy3pretty_simple_namespace/fns/internal/passThrough.pyfrom .reduce import reduce def passThrough(arg, fnList): return reduce(lambda result, fn: fn(result), arg)(fnList) PK!W.pretty_simple_namespace/fns/internal/raise_.pyfrom tedent import tedent from .isOnlyWhitespace import isOnlyWhitespace import os def raise_(errorClass, message, *, fromException=None): allLines = message.split(os.linesep) if isOnlyWhitespace(allLines[0]) and isOnlyWhitespace(allLines[-1]): message = tedent(message) err = errorClass(message) if fromException is None: raise err else: raise err from fromException PK!Et.pretty_simple_namespace/fns/internal/reduce.py# ------- # # Imports # # ------- # from .makeGenericCallFn import makeGenericCallFn from .getTypedResult import getTypedResult from ..decorators.argIsCallable import argIsCallable # ---- # # Main # # ---- # @argIsCallable def reduce(fn, initial): reducerFn = makeGenericCallFn(fn, 4, "reduce") def reduce_inner(collection): typedReduce = getTypedResult(collection, typeToReduce, "reduce") return typedReduce(reducerFn, initial, collection) return reduce_inner # ------- # # Helpers # # ------- # def reduce_list(reducerFn, initial, aList): result = initial for idx, el in enumerate(aList): result = reducerFn(result, el, idx, aList) return result typeToReduce = {list: reduce_list} PK!pjj;pretty_simple_namespace/fns/internal/returnFirstArgument.pyfrom .iif import iif def returnFirstArgument(*args, **kwargs): return iif(len(args), args[0], None) PK!\xx7pretty_simple_namespace/fns/internal/sanitizeAscDesc.pyfrom .raise_ import raise_ ascDescSet = {"asc", "desc"} def sanitizeAscDesc(ascOrDesc): sanitized = ascOrDesc.lower() if sanitized not in ascDescSet: raise_( ValueError, f""" ascOrDesc must be either 'asc' or 'desc' (case insensitive) value given: {ascOrDesc} """, ) return sanitized PK!0oo,pretty_simple_namespace/fns/internal/sort.py# ------- # # Imports # # ------- # from .getTypedResult import getTypedResult # ---- # # Main # # ---- # def sort(collection): typedSort = getTypedResult(collection, typeToSort, "sort") return typedSort(collection) # ------- # # Helpers # # ------- # def sort_viaSorted(something): return sorted(something) typeToSort = {list: sort_viaSorted} PK!V;22.pretty_simple_namespace/fns/internal/toType.pydef toType(something): return type(something) PK!%tt)pretty_simple_namespace/fns/invokeAttr.pydef invokeAttr(key): def invokeAttr_inner(obj): return getattr(obj, key)() return invokeAttr_inner PK!¢[&pretty_simple_namespace/fns/isEmpty.pyfrom types import SimpleNamespace # TODO: make 'isEmpty' generic like the other utils def isEmpty(lenAble): if isinstance(lenAble, SimpleNamespace): return len(lenAble.__dict__) is 0 else: return len(lenAble) is 0 PK!X33&pretty_simple_namespace/fns/isLaden.pyfrom .internal.isLaden import isLaden # noqa f401 PK!955'pretty_simple_namespace/fns/joinWith.pyfrom .internal.joinWith import joinWith # noqa f401 PK!ʝx%pretty_simple_namespace/fns/mOrder.py# ------- # # Imports # # ------- # from .internal.getTypedResult import getTypedResult from .internal.sanitizeAscDesc import sanitizeAscDesc # ---- # # Main # # ---- # def mOrder(ascOrDesc): ascOrDesc = sanitizeAscDesc(ascOrDesc) def mOrder_inner(collection): fnName = mOrder.__name__ typedMOrder = getTypedResult(collection, typeToMOrder, fnName) return typedMOrder(collection, ascOrDesc) return mOrder_inner # ------- # # Helpers # # ------- # def mOrder_viaSort(something, ascOrDesc): something.sort(reverse=(ascOrDesc == "desc")) return something typeToMOrder = {list: mOrder_viaSort} PK!}--#pretty_simple_namespace/fns/map_.pyfrom .internal.map_ import map_ # noqa f401 PK!F;;*pretty_simple_namespace/fns/passThrough.pyfrom .internal.passThrough import passThrough # noqa f401 PK!MѺ pretty_simple_namespace/index.py# ------- # # Imports # # ------- # from types import SimpleNamespace as o from .bfFormat import bfFormat # ---- # # Init # # ---- # defaultIndent = 2 # ---- # # Main # # ---- # def pprint(something, *, indent=defaultIndent): print(format(something, indent=indent)) def format(something, *, indent=defaultIndent): return bfFormat(something, o(indent=indent)) def wrapWith(*, indent): wrappedIndent = indent def wrappedPprint(something, *, indent=wrappedIndent): pprint(something, indent=indent) def wrappedFormat(something, *, indent=wrappedIndent): return format(something, indent=indent) return o(pprint=wrappedPprint, format=wrappedFormat) PK!̱?(}} pretty_simple_namespace/queue.py# # README # - This class exists because I don't like deque's api # # ------- # # Imports # # ------- # from collections import deque # ---- # # Main # # ---- # class Queue: def __init__(self, aList=[]): validateInput(aList) self._data = deque(aList) def __len__(self): return len(self._data) def add(self, element): self._data.append(element) return self def pop(self): return self._data.popleft() # ------- # # Helpers # # ------- # def validateInput(aList): if not isinstance(aList, list): raise TypeError("aList must be an instance of list") PK!HڽTU-pretty_simple_namespace-0.1.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!HU|AO 0pretty_simple_namespace-0.1.0.dist-info/METADATAWmo8_1;)P4Y4خS$ChH3{]EvW_3ϼ7D)H*ݎEvLE#:jX(d=Noac:'QЭ?=~vb s-yVHV]sԭN8a49]͘WV]FkkF&7^ikH™ij%v{3ڔ@8?N|t~[yʼ*D,\ݘn$p*z7s~!maTPuj]:[w('P~^IévURx.G%W;$(4[@Y~ݩK%a$' YZUXZQNbv0Iss)of邖,_ GH$٦^1컒MYxq==Ռfonz:n.ӛӍ5}xq>gb^K @J*ӧ TTa\Saw5Ӱ @ O/:-ЯSr>rUYxu YĄt;-)?(0u c.,N8dsPϐi,(o:4+1(>g"Zqnr 7t])`%!h%ּHa39KZ 'I:YĆr~{smuTu:\IYK+|[(cޘ7=Pڢjבq/ģ6_.nOtduR<}%lCX 0=c(dc:A\bXW?1x h:~rtwCVzd( dգj MsֈsI.- Ӣ5kh 8-!d&禓({wi}zX,ӂ/ DskV )p߸ңnerR֯L) wTe ͭjb%G6bL[`̖7~_b%#:7Ko!> r9 a q(F3pSͅ\VOC0S)reKRK*ooseHNAD(bG3=vW}6H w`?rE*x3F䌱PBrbgf+Ak쟷`3lrmp陌#`ET:>kt 'cO1I;~Ь*x=r{\9^r9` ޗjᯭ5/%ӣ{ Kfvs :pO!_ I$(A۰f7B=pb>KNf!f=s2~k4֛ /Gҭ4_cFڄPVO l샐9 [1tf5a?fVM /?-L߲r!޵PK!Hbc .pretty_simple_namespace-0.1.0.dist-info/RECORDWɶV[<,z, 1"f[emʮ5:ʼu~nFRnKJ ^I⚰+$ oqe4+:t}:p(N6jҡ0,b oh8f #/Lt%=,5J$a>Df2h jop ++twW0ȇY;Zs4`PNexA6 H`4kzҟGP-W/$c7 Rc@PsqK\~ʼn@C|1?EJfǻzj&:UCFCi:Q]G:ݖSU )RTV* +X;2D1կFnpK]3Uh=;E?K:D8+.ƨ=C[ry  Phj)Y 23ݭ>C4FheޣrUrPe<s&iT4cVӲ!F]Qhpr*[$!@HW$rP2.EbSC=HڼԼCA\m41ܕtT D~ R6.| ڹn:q ʹ;aWt1Pi<ݧ̬1si9ٹc]Mz0T%Dc? &tnQd۴ڔyB1"jp"#`4  ܾ_M0ĦL 8CEޑ XŅtK*{85{d[nb,*{^;pC\]J/JKC/'K [No-SvX @qND'Rs2 <۶\ ul.\ 3S$c}7sU 6ܺASCdF9ب=5rjGǣì"-950-Շwe%CL n3H5-mYofGɖ80ǣ"C1B, ʌrrbqa7y;)1#Kd ~NMp<{.]qWO4o}ƱNk2 Euһ%Xm(`S۪ӹ0k =Seߖ2V/i>*t[P6k'PAUd(z>ڙ!}34~0QD&JlY*-!!Cuu "kO%ޔ7SE?|WSp8Σzs'NGЩ+pc(WuVrC,C ?&>JL(w™CF쁼]:oKJ 섻]˙X-)^`.3$xN-@@@"{Q; W_ V"}-1ʣ_qՂ4*Ʊ4ţ]àUp.J|]!7& ,9V/:5HM7>6=>z젵RE["5pֈI<16lpa_?\>%l9H%H zѨ+ULLFBQ9A6' B9{ q0 'fN<OmץB;uEtgG0IYG Q[& 1=y,o#%8]4qAsv }'Ĉ%;fk3[J sUEV H}Ppc_K}'Aqik 5ߝQJ~֑~5m"ېbwv*_s! 0 |{#\5I|a'|pljXX"L]Az=]&yoI&ȑ!PK!4Npretty_simple_namespace/fns/internal/getNumPositionalParams.pyPK!w<6Spretty_simple_namespace/fns/internal/getTypedResult.pyPK!;||+Wpretty_simple_namespace/fns/internal/iif.pyPK!ws{33/Wpretty_simple_namespace/fns/internal/isLaden.pyPK!Ȋ8YXpretty_simple_namespace/fns/internal/isOnlyWhitespace.pyPK!f.9Ypretty_simple_namespace/fns/internal/isType.pyPK!v_R*++0Zpretty_simple_namespace/fns/internal/joinWith.pyPK!K5\pretty_simple_namespace/fns/internal/mAssignToSelf.pyPK!K2&^pretty_simple_namespace/fns/internal/makeCallFn.pyPK!T-9`pretty_simple_namespace/fns/internal/makeGenericCallFn.pyPK!G~,cpretty_simple_namespace/fns/internal/map_.pyPK!yy3fpretty_simple_namespace/fns/internal/passThrough.pyPK!W.|gpretty_simple_namespace/fns/internal/raise_.pyPK!Et.hipretty_simple_namespace/fns/internal/reduce.pyPK!pjj;lpretty_simple_namespace/fns/internal/returnFirstArgument.pyPK!\xx7`mpretty_simple_namespace/fns/internal/sanitizeAscDesc.pyPK!0oo,-opretty_simple_namespace/fns/internal/sort.pyPK!V;22.ppretty_simple_namespace/fns/internal/toType.pyPK!%tt)dqpretty_simple_namespace/fns/invokeAttr.pyPK!¢[&rpretty_simple_namespace/fns/isEmpty.pyPK!X33&Uspretty_simple_namespace/fns/isLaden.pyPK!955'spretty_simple_namespace/fns/joinWith.pyPK!ʝx%Ftpretty_simple_namespace/fns/mOrder.pyPK!}--#wpretty_simple_namespace/fns/map_.pyPK!F;;*~wpretty_simple_namespace/fns/passThrough.pyPK!MѺ xpretty_simple_namespace/index.pyPK!̱?(}} zpretty_simple_namespace/queue.pyPK!HڽTU-}pretty_simple_namespace-0.1.0.dist-info/WHEELPK!HU|AO 0S~pretty_simple_namespace-0.1.0.dist-info/METADATAPK!Hbc .pretty_simple_namespace-0.1.0.dist-info/RECORDPK33;V