fix encoding on download

This commit is contained in:
Victor Shyba 2018-08-10 18:23:50 -03:00 committed by Jack Robison
parent 3f6e928cc2
commit 0841c90e6c
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
10 changed files with 26 additions and 25 deletions

View file

@ -158,7 +158,7 @@ class Manager:
@staticmethod @staticmethod
def _download_properties(id_, name, claim_dict=None, report=None): def _download_properties(id_, name, claim_dict=None, report=None):
sd_hash = None if not claim_dict else claim_dict.source_hash sd_hash = None if not claim_dict else claim_dict.source_hash.decode()
p = { p = {
'download_id': id_, 'download_id': id_,
'name': name, 'name': name,
@ -177,9 +177,9 @@ class Manager:
return { return {
'download_id': id_, 'download_id': id_,
'name': name, 'name': name,
'stream_info': claim_dict.source_hash, 'stream_info': claim_dict.source_hash.decode(),
'error': error_name(error), 'error': error_name(error),
'reason': error.message, 'reason': str(error),
'report': report 'report': report
} }

View file

@ -109,7 +109,7 @@ class ClientProtocol(Protocol, TimeoutMixin):
self.connection_closing = True self.connection_closing = True
ds = [] ds = []
err = RequestCanceledError() err = RequestCanceledError()
for key, d in self._response_deferreds.items(): for key, d in list(self._response_deferreds.items()):
del self._response_deferreds[key] del self._response_deferreds[key]
d.errback(err) d.errback(err)
ds.append(d) ds.append(d)

View file

@ -96,7 +96,7 @@ class ConnectionManager:
d.addBoth(lambda _: disconnect_peer(p)) d.addBoth(lambda _: disconnect_peer(p))
return d return d
closing_deferreds = [close_connection(peer) for peer in self._peer_connections.keys()] closing_deferreds = [close_connection(peer) for peer in list(self._peer_connections.keys())]
return defer.DeferredList(closing_deferreds) return defer.DeferredList(closing_deferreds)
@defer.inlineCallbacks @defer.inlineCallbacks

View file

@ -292,7 +292,7 @@ class Daemon(AuthJSONRPCServer):
@defer.inlineCallbacks @defer.inlineCallbacks
def _get_stream_analytics_report(self, claim_dict): def _get_stream_analytics_report(self, claim_dict):
sd_hash = claim_dict.source_hash sd_hash = claim_dict.source_hash.decode()
try: try:
stream_hash = yield self.storage.get_stream_hash_for_sd_hash(sd_hash) stream_hash = yield self.storage.get_stream_hash_for_sd_hash(sd_hash)
except Exception: except Exception:
@ -371,7 +371,7 @@ class Daemon(AuthJSONRPCServer):
log.error('Failed to get %s (%s)', name, err) log.error('Failed to get %s (%s)', name, err)
if self.streams[sd_hash].downloader and self.streams[sd_hash].code != 'running': if self.streams[sd_hash].downloader and self.streams[sd_hash].code != 'running':
yield self.streams[sd_hash].downloader.stop(err) yield self.streams[sd_hash].downloader.stop(err)
result = {'error': err.message} result = {'error': str(err)}
finally: finally:
del self.streams[sd_hash] del self.streams[sd_hash]
defer.returnValue(result) defer.returnValue(result)
@ -1413,7 +1413,7 @@ class Daemon(AuthJSONRPCServer):
resolved = resolved['claim'] resolved = resolved['claim']
txid, nout, name = resolved['txid'], resolved['nout'], resolved['name'] txid, nout, name = resolved['txid'], resolved['nout'], resolved['name']
claim_dict = ClaimDict.load_dict(resolved['value']) claim_dict = ClaimDict.load_dict(resolved['value'])
sd_hash = claim_dict.source_hash sd_hash = claim_dict.source_hash.decode()
if sd_hash in self.streams: if sd_hash in self.streams:
log.info("Already waiting on lbry://%s to start downloading", name) log.info("Already waiting on lbry://%s to start downloading", name)

View file

@ -162,7 +162,7 @@ class GetStream:
@defer.inlineCallbacks @defer.inlineCallbacks
def _initialize(self, stream_info): def _initialize(self, stream_info):
# Set sd_hash and return key_fee from stream_info # Set sd_hash and return key_fee from stream_info
self.sd_hash = stream_info.source_hash self.sd_hash = stream_info.source_hash.decode()
key_fee = None key_fee = None
if stream_info.has_fee: if stream_info.has_fee:
key_fee = yield self.check_fee_and_convert(stream_info.source_fee) key_fee = yield self.check_fee_and_convert(stream_info.source_fee)

View file

@ -492,9 +492,9 @@ class SQLiteStorage:
@defer.inlineCallbacks @defer.inlineCallbacks
def save_downloaded_file(self, stream_hash, file_name, download_directory, data_payment_rate): def save_downloaded_file(self, stream_hash, file_name, download_directory, data_payment_rate):
# touch the closest available file to the file name # touch the closest available file to the file name
file_name = yield open_file_for_writing(unhexlify(download_directory), unhexlify(file_name)) file_name = yield open_file_for_writing(unhexlify(download_directory).decode(), unhexlify(file_name).decode())
result = yield self.save_published_file( result = yield self.save_published_file(
stream_hash, hexlify(file_name), download_directory, data_payment_rate stream_hash, hexlify(file_name.encode()), download_directory, data_payment_rate
) )
defer.returnValue(result) defer.returnValue(result)

View file

@ -2,7 +2,7 @@
Download LBRY Files from LBRYnet and save them to disk. Download LBRY Files from LBRYnet and save them to disk.
""" """
import logging import logging
import binascii from binascii import hexlify, unhexlify
from twisted.internet import defer from twisted.internet import defer
from lbrynet import conf from lbrynet import conf
@ -43,7 +43,7 @@ class ManagedEncryptedFileDownloader(EncryptedFileSaver):
) )
self.sd_hash = sd_hash self.sd_hash = sd_hash
self.rowid = rowid self.rowid = rowid
self.suggested_file_name = binascii.unhexlify(suggested_file_name) self.suggested_file_name = unhexlify(suggested_file_name).decode()
self.lbry_file_manager = lbry_file_manager self.lbry_file_manager = lbry_file_manager
self._saving_status = False self._saving_status = False
self.claim_id = None self.claim_id = None
@ -178,9 +178,10 @@ class ManagedEncryptedFileDownloaderFactory:
metadata.source_blob_hash, metadata.source_blob_hash,
metadata.validator.raw_info) metadata.validator.raw_info)
if file_name: if file_name:
file_name = binascii.hexlify(file_name) file_name = hexlify(file_name.encode())
hex_download_directory = hexlify(download_directory.encode())
lbry_file = yield self.lbry_file_manager.add_downloaded_file( lbry_file = yield self.lbry_file_manager.add_downloaded_file(
stream_hash, metadata.source_blob_hash, binascii.hexlify(download_directory), payment_rate_manager, stream_hash, metadata.source_blob_hash, hex_download_directory, payment_rate_manager,
data_rate, file_name=file_name, download_mirrors=download_mirrors data_rate, file_name=file_name, download_mirrors=download_mirrors
) )
defer.returnValue(lbry_file) defer.returnValue(lbry_file)

