Пример #1
0
 def setUp(self):
     self.realm = RootRealm(None)
     self.realm.macros[from_string('X')] = self.macro
     self.realm.macros[from_string('C-M-X')] = self.bad_macro
     self.realm.macros[from_string('Z')] = self.simulated_grumpy_user
     self.realm.macros[from_string('L')] = self.macro_returning_true
     self.macro_called_with = []
Пример #2
0
def configure(factory):
    """Set the right reactor up and get the GUI going."""
    gui = GUI(factory.realm)
    macros = {from_string("<page up>"): gui.forward_page_up_cb,
              from_string('<page down>'): gui.forward_page_down_cb,
              from_string("C-c"): gui.maybe_forward_copy_cb}
    factory.realm.macros.update(macros)
    factory.realm.baked_in_macros.update(macros)
Пример #3
0
def test_modifiers_are_case_sensitive():
    try:
        res = from_string('m-f')
    except InvalidModifiersError:
        pass
    else:
        assert False
Пример #4
0
def test_rejects_blank_key_with_modifier():
    try:
        res = from_string('M-')
    except CantParseThatError:
        pass
    else:
        assert False
Пример #5
0
def test_blows_up_on_unexpected_sequence_of_characters():
    try:
        res = from_string('foo')
    except CantParseThatError:
        pass
    else:
        assert False, res
Пример #6
0
def test_rejects_dash_on_its_own():
    try:
        res = from_string('-')
    except (InvalidModifiersError, CantParseThatError):
        pass
    else:
        assert False
Пример #7
0
def test_blows_up_on_unclosed_special_key():
    try:
        res = from_string('<escape')
    except CantParseThatError:
        pass
    else:
        assert False, res
Пример #8
0
def test_rejects_unknown_modifier():
    try:
        res = from_string('x-f')
    except InvalidModifiersError:
        pass
    else:
        assert False
Пример #9
0
 def test_KeyboardInterrupt_is_not_caught(self):
     try:
         self.realm.maybe_do_macro(from_string('Z'))
     except KeyboardInterrupt:
         pass
     else:
         assert False
Пример #10
0
def test_special_keys_go_through_alright():
    allowed_specials = ["backspace", 
                        "tab", 
                        "return",
                        "enter",
                        "dash",
                        "pause",
                        "escape",
                        "page up",
                        "page down",
                        "end",
                        "home",
                        "left",
                        "up",
                        "right",
                        "down", 
                        "insert",
                        "delete"] + \
                        ['f%d' % n for n in range(1, 13)] + \
                        ['numpad %s' % n for n in range(0, 10) +
                                                  ['add', 'divide', 
                                                   'multiply', 'subtract']]

    for special in allowed_specials:
        yield single_keychord_key_equal, special, from_string('<%s>' % special)
Пример #11
0
def test_rejects_blank_key():
    try:
        res = from_string('')
    except CantParseThatError:
        pass
    else:
        assert False
Пример #12
0
def test_invalid_special_keys_raises_errors():
    invalid_specials = ['foo', 'bar', 'baz']

    for special in invalid_specials:
        try:
            v = from_string('<%s>')
        except InvalidSpecialKeyError:
            pass
        else:
            assert False, v
Пример #13
0
 def lineReceived_recomposed(self, line):
     meth, rest = json.loads(line)
     if meth == 'ack':
         self.messages_not_acknowledged -= 1
         if not self.messages_not_acknowledged:
             process_time = time.time() - self.client_started_processing_at
             self.communicator.total_client_time += process_time
             self.client_started_processing_at = None
             #print('Process Time: %(process_time)d, Total Process Time: %(total_process_time)d\n'%
             #      {'process_time':process_time, 'total_process_time':self.communicator.total_client_time})
     elif meth == 'send_to_mud':
         self.communicator.telnet.sendLine(rest)   
     elif meth == 'ping':
         self.send_to_client('ping', []) 
     elif meth == "display_line":
         metaline = json_to_metaline(rest[0])
         soft_line_start = bool(rest[1])
         self.communicator.write(metaline, soft_line_start)
     elif meth == 'set_active_channels':
         self.communicator.setActiveChannels(rest)
     elif meth == "hello":
         macros = rest[0]
         def make_macro(cmd):
             def macro(cc):
                 cc.client.do_alias(cmd, False)
             return macro
         self.communicator.macros.clear()
         self.communicator.macros.update(dict((from_string(k), make_macro(l)) for k, l in macros.items()))
         self.communicator.macros.update(self.communicator.baked_in_macros)
         self.communicator.clientConnectionMade(self)
     elif meth == "error":
         if self.communicator.debug:
             self.communicator.cwrite('<white*:red>ERROR RECEIVED: \n %s'%rest)
         else:
             print(rest)
     elif meth == 'set_state':
         self.communicator.set_state(rest[0],rest[1])
     elif meth == 'event':
         event_name = rest[0]
         args = rest[1]
         self.communicator.fireEventLocal(event_name, *args)
     
     elif meth == 'debug':
         line = rest[0]
         if self.communicator.debug:
             self.communicator.cwrite('<grey:white>PROCESSOR DEBUG [[%s]]'%line)
         else:
             print('PROCESSOR DEBUG [[%s]]'%line)
     else:
         if self.communicator.debug:
             self.communicator.cwrite('<white*:red>UNKNOWN METHOD RECEIVED: \n Method:%(meth)s \n Args: %(rest)s'%{'rest':rest, 'meth':meth})
         else:
             print('UNKNOWN METHOD RECEIVED: \n Method:%(meth)s \n Args: %(rest)s'%{'rest':rest, 'meth':meth})
