Example #1
0
def save_local_info(username, password, accounts, local_order):
    assert isinstance(username, basestring)
    assert isinstance(password, basestring)
    log.debug_s("saving local: %r", serialize_local(accounts, local_order))
    data = encrypt(username, password, serialize_local(accounts, local_order))

    with files.atomic_write(local_file(username), "wb") as f:
        f.write(data)
Example #2
0
def save_local_info(username, password, accounts, local_order):
    assert isinstance(username, basestring)
    assert isinstance(password, basestring)
    log.debug_s('saving local: %r', serialize_local(accounts, local_order))
    data = encrypt(username, password, serialize_local(accounts, local_order))

    with files.atomic_write(local_file(username), 'wb') as f:
        f.write(data)
Example #3
0
def save_server_info(username, password, server_account_hash, server_order):
    assert isinstance(username, basestring)
    assert isinstance(password, basestring)
    server_data = serialize_server(server_account_hash, server_order)
    log.debug_s("saving server: %r", server_data)
    data = encrypt(username, password, server_data)

    with files.atomic_write(server_file(username), "wb") as f:
        f.write(data)
Example #4
0
def save_server_info(username, password, server_account_hash, server_order):
    assert isinstance(username, basestring)
    assert isinstance(password, basestring)
    server_data = serialize_server(server_account_hash, server_order)
    log.debug_s('saving server: %r', server_data)
    data = encrypt(username, password, server_data)

    with files.atomic_write(server_file(username), 'wb') as f:
        f.write(data)
Example #5
0
    def set(self, key, value):
        '''
        Put 'value' in '_storage' as 'key'
        '''
        if not self.storage.isdir():
            self.storage.makedirs()

        data = self.serialize(key, value)

        with files.atomic_write(self.storage / key, 'wb') as f:
            f.write(data)
Example #6
0
    def set(self, key, value):
        '''
        Put 'value' in '_storage' as 'key'
        '''
        if not self.storage.isdir():
            self.storage.makedirs()

        data = self.serialize(key, value)

        with files.atomic_write(self.storage / key, 'wb') as f:
            f.write(data)
Example #7
0
    def test_atomic_write(self):
        temp_name = os.path.join('c:\\', 'test_abc_def.txt')
        assert not os.path.isfile(temp_name)

        try:
            # a fresh file: write to temporary and then rename will be used
            with atomic_write(temp_name) as f:
                f.write('good')

            assert filecontents(temp_name) == 'good'

            # a second time: ReplaceFile will be used on Windows
            with atomic_write(temp_name) as f:
                f.write('good 2')

            assert filecontents(temp_name) == 'good 2'

            # TODO: test error during a write

        finally:
            if os.path.isfile(temp_name):
                os.remove(temp_name)
Example #8
0
    def test_atomic_write(self):
        temp_name = os.path.join('c:\\', 'test_abc_def.txt')
        assert not os.path.isfile(temp_name)

        try:
            # a fresh file: write to temporary and then rename will be used
            with atomic_write(temp_name) as f:
                f.write('good')

            assert filecontents(temp_name) == 'good'

            # a second time: ReplaceFile will be used on Windows
            with atomic_write(temp_name) as f:
                f.write('good 2')

            assert filecontents(temp_name) == 'good 2'


            # TODO: test error during a write

        finally:
            if os.path.isfile(temp_name):
                os.remove(temp_name)