Mercurial > repos > fubar > jbrowse2
diff jb2_GFF/_utils.py @ 17:4c201a3d4755 draft
planemo upload for repository https://github.com/usegalaxy-eu/temporary-tools/tree/master/jbrowse2 commit a37bfdfc108501b11c7b2aa15efb1bd16f0c4b66
author | fubar |
---|---|
date | Sun, 28 Jan 2024 06:48:52 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jb2_GFF/_utils.py Sun Jan 28 06:48:52 2024 +0000 @@ -0,0 +1,49 @@ +class defaultdict(dict): + """Back compatible defaultdict: + http://code.activestate.com/recipes/523034/""" + + def __init__(self, default_factory=None, *a, **kw): + if default_factory is not None and not hasattr( + default_factory, "__call__" + ): + raise TypeError("first argument must be callable") + dict.__init__(self, *a, **kw) + self.default_factory = default_factory + + def __getitem__(self, key): + try: + return dict.__getitem__(self, key) + except KeyError: + return self.__missing__(key) + + def __missing__(self, key): + if self.default_factory is None: + raise KeyError(key) + self[key] = value = self.default_factory() + return value + + def __reduce__(self): + if self.default_factory is None: + args = tuple() + else: + args = (self.default_factory,) + return type(self), args, None, None, self.items() + + def copy(self): + return self.__copy__() + + def __copy__(self): + return type(self)(self.default_factory, self) + + def __deepcopy__(self, memo): + import copy + + return type(self)( + self.default_factory, copy.deepcopy(self.items()) + ) + + def __repr__(self): + return "defaultdict(%s, %s)" % ( + self.default_factory, + dict.__repr__(self), + )