Esempio n. 1
0
    def __init__(self, service, sock, *, serializer=None, content_monitor=None):
        # Backend instance that created this connection.
        self.service = service
        # Socket used to talk to frontend.
        self.sock = sock
        #: Timestamp of last message received from this frontend (initialized due to accept).
        self.ts_last_data_received = datetime.datetime.now()

        #: Serializer used to decode data from frontend.
        self.serializer = serializer or MessageSerializer()

        #: Content monitor for synchronized file data sent by connected frontend.
        self.content_monitor = content_monitor or ContentMonitor()
Esempio n. 2
0
def test_out_of_sync():
    monitor = ContentMonitor()
    monitor.synchronize(mock.sentinel.FILEPATH, "This is the string.", 0)
    assert monitor.synchronize(mock.sentinel.FILEPATH, " Really!", 20, 22) == SynchronizationResult.OutOfSync
    assert monitor[mock.sentinel.FILEPATH] == "This is the string."
    assert monitor.synchronize(mock.sentinel.FILEPATH, " Really!", 10, 9) == SynchronizationResult.OutOfSync
    assert monitor[mock.sentinel.FILEPATH] == "This is the string."
    assert monitor.synchronize(mock.sentinel.FILEPATH, " Really!", -1, 5) == SynchronizationResult.OutOfSync
    assert monitor[mock.sentinel.FILEPATH] == "This is the string."
    assert monitor.synchronize(mock.sentinel.FILEPATH, " Really!", 0, -1) == SynchronizationResult.OutOfSync
    assert monitor[mock.sentinel.FILEPATH] == "This is the string."
Esempio n. 3
0
def test_out_of_sync():
    monitor = ContentMonitor()
    monitor.synchronize(mock.sentinel.FILEPATH, 'This is the string.', 0)
    assert monitor.synchronize(mock.sentinel.FILEPATH, ' Really!', 20,
                               22) == SynchronizationResult.OutOfSync
    assert monitor[mock.sentinel.FILEPATH] == 'This is the string.'
    assert monitor.synchronize(mock.sentinel.FILEPATH, ' Really!', 10,
                               9) == SynchronizationResult.OutOfSync
    assert monitor[mock.sentinel.FILEPATH] == 'This is the string.'
    assert monitor.synchronize(mock.sentinel.FILEPATH, ' Really!', -1,
                               5) == SynchronizationResult.OutOfSync
    assert monitor[mock.sentinel.FILEPATH] == 'This is the string.'
    assert monitor.synchronize(mock.sentinel.FILEPATH, ' Really!', 0,
                               -1) == SynchronizationResult.OutOfSync
    assert monitor[mock.sentinel.FILEPATH] == 'This is the string.'
Esempio n. 4
0
def test_append():
    monitor = ContentMonitor()
    monitor.synchronize(mock.sentinel.FILEPATH, "This is the string.", 0)
    assert monitor.synchronize(mock.sentinel.FILEPATH, " Really!", 19, 19) == SynchronizationResult.Updated
    assert monitor[mock.sentinel.FILEPATH] == "This is the string. Really!"
Esempio n. 5
0
def test_insert_beginning():
    monitor = ContentMonitor()
    monitor.synchronize(mock.sentinel.FILEPATH, "This is the string.", 0)
    assert monitor.synchronize(mock.sentinel.FILEPATH, "Listen: ", 0, 0) == SynchronizationResult.Updated
    assert monitor[mock.sentinel.FILEPATH] == "Listen: This is the string."
Esempio n. 6
0
def test_replace_part():
    monitor = ContentMonitor()
    monitor.synchronize(mock.sentinel.FILEPATH, "This is the string.", 0)
    assert monitor.synchronize(mock.sentinel.FILEPATH, "WAS", 5, 7) == SynchronizationResult.Updated
    assert monitor[mock.sentinel.FILEPATH] == "This WAS the string."
Esempio n. 7
0
def test_replace_all():
    monitor = ContentMonitor()
    monitor.synchronize(mock.sentinel.FILEPATH, "This is the string.", 0)
    assert monitor.synchronize(mock.sentinel.FILEPATH, "Something else", 0) == SynchronizationResult.Updated
    assert monitor[mock.sentinel.FILEPATH] == "Something else"
Esempio n. 8
0
def test_initial_sync():
    monitor = ContentMonitor()
    assert monitor.synchronize(mock.sentinel.FILEPATH, "This is the string.", 0) == SynchronizationResult.Updated
    assert monitor[mock.sentinel.FILEPATH] == "This is the string."
Esempio n. 9
0
def test_content_empty():
    monitor = ContentMonitor()
    assert monitor[mock.sentinel.UNKNOWN_FILE] is None
Esempio n. 10
0
def test_append():
    monitor = ContentMonitor()
    monitor.synchronize(mock.sentinel.FILEPATH, 'This is the string.', 0)
    assert monitor.synchronize(mock.sentinel.FILEPATH, ' Really!', 19,
                               19) == SynchronizationResult.Updated
    assert monitor[mock.sentinel.FILEPATH] == 'This is the string. Really!'
Esempio n. 11
0
def test_insert_beginning():
    monitor = ContentMonitor()
    monitor.synchronize(mock.sentinel.FILEPATH, 'This is the string.', 0)
    assert monitor.synchronize(mock.sentinel.FILEPATH, 'Listen: ', 0,
                               0) == SynchronizationResult.Updated
    assert monitor[mock.sentinel.FILEPATH] == 'Listen: This is the string.'
Esempio n. 12
0
def test_replace_part():
    monitor = ContentMonitor()
    monitor.synchronize(mock.sentinel.FILEPATH, 'This is the string.', 0)
    assert monitor.synchronize(mock.sentinel.FILEPATH, 'WAS', 5,
                               7) == SynchronizationResult.Updated
    assert monitor[mock.sentinel.FILEPATH] == 'This WAS the string.'
Esempio n. 13
0
def test_replace_all():
    monitor = ContentMonitor()
    monitor.synchronize(mock.sentinel.FILEPATH, 'This is the string.', 0)
    assert monitor.synchronize(mock.sentinel.FILEPATH, 'Something else',
                               0) == SynchronizationResult.Updated
    assert monitor[mock.sentinel.FILEPATH] == 'Something else'
Esempio n. 14
0
def test_initial_sync():
    monitor = ContentMonitor()
    assert monitor.synchronize(mock.sentinel.FILEPATH, 'This is the string.',
                               0) == SynchronizationResult.Updated
    assert monitor[mock.sentinel.FILEPATH] == 'This is the string.'