View file

@ -188,7 +188,7 @@ class EncryptedFileManager:
rowid = yield self.storage.save_downloaded_file( rowid = yield self.storage.save_downloaded_file(
stream_hash, hexlify(os.path.basename(unhexlify(file_name))), download_directory, blob_data_rate stream_hash, hexlify(os.path.basename(unhexlify(file_name))), download_directory, blob_data_rate
) )
file_name = yield self.storage.get_filename_for_rowid(rowid) file_name = (yield self.storage.get_filename_for_rowid(rowid)).decode()
lbry_file = self._get_lbry_file( lbry_file = self._get_lbry_file(
rowid, stream_hash, payment_rate_manager, sd_hash, key, stream_name, file_name, download_directory, rowid, stream_hash, payment_rate_manager, sd_hash, key, stream_name, file_name, download_directory,
stream_metadata['suggested_file_name'], download_mirrors stream_metadata['suggested_file_name'], download_mirrors

View file

@ -1,13 +1,13 @@
import binascii import os
import logging
import traceback
from binascii import hexlify, unhexlify
from lbrynet.core.StreamDescriptor import save_sd_info from lbrynet.core.StreamDescriptor import save_sd_info
from lbrynet.cryptstream.client.CryptStreamDownloader import CryptStreamDownloader from lbrynet.cryptstream.client.CryptStreamDownloader import CryptStreamDownloader
from lbrynet.core.client.StreamProgressManager import FullStreamProgressManager from lbrynet.core.client.StreamProgressManager import FullStreamProgressManager
from lbrynet.lbry_file.client.EncryptedFileMetadataHandler import EncryptedFileMetadataHandler from lbrynet.lbry_file.client.EncryptedFileMetadataHandler import EncryptedFileMetadataHandler
import os
from twisted.internet import defer, threads from twisted.internet import defer, threads
import logging
import traceback
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -22,7 +22,7 @@ class EncryptedFileDownloader(CryptStreamDownloader):
payment_rate_manager, wallet, key, stream_name) payment_rate_manager, wallet, key, stream_name)
self.stream_hash = stream_hash self.stream_hash = stream_hash
self.storage = storage self.storage = storage
self.file_name = os.path.basename(binascii.unhexlify(file_name)) self.file_name = os.path.basename(unhexlify(file_name))
self._calculated_total_bytes = None self._calculated_total_bytes = None
@defer.inlineCallbacks @defer.inlineCallbacks
@ -128,8 +128,8 @@ class EncryptedFileSaver(EncryptedFileDownloader):
super().__init__(stream_hash, peer_finder, rate_limiter, super().__init__(stream_hash, peer_finder, rate_limiter,
blob_manager, storage, payment_rate_manager, blob_manager, storage, payment_rate_manager,
wallet, key, stream_name, file_name) wallet, key, stream_name, file_name)
self.download_directory = binascii.unhexlify(download_directory) self.download_directory = unhexlify(download_directory).decode()
self.file_written_to = os.path.join(self.download_directory, binascii.unhexlify(file_name)) self.file_written_to = os.path.join(self.download_directory, unhexlify(file_name).decode())
self.file_handle = None self.file_handle = None
def __str__(self): def __str__(self):
@ -181,7 +181,7 @@ class EncryptedFileSaver(EncryptedFileDownloader):
class EncryptedFileSaverFactory(EncryptedFileDownloaderFactory): class EncryptedFileSaverFactory(EncryptedFileDownloaderFactory):
def __init__(self, peer_finder, rate_limiter, blob_manager, storage, wallet, download_directory): def __init__(self, peer_finder, rate_limiter, blob_manager, storage, wallet, download_directory):
super().__init__(peer_finder, rate_limiter, blob_manager, storage, wallet) super().__init__(peer_finder, rate_limiter, blob_manager, storage, wallet)
self.download_directory = binascii.hexlify(download_directory.encode()) self.download_directory = hexlify(download_directory.encode())
def _make_downloader(self, stream_hash, payment_rate_manager, stream_info): def _make_downloader(self, stream_hash, payment_rate_manager, stream_info):
stream_name = stream_info.raw_info['stream_name'] stream_name = stream_info.raw_info['stream_name']

View file

@ -155,7 +155,7 @@ class TestTransfer(unittest.TestCase):
) )
metadata = yield self.sd_identifier.get_metadata_for_sd_blob(sd_blob) metadata = yield self.sd_identifier.get_metadata_for_sd_blob(sd_blob)
downloader = yield metadata.factories[0].make_downloader( downloader = yield metadata.factories[0].make_downloader(
metadata, self.prm.min_blob_data_payment_rate, self.prm, self.db_dir.encode(), download_mirrors=None metadata, self.prm.min_blob_data_payment_rate, self.prm, self.db_dir, download_mirrors=None
) )
yield downloader.start() yield downloader.start()
with open(os.path.join(self.db_dir, 'test_file'), 'rb') as f: with open(os.path.join(self.db_dir, 'test_file'), 'rb') as f: