# Path: uzbl/plugins/on_event.py
# class OnEventPlugin(PerInstancePlugin):
#     CONFIG_SECTION = 'on_event'
# 
#     def __init__(self, uzbl):
#         '''Export functions and connect handlers to events.'''
#         super(OnEventPlugin, self).__init__(uzbl)
# 
#         self.events = {}
# 
#         uzbl.connect('ON_EVENT', self.parse_on_event)
# 
#     def event_handler(self, *args, **kargs):
#         '''This function handles all the events being watched by various
#         on_event definitions and responds accordingly.'''
# 
#         # Could be connected to a EM internal event that can use anything as
#         # arguments
#         if len(args) == 1 and isinstance(args[0], str):
#             args = splitquoted(args[0])
# 
#         event = kargs['on_event']
#         if event not in self.events:
#             return
# 
#         commands = self.events[event]
#         for cmd, pattern in commands:
#             if not pattern or match_args(pattern, args):
#                 send_user_command(self.uzbl, cmd, args)
# 
#     def on_event(self, event, pattern, cmd):
#         '''Add a new event to watch and respond to.'''
# 
#         event = event.upper()
#         self.logger.debug('new event handler %r %r %r', event, pattern, cmd)
#         if event not in self.events:
#             self.uzbl.connect(event,
#                               partial(self.event_handler, on_event=event))
#             self.events[event] = []
# 
#         if isinstance(cmd, str):
#             cmd = (cmd,)
# 
#         cmds = self.events[event]
#         if cmd not in cmds:
#             cmds.append((cmd, pattern))
# 
#     def parse_on_event(self, args):
#         '''Parse ON_EVENT events and pass them to the on_event function.
# 
#         Syntax: "event ON_EVENT <EVENT_NAME> <[ pattern ]> commands".'''
# 
#         args = splitquoted(args)
#         assert args, 'missing on event arguments'
# 
#         # split into event name, optional argument pattern and command
#         event = args[0]
#         pattern = []
#         if args[1] == '[':
#             for i, arg in enumerate(args[2:]):
#                 if arg == ']':
#                     break
#                 pattern.append(arg)
#             command = tuple(args[3+i:])
#         else:
#             command = tuple(args[1:])
# 
#         assert event and command, 'missing on event command'
#         self.on_event(event, pattern, command)
# 
#     def cleanup(self):
#         self.events.clear()
#         super(OnEventPlugin, self).cleanup()


import unittest
from emtest import EventManagerMock
from uzbl.plugins.on_event import OnEventPlugin
#!/usr/bin/env python
# vi: set et ts=4:



class OnEventTest(unittest.TestCase):
    def setUp(self):
        self.event_manager = EventManagerMock(

# Path: uzbl/plugins/on_event.py
# class OnEventPlugin(PerInstancePlugin):
#     CONFIG_SECTION = 'on_event'
# 
#     def __init__(self, uzbl):
#         '''Export functions and connect handlers to events.'''
#         super(OnEventPlugin, self).__init__(uzbl)
# 
#         self.events = {}
# 
#         uzbl.connect('ON_EVENT', self.parse_on_event)
# 
#     def event_handler(self, *args, **kargs):
#         '''This function handles all the events being watched by various
#         on_event definitions and responds accordingly.'''
# 
#         # Could be connected to a EM internal event that can use anything as
#         # arguments
#         if len(args) == 1 and isinstance(args[0], str):
#             args = splitquoted(args[0])
# 
#         event = kargs['on_event']
#         if event not in self.events:
#             return
# 
#         commands = self.events[event]
#         for cmd, pattern in commands:
#             if not pattern or match_args(pattern, args):
#                 send_user_command(self.uzbl, cmd, args)
# 
#     def on_event(self, event, pattern, cmd):
#         '''Add a new event to watch and respond to.'''
# 
#         event = event.upper()
#         self.logger.debug('new event handler %r %r %r', event, pattern, cmd)
#         if event not in self.events:
#             self.uzbl.connect(event,
#                               partial(self.event_handler, on_event=event))
#             self.events[event] = []
# 
#         if isinstance(cmd, str):
#             cmd = (cmd,)
# 
#         cmds = self.events[event]
#         if cmd not in cmds:
#             cmds.append((cmd, pattern))
# 
#     def parse_on_event(self, args):
#         '''Parse ON_EVENT events and pass them to the on_event function.
# 
#         Syntax: "event ON_EVENT <EVENT_NAME> <[ pattern ]> commands".'''
# 
#         args = splitquoted(args)
#         assert args, 'missing on event arguments'
# 
#         # split into event name, optional argument pattern and command
#         event = args[0]
#         pattern = []
#         if args[1] == '[':
#             for i, arg in enumerate(args[2:]):
#                 if arg == ']':
#                     break
#                 pattern.append(arg)
#             command = tuple(args[3+i:])
#         else:
#             command = tuple(args[1:])
# 
#         assert event and command, 'missing on event command'
#         self.on_event(event, pattern, command)
# 
#     def cleanup(self):
#         self.events.clear()
#         super(OnEventPlugin, self).cleanup()


# Path: tests/event-manager/testonevent.py
import unittest
from emtest import EventManagerMock
from uzbl.plugins.on_event import OnEventPlugin

#!/usr/bin/env python
# vi: set et ts=4:



class OnEventTest(unittest.TestCase):
    def setUp(self):
        self.event_manager = EventManagerMock(

            (), (OnEventPlugin,),