# Path: uzbl/plugins/config.py
# class Config(PerInstancePlugin):
#     """Configuration plugin, has dictionary interface for config access
# 
#     This class is currenty not inherited from either UserDict or abc.Mapping
#     because not sure what version of python we want to support. It's not
#     hard to implement all needed methods either.
#     """
# 
#     CONFIG_SECTION = 'config'
# 
#     def __init__(self, uzbl):
#         super(Config, self).__init__(uzbl)
# 
#         self.data = {}
#         uzbl.connect('VARIABLE_SET', self.parse_set_event)
#         assert not 'a' in self.data
# 
#     def __getitem__(self, key):
#         return self.data[key]
# 
#     def __setitem__(self, key, value):
#         self.set(key, value)
# 
#     def __delitem__(self, key):
#         self.set(key)
# 
#     def get(self, key, default=None):
#         return self.data.get(key, default)
# 
#     def __contains__(self, key):
#         return key in self.data
# 
#     def keys(self):
#         return iter(self.data.keys())
# 
#     def items(self):
#         return iter(self.data.items())
# 
#     def update(self, other=None, **kwargs):
#         if other is None:
#             other = {}
# 
#         for (key, value) in list(dict(other).items()) + list(kwargs.items()):
#             self[key] = value
# 
# 
#     def set(self, key, value='', force=False):
#         '''Generates a `set <key> <value>` command string to send to the
#         current uzbl instance.
# 
#         Note that the config dict isn't updated by this function. The config
#         dict is only updated after a successful `VARIABLE_SET ..` event
#         returns from the uzbl instance.'''
# 
#         assert valid_key(key)
# 
#         if isinstance(value, bool):
#             value = int(value)
# 
#         else:
#             value = str(value)
#             assert '\n' not in value
# 
#         if not force and key in self and self[key] == value:
#             return
# 
#         self.uzbl.send('set %s %s' % (key, value))
# 
# 
#     def parse_set_event(self, args):
#         '''Parse `VARIABLE_SET <var> <type> <value>` event and load the
#         (key, value) pair into the `uzbl.config` dict.'''
# 
#         args = splitquoted(args)
#         if len(args) == 2:
#             key, type, raw_value = args[0], args[1], ''
#         elif len(args) == 3:
#             key, type, raw_value = args
#         else:
#             raise Exception('Invalid number of arguments')
# 
#         assert valid_key(key)
#         assert type in types
# 
#         new_value = types[type](raw_value)
#         old_value = self.data.get(key, None)
# 
#         # Update new value.
#         self.data[key] = new_value
# 
#         if old_value != new_value:
#             self.uzbl.event('CONFIG_CHANGED', key, new_value)
# 
#         # Cleanup null config values.
#         if type == 'str' and not new_value:
#             del self.data[key]
# 
#     def cleanup(self):
#         # not sure it's needed, but safer for cyclic links
#         self.data.clear()
#         super(Config, self).cleanup()


import sys
import unittest
from emtest import EventManagerMock
from six import next
from uzbl.plugins.history import History, SharedHistory
from uzbl.plugins.keycmd import Keylet, KeyCmd
from uzbl.plugins.on_set import OnSetPlugin
from uzbl.plugins.config import Config
        self.assertIs(a, b)

    def test_add_and_get(self):
        s = SharedHistory[self.uzbl]
        s.addline('foo', 'bar')
        s.addline('foo', 'baz')
        s.addline('foo', 'bap')
        self.assertEqual(s.get_line_number('foo'), 3)
        self.assertEqual(s.get_line_number('other'), 0)
        self.assertEqual(s.getline('foo', 0), 'bar')
        self.assertEqual(s.getline('foo', 1), 'baz')
        self.assertEqual(s.getline('foo', 2), 'bap')
        self.assertEqual(s.getline('foo', -1), 'bap')

    def test_empty_line_number(self):
        s = SharedHistory[self.uzbl]
        s.addline('foo', 'bar')
        self.assertEqual(s.get_line_number(''), 0)
        self.assertEqual(s.get_line_number('other'), 0)

    def test_get_missing_prompt(self):
        s = SharedHistory[self.uzbl]
        s.addline('foo', 'bar')
        self.assertRaises(IndexError, s.getline, 'bar', 0)


