mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
Separate KeyedDefaultdict into new structures module (#199)
This commit is contained in:
parent
2c60aa6395
commit
7f46e1c35c
@ -19,6 +19,7 @@ from copy import deepcopy
|
|||||||
from log import *
|
from log import *
|
||||||
import world
|
import world
|
||||||
import utils
|
import utils
|
||||||
|
import structures
|
||||||
|
|
||||||
### Exceptions
|
### Exceptions
|
||||||
|
|
||||||
@ -113,7 +114,7 @@ class Irc():
|
|||||||
internal=True, desc=self.serverdata.get('serverdesc')
|
internal=True, desc=self.serverdata.get('serverdesc')
|
||||||
or self.botdata['serverdesc'])}
|
or self.botdata['serverdesc'])}
|
||||||
self.users = {}
|
self.users = {}
|
||||||
self.channels = utils.KeyedDefaultdict(IrcChannel)
|
self.channels = structures.KeyedDefaultdict(IrcChannel)
|
||||||
|
|
||||||
# This sets the list of supported channel and user modes: the default
|
# This sets the list of supported channel and user modes: the default
|
||||||
# RFC1459 modes are implied. Named modes are used here to make
|
# RFC1459 modes are implied. Named modes are used here to make
|
||||||
|
19
structures.py
Normal file
19
structures.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
"""
|
||||||
|
structures.py - PyLink data structures module.
|
||||||
|
|
||||||
|
This module contains custom data structures that may be useful in various situations.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import collections
|
||||||
|
|
||||||
|
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
|
14
utils.py
14
utils.py
@ -10,25 +10,11 @@ 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…
Reference in New Issue
Block a user