cleanup whitespace and long-lines

This commit is contained in:
Job Evers-Meltzer 2016-11-04 11:39:52 -05:00
parent 0036685ece
commit 43b2cd1433
3 changed files with 23 additions and 24 deletions

View file

@ -65,12 +65,10 @@ class StreamCreator(object):
pass pass
def write(self, data): def write(self, data):
from twisted.internet import reactor from twisted.internet import reactor
self._write(data) self._write(data)
if self.stopped is False and self.streaming is False: if self.stopped is False and self.streaming is False:
reactor.callLater(0, self.producer.resumeProducing) reactor.callLater(0, self.producer.resumeProducing)
def _write(self, data): def _write(self, data):
pass pass

View file

@ -18,22 +18,23 @@ log = logging.getLogger(__name__)
class CryptStreamCreator(StreamCreator): class CryptStreamCreator(StreamCreator):
"""Create a new stream with blobs encrypted by a symmetric cipher. """Create a new stream with blobs encrypted by a symmetric cipher.
Each blob is encrypted with the same key, but each blob has its own initialization vector Each blob is encrypted with the same key, but each blob has its
which is associated with the blob when the blob is associated with the stream.""" own initialization vector which is associated with the blob when
the blob is associated with the stream.
"""
def __init__(self, blob_manager, name=None, key=None, iv_generator=None): def __init__(self, blob_manager, name=None, key=None, iv_generator=None):
""" """@param blob_manager: Object that stores and provides access to blobs.
@param blob_manager: Object that stores and provides access to blobs.
@type blob_manager: BlobManager @type blob_manager: BlobManager
@param name: the name of the stream, which will be presented to the user @param name: the name of the stream, which will be presented to the user
@type name: string @type name: string
@param key: the raw AES key which will be used to encrypt the blobs. If None, a random key will @param key: the raw AES key which will be used to encrypt the
be generated. blobs. If None, a random key will be generated.
@type key: string @type key: string
@param iv_generator: a generator which yields initialization vectors for the blobs. Will be called @param iv_generator: a generator which yields initialization
once for each blob. vectors for the blobs. Will be called once for each blob.
@type iv_generator: a generator function which yields strings @type iv_generator: a generator function which yields strings
@return: None @return: None
@ -75,7 +76,6 @@ class CryptStreamCreator(StreamCreator):
return d return d
def _write(self, data): def _write(self, data):
def close_blob(blob): def close_blob(blob):
d = blob.close() d = blob.close()
d.addCallback(self._blob_finished) d.addCallback(self._blob_finished)
@ -94,4 +94,4 @@ class CryptStreamCreator(StreamCreator):
self.current_blob = None self.current_blob = None
def _get_blob_maker(self, iv, blob_creator): def _get_blob_maker(self, iv, blob_creator):
return CryptStreamBlobMaker(self.key, iv, self.blob_count, blob_creator) return CryptStreamBlobMaker(self.key, iv, self.blob_count, blob_creator)

View file

@ -24,10 +24,7 @@ class EncryptedFileStreamCreator(CryptStreamCreator):
key=None, iv_generator=None, suggested_file_name=None): key=None, iv_generator=None, suggested_file_name=None):
CryptStreamCreator.__init__(self, blob_manager, name, key, iv_generator) CryptStreamCreator.__init__(self, blob_manager, name, key, iv_generator)
self.lbry_file_manager = lbry_file_manager self.lbry_file_manager = lbry_file_manager
if suggested_file_name is None: self.suggested_file_name = suggested_file_name or name
self.suggested_file_name = name
else:
self.suggested_file_name = suggested_file_name
self.stream_hash = None self.stream_hash = None
self.blob_infos = [] self.blob_infos = []
@ -82,8 +79,7 @@ class EncryptedFileStreamCreator(CryptStreamCreator):
def create_lbry_file(session, lbry_file_manager, file_name, file_handle, key=None, def create_lbry_file(session, lbry_file_manager, file_name, file_handle, key=None,
iv_generator=None, suggested_file_name=None): iv_generator=None, suggested_file_name=None):
""" """Turn a plain file into an LBRY File.
Turn a plain file into an LBRY File.
An LBRY File is a collection of encrypted blobs of data and the metadata that binds them An LBRY File is a collection of encrypted blobs of data and the metadata that binds them
together which, when decrypted and put back together according to the metadata, results together which, when decrypted and put back together according to the metadata, results
@ -113,8 +109,8 @@ def create_lbry_file(session, lbry_file_manager, file_name, file_handle, key=Non
be generated. be generated.
@type key: string @type key: string
@param iv_generator: a generator which yields initialization vectors for the blobs. Will be called @param iv_generator: a generator which yields initialization
once for each blob. vectors for the blobs. Will be called once for each blob.
@type iv_generator: a generator function which yields strings @type iv_generator: a generator function which yields strings
@param suggested_file_name: what the file should be called when the LBRY File is saved to disk. @param suggested_file_name: what the file should be called when the LBRY File is saved to disk.
@ -130,7 +126,8 @@ def create_lbry_file(session, lbry_file_manager, file_name, file_handle, key=Non
def make_stream_desc_file(stream_hash): def make_stream_desc_file(stream_hash):
log.debug("creating the stream descriptor file") log.debug("creating the stream descriptor file")
descriptor_file_path = os.path.join(session.db_dir, file_name + settings.CRYPTSD_FILE_EXTENSION) descriptor_file_path = os.path.join(
session.db_dir, file_name + settings.CRYPTSD_FILE_EXTENSION)
descriptor_writer = PlainStreamDescriptorWriter(descriptor_file_path) descriptor_writer = PlainStreamDescriptorWriter(descriptor_file_path)
d = get_sd_info(lbry_file_manager.stream_info_manager, stream_hash, True) d = get_sd_info(lbry_file_manager.stream_info_manager, stream_hash, True)
@ -141,8 +138,12 @@ def create_lbry_file(session, lbry_file_manager, file_name, file_handle, key=Non
base_file_name = os.path.basename(file_name) base_file_name = os.path.basename(file_name)
lbry_file_creator = EncryptedFileStreamCreator(session.blob_manager, lbry_file_manager, base_file_name, lbry_file_creator = EncryptedFileStreamCreator(
key, iv_generator, suggested_file_name) session.blob_manager,
lbry_file_manager,
base_file_name, key,
iv_generator,
suggested_file_name)
def start_stream(): def start_stream():
file_sender = FileSender() file_sender = FileSender()