mirror of
https://github.com/jlu5/PyLink.git
synced 2025-10-15 16:17:25 +02:00
utils: add KeyedDefaultdict
This is a subclass of defaultdict allowing the key to be passed to the default factory.
This commit is contained in:
parent
abce18a5ba
commit
544d6e1041
14
utils.py
14
utils.py
@ -10,11 +10,25 @@ import re
|
|||||||
import inspect
|
import inspect
|
||||||
import importlib
|
import importlib
|
||||||
import os
|
import os
|
||||||
|
import collections
|
||||||
|
|
||||||
from log import log
|
from log import log
|
||||||
import world
|
import world
|
||||||
import conf
|
import conf
|
||||||
|
|
||||||
|
class KeyedDefaultdict(collections.defaultdict):
|
||||||
|
"""
|
||||||
|
Subclass of defaultdict allowing the key to be passed to the default factory.
|
||||||
|
"""
|
||||||
|
def __missing__(self, key):
|
||||||
|
if self.default_factory is None:
|
||||||
|
# If there is no default factory, just let defaultdict handle it
|
||||||
|
super().__missing__(self, key)
|
||||||
|
else:
|
||||||
|
value = self[key] = self.default_factory(key)
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
class NotAuthenticatedError(Exception):
|
class NotAuthenticatedError(Exception):
|
||||||
"""
|
"""
|
||||||
Exception raised by checkAuthenticated() when a user fails authentication
|
Exception raised by checkAuthenticated() when a user fails authentication
|
||||||
|
Loading…
x
Reference in New Issue
Block a user