Пример #14
0
 def test_Exception_is_caught(self, tb):
     self.realm.maybe_do_macro(from_string('C-M-X'))
     assert tb.print_exc.called
Пример #15
0
 def test_bad_macros_still_return_True(self, tb):
     res = self.realm.maybe_do_macro(from_string('C-M-X'))
     assert res
Пример #16
0
 def test_calls_macro_with_itself(self):
     self.realm.maybe_do_macro(from_string('X'))
     assert len(self.macro_called_with) == 1
     assert self.macro_called_with[0] is self.realm
Пример #17
0
def test_equal_chords_hash_the_same():
    assert hash(from_string('f')) == hash(from_string('f'))
Пример #18
0
 def test_returns_False_if_no_macro_found(self):
     res = self.realm.maybe_do_macro(from_string('Q'))
     assert not res
Пример #19
0
 def test_returns_True_if_a_macro_found(self):
     res = self.realm.maybe_do_macro(from_string('X'))
     assert res
Пример #20
0
def trace_toggle(realm):
    """Turn tracing on or off, depending on its current state."""
    if not realm.tracing:
        realm.trace_on()
    else:
        realm.trace_off()

def keypad_move(direction):
    """A wrapper to stop me having loads of different direction-moving
    functions.
    """
    def walker(realm):
        """Actually send the direction."""
        realm.send(direction)
    return walker

#pylint: enable-msg= W0613

keypad_directions = {from_string('<numpad 7>'): keypad_move('nw'),
                     from_string('<numpad 8>'): keypad_move('n'),
                     from_string('<numpad 9>'): keypad_move('ne'),
                     from_string('<numpad 4>'): keypad_move('w'),
                     from_string('<numpad 6>'): keypad_move('e'),
                     from_string('<numpad 1>'): keypad_move('sw'),
                     from_string('<numpad 2>'): keypad_move('s'),
                     from_string('<numpad 3>'): keypad_move('se'),
                     from_string('<numpad divide>'): keypad_move('in'),
                     from_string('<numpad multiply>'): keypad_move('out'),
                     from_string('<numpad subtract>'): keypad_move('up'),
                     from_string('<numpad add>'): keypad_move('down')}
Пример #21
0
def test_normal_key_case_insensitive():
    assert from_string('F').key == 'f'
Пример #22
0
"""The predefined keybindings for the GUI."""
from pymudclient.gui.keychords import from_string
from pymudclient.aliases import binding_alias

gui_macros = {}

def enter_pressed(realm):
    """Submit the line to the realm."""
    realm.factory.gui.command_line.submit_line()

gui_macros[from_string('<Enter>')] = enter_pressed
gui_macros[from_string('<Return>')] = enter_pressed

def escape_pressed(realm):
    """Escape's been pressed. Store the current line in the history, and then
    clear the entry area.
    """
    realm.factory.gui.command_line.escape_pressed()

gui_macros[from_string('<Escape>')] = escape_pressed

def tab_pressed(realm):
    """Complete the current word in the buffer."""
    realm.factory.gui.command_line.tab_complete()

gui_macros[from_string('<Tab>')] = tab_pressed

def up_pressed(realm):
    """Go back one command in the history."""
    realm.factory.gui.command_line.history_up()
Пример #23
0
def test_equality():
    #XXX: other interesting comparison cases
    kc1 = from_string('f')
    kc2 = from_string('f')
    assert kc1 == kc2, (kc1, kc2)
Пример #24
0
def test_inequality():
    assert from_string('m') != from_string('r')
Пример #25
0
def test_plays_nice_with_dict():
    d = {from_string('C-f'): 'foo',
         from_string('M-f'): 'bar',
         from_string('f'): 'baz'}
    assert from_string('C-f') in d
    assert d[from_string('M-f')] == 'bar'
Пример #26
0
def test_case_insensitivity_in_special_keys():
    vals = ['escape', 'EsCaPe', 'esCApe', 'ESCAPE']

    for val in vals:
        yield single_keychord_key_equal, 'escape', from_string('<%s>' % val)
Пример #27
0
 def test_macro_that_returns_True_tells_gui_to_keep_processing(self):
     res = self.realm.maybe_do_macro(from_string('L'))
     assert not res
Пример #28
0
def test_ordering_of_modifiers_doesnt_matter():
    c1 = from_string('C-M-q')
    c2 = from_string('M-C-q')
    assert c1 == c2
Пример #29
0
def test_KeyChord_unicode_and_ascii_characters_are_the_same():
    kc1 = from_string('f')
    kc2 = from_string(u'f')
    assert kc1 == kc2
Пример #30
0
def test_normal_key_setting():
    assert from_string('f').key == 'f'