class HistoryTest(unittest.TestCase):
    def setUp(self):
        self.event_manager = EventManagerMock(
            (SharedHistory,),

# Path: uzbl/plugins/config.py
# class Config(PerInstancePlugin):
#     """Configuration plugin, has dictionary interface for config access
# 
#     This class is currenty not inherited from either UserDict or abc.Mapping
#     because not sure what version of python we want to support. It's not
#     hard to implement all needed methods either.
#     """
# 
#     CONFIG_SECTION = 'config'
# 
#     def __init__(self, uzbl):
#         super(Config, self).__init__(uzbl)
# 
#         self.data = {}
#         uzbl.connect('VARIABLE_SET', self.parse_set_event)
#         assert not 'a' in self.data
# 
#     def __getitem__(self, key):
#         return self.data[key]
# 
#     def __setitem__(self, key, value):
#         self.set(key, value)
# 
#     def __delitem__(self, key):
#         self.set(key)
# 
#     def get(self, key, default=None):
#         return self.data.get(key, default)
# 
#     def __contains__(self, key):
#         return key in self.data
# 
#     def keys(self):
#         return iter(self.data.keys())
# 
#     def items(self):
#         return iter(self.data.items())
# 
#     def update(self, other=None, **kwargs):
#         if other is None:
#             other = {}
# 
#         for (key, value) in list(dict(other).items()) + list(kwargs.items()):
#             self[key] = value
# 
# 
#     def set(self, key, value='', force=False):
#         '''Generates a `set <key> <value>` command string to send to the
#         current uzbl instance.
# 
#         Note that the config dict isn't updated by this function. The config
#         dict is only updated after a successful `VARIABLE_SET ..` event
#         returns from the uzbl instance.'''
# 
#         assert valid_key(key)
# 
#         if isinstance(value, bool):
#             value = int(value)
# 
#         else:
#             value = str(value)
#             assert '\n' not in value
# 
#         if not force and key in self and self[key] == value:
#             return
# 
#         self.uzbl.send('set %s %s' % (key, value))
# 
# 
#     def parse_set_event(self, args):
#         '''Parse `VARIABLE_SET <var> <type> <value>` event and load the
#         (key, value) pair into the `uzbl.config` dict.'''
# 
#         args = splitquoted(args)
#         if len(args) == 2:
#             key, type, raw_value = args[0], args[1], ''
#         elif len(args) == 3:
#             key, type, raw_value = args
#         else:
#             raise Exception('Invalid number of arguments')
# 
#         assert valid_key(key)
#         assert type in types
# 
#         new_value = types[type](raw_value)
#         old_value = self.data.get(key, None)
# 
#         # Update new value.
#         self.data[key] = new_value
# 
#         if old_value != new_value:
#             self.uzbl.event('CONFIG_CHANGED', key, new_value)
# 
#         # Cleanup null config values.
#         if type == 'str' and not new_value:
#             del self.data[key]
# 
#     def cleanup(self):
#         # not sure it's needed, but safer for cyclic links
#         self.data.clear()
#         super(Config, self).cleanup()


# Path: tests/event-manager/testhistory.py
import sys
import unittest
from emtest import EventManagerMock
from six import next
from uzbl.plugins.history import History, SharedHistory
from uzbl.plugins.keycmd import Keylet, KeyCmd
from uzbl.plugins.on_set import OnSetPlugin
from uzbl.plugins.config import Config

        self.assertIs(a, b)

    def test_add_and_get(self):
        s = SharedHistory[self.uzbl]
        s.addline('foo', 'bar')
        s.addline('foo', 'baz')
        s.addline('foo', 'bap')
        self.assertEqual(s.get_line_number('foo'), 3)
        self.assertEqual(s.get_line_number('other'), 0)
        self.assertEqual(s.getline('foo', 0), 'bar')
        self.assertEqual(s.getline('foo', 1), 'baz')
        self.assertEqual(s.getline('foo', 2), 'bap')
        self.assertEqual(s.getline('foo', -1), 'bap')

    def test_empty_line_number(self):
        s = SharedHistory[self.uzbl]
        s.addline('foo', 'bar')
        self.assertEqual(s.get_line_number(''), 0)
        self.assertEqual(s.get_line_number('other'), 0)

    def test_get_missing_prompt(self):
        s = SharedHistory[self.uzbl]
        s.addline('foo', 'bar')
        self.assertRaises(IndexError, s.getline, 'bar', 0)


class HistoryTest(unittest.TestCase):
    def setUp(self):
        self.event_manager = EventManagerMock(
            (SharedHistory,),

            (OnSetPlugin, KeyCmd, Config, History)