Exemple #1
0
    def init(self, *args, **kwargs):
        super(Processor, self).init(*args, **kwargs)

        # command -> plugin
        self.command = cidict()

        # plugin name -> commands
        self.commands = cidict()

        # plugin name -> plugin
        self.plugins = cidict()
Exemple #2
0
    def init(self, *args, **kwargs):
        super(Processor, self).init(*args, **kwargs)

        # command -> plugin
        self.command = cidict()

        # plugin name -> commands
        self.commands = cidict()

        # plugin name -> plugin
        self.plugins = cidict()
Exemple #3
0
    def init(self, init_args=None, init_kwargs=None):
        self.init_args = init_args or tuple()
        self.init_kwargs = init_kwargs or dict()

        self.logger = getLogger(__name__)

        self.plugins = cidict()
Exemple #4
0
    def init(self, init_args=None, init_kwargs=None):
        self.init_args = init_args or tuple()
        self.init_kwargs = init_kwargs or dict()

        self.logger = getLogger(__name__)

        self.plugins = cidict()
Exemple #5
0
 def test_case_insensitive_membership(self):
     d = cidict.cidict(foo=1, bar=2)
     self.assertEqual(2, len(d))
     assert 'foo' in d
     assert 'FOO' in d
     assert 'bar' in d
     assert 'BAR' in d
Exemple #6
0
 def test_case_insensitive_access(self):
     d = cidict.cidict(foo=1, bar=2)
     self.assertEqual(2, len(d))
     self.assertEqual(1, d['foo'])
     self.assertEqual(1, d['FOO'])
     self.assertEqual(2, d['bar'])
     self.assertEqual(2, d['BAR'])
Exemple #7
0
 def _build_initial_headers(self):
     # We do not set multiple headers ourselves and therefore
     # can use a dictionary for headers
     headers = cidict.cidict()
     
     if self.config.user_agent is not None:
         headers['user-agent'] = self.config.user_agent
     
     return headers
Exemple #8
0
    def init(self, data, config):
        self.data = data
        self.config = config

        self.terminate = False

        self.host = self.config["host"]
        self.port = self.config["port"]

        self.auth = {
            "host": gethostname(),
            "server": self.host,
            "nick": self.config["nick"],
            "ident": kdb.__name__,
            "name": self.config.get("settings", {}).get("name", kdb.__description__),
        }

        if "password" in self.config:
            self.auth["password"] = self.config["password"]

        # command -> plugin
        self.command = cidict()

        # plugin name -> commands
        self.commands = cidict()

        # plugin name -> plugin
        self.plugins = cidict()

        self.data.init(
            {
                "state": {
                    "host": self.auth["host"],
                    "server": self.auth["server"],
                    "nick": self.auth["nick"],
                    "ident": self.auth["ident"],
                    "name": self.auth["name"],
                }
            }
        )

        self.transport = TCPClient(channel=self.channel).register(self)
        self.protocol = IRC(channel=self.channel).register(self)
Exemple #9
0
 def test_missing_keys(self):
     d = cidict.cidict(foo=1)
     assert 'foo' in d
     assert 'bar' not in d
     
     self.assertEqual(1, d['foo'])
     try:
         d['bar']
     except KeyError:
         pass
     else:
         self.fail('Expected KeyError to be raised')
Exemple #10
0
 def headers(self):
     '''Returns response headers as a case-insensitive dictionary.
     
     If multiple headers with the same name are present in the response,
     the last header overwrites preceding ones. Use raw_headers to
     retrieve headers as a list with duplicate headers preserved.
     '''
     
     raw_headers = self.raw_headers
     map = cidict.cidict()
     for key, value in raw_headers:
         map[key] = value
     return map
Exemple #11
0
    def init(self, *args, **kwargs):
        super(Greeting, self).init(*args, **kwargs)

        seed(time())

        self.data.init(
            {
                "greeting": {
                    "history": cidict(),
                    "greetings": DEFAULTS,
                }
            }
        )

        Commands().register(self)
Exemple #12
0
    def init(self, init_args=None, init_kwargs=None):
        self.init_args = init_args or tuple()
        self.init_kwargs = init_kwargs or dict()

        self.plugins = cidict()
Exemple #13
0
 def test_init_kwargs_conflict(self):
     d = cidict.cidict(foo=1, bar=2, BAR=3)
     self.assertEqual(2, len(d))
     self.assertEqual(1, d['foo'])
     assert d.has_key('bar')
     assert d['bar'] in [2, 3]
Exemple #14
0
 def test_empty(self):
     d = cidict.cidict()
     self.assertEqual(0, len(d))
Exemple #15
0
 def test_init_kwargs_ci_override(self):
     d = cidict.cidict(dict(foo=1, BAR=2), FOO=4, bar=5)
     self.assertEqual(2, len(d))
     self.assertEqual(4, d['foo'])
     self.assertEqual(5, d['bar'])
Exemple #16
0
 def test_init_maping_no_conflict(self):
     d = cidict.cidict(dict(foo=1, bar=2))
     self.assertEqual(2, len(d))
     self.assertEqual(1, d['foo'])
     self.assertEqual(2, d['bar'])
Exemple #17
0
 def _guess_media_info(self, results):
     return [(
         result,
         cidict(guess_media_info(result['title'])),
     ) for result in results]