diff --git a/lbrynet/core/Error.py b/lbrynet/core/Error.py index 7bade2561..231f3580f 100644 --- a/lbrynet/core/Error.py +++ b/lbrynet/core/Error.py @@ -54,7 +54,7 @@ class InvalidStreamDescriptorError(Exception): class InvalidStreamInfoError(Exception): def __init__(self, name, stream_info): - msg = '{} has claim with invalid stream info: {}'.format(name, stream_info) + msg = '{} has claim with invalid stream info: {}'.format(name, stream_info) Exception.__init__(self, msg) self.name = name self.stream_info = stream_info diff --git a/lbrynet/core/Wallet.py b/lbrynet/core/Wallet.py index 1e3f72567..e611fec4c 100644 --- a/lbrynet/core/Wallet.py +++ b/lbrynet/core/Wallet.py @@ -330,22 +330,18 @@ class Wallet(object): def _check_result_fields(r): for k in ['value', 'txid', 'n', 'height', 'amount']: assert k in r, "getvalueforname response missing field %s" % k - + def _log_success(claim_id): log.info("lbry://%s complies with %s, claimid: %s", name, metadata.version, claim_id) return defer.succeed(None) - if 'error' in result: log.warning("Got an error looking up a name: %s", result['error']) return Failure(UnknownNameError(name)) - _check_result_fields(result) - try: - metadata = Metadata(json.loads(result['value'])) + metadata = Metadata(json.loads(result['value'])) except (TypeError, ValueError, ValidationError): - return Failure(InvalidStreamInfoError(name,result['value'])) - + return Failure(InvalidStreamInfoError(name, result['value'])) txid = result['txid'] sd_hash = metadata['sources']['lbry_sd_hash'] d = self._save_name_metadata(name, txid, sd_hash) diff --git a/lbrynet/cryptstream/CryptBlob.py b/lbrynet/cryptstream/CryptBlob.py index da94f631b..2918d7898 100644 --- a/lbrynet/cryptstream/CryptBlob.py +++ b/lbrynet/cryptstream/CryptBlob.py @@ -91,7 +91,7 @@ class CryptStreamBlobMaker(object): def _write_buffer(self): num_bytes_to_encrypt = (len(self.buff) // AES.block_size) * AES.block_size - data_to_encrypt, self.buff = self.buff[:num_bytes_to_encrypt], self.buff[num_bytes_to_encrypt:] + data_to_encrypt, self.buff = split(self.buff, num_bytes_to_encrypt) encrypted_data = self.cipher.encrypt(data_to_encrypt) self.blob.write(encrypted_data) @@ -106,4 +106,7 @@ class CryptStreamBlobMaker(object): self.blob.write(encrypted_data) def _return_info(self, blob_hash): - return CryptBlobInfo(blob_hash, self.blob_num, self.length, binascii.hexlify(self.iv)) \ No newline at end of file + return CryptBlobInfo(blob_hash, self.blob_num, self.length, binascii.hexlify(self.iv)) + +def split(buff, cutoff): + return buff[:cutoff], buff[cutoff:] diff --git a/lbrynet/dht/node.py b/lbrynet/dht/node.py index 053f46f27..3b49cd167 100644 --- a/lbrynet/dht/node.py +++ b/lbrynet/dht/node.py @@ -572,7 +572,7 @@ class Node(object): def findNode(self, key, **kwargs): """ Finds a number of known nodes closest to the node/value with the specified key. - + @param key: the n-bit key (i.e. the node or value ID) to search for @type key: str @@ -590,17 +590,17 @@ class Node(object): contacts = self._routingTable.findCloseNodes(key, constants.k, rpcSenderID) contactTriples = [] for contact in contacts: - contactTriples.append( (contact.id, contact.address, contact.port) ) + contactTriples.append((contact.id, contact.address, contact.port)) return contactTriples @rpcmethod def findValue(self, key, **kwargs): """ Return the value associated with the specified key if present in this node's data, otherwise execute FIND_NODE for the key - + @param key: The hashtable key of the data to return @type key: str - + @return: A dictionary containing the requested key/value pair, or a list of contact triples closest to the requested key. @rtype: dict or list diff --git a/lbrynet/dht/protocol.py b/lbrynet/dht/protocol.py index 8eae3bc0e..37c855c50 100644 --- a/lbrynet/dht/protocol.py +++ b/lbrynet/dht/protocol.py @@ -266,7 +266,8 @@ class KademliaProtocol(protocol.DatagramProtocol): try: ##try: ## # Try to pass the sender's node id to the function... - result = func(*args, **{'_rpcNodeID': senderContact.id, '_rpcNodeContact': senderContact}) + kwargs = {'_rpcNodeID': senderContact.id, '_rpcNodeContact': senderContact} + result = func(*args, **kwargs) ##except TypeError: ## # ...or simply call it if that fails ## result = func(*args) @@ -276,7 +277,7 @@ class KademliaProtocol(protocol.DatagramProtocol): df.callback(result) else: # No such exposed method - df.errback( failure.Failure( AttributeError('Invalid method: %s' % method) ) ) + df.errback(failure.Failure(AttributeError('Invalid method: %s' % method))) def _msgTimeout(self, messageID): """ Called when an RPC request message times out """ diff --git a/lbrynet/dht/routingtable.py b/lbrynet/dht/routingtable.py index 0a237cea9..07833413a 100644 --- a/lbrynet/dht/routingtable.py +++ b/lbrynet/dht/routingtable.py @@ -419,4 +419,5 @@ class OptimizedTreeRoutingTable(TreeRoutingTable): # Replace this stale contact with one from our replacemnent cache, if we have any if self._replacementCache.has_key(bucketIndex): if len(self._replacementCache[bucketIndex]) > 0: - self._buckets[bucketIndex].addContact( self._replacementCache[bucketIndex].pop() ) + self._buckets[bucketIndex].addContact( + self._replacementCache[bucketIndex].pop()) diff --git a/lbrynet/dhttest.py b/lbrynet/dhttest.py index 3aa85434f..0efca9e2a 100644 --- a/lbrynet/dhttest.py +++ b/lbrynet/dhttest.py @@ -145,9 +145,9 @@ if __name__ == '__main__': # If you wish to have a pure Kademlia network, use the entangled.kademlia.node.Node class instead print 'Creating Node...' #node = EntangledNode( udpPort=int(sys.argv[1]), dataStore=dataStore ) - node = Node( udpPort=int(sys.argv[1]), lbryid=lbryid) + node = Node(udpPort=int(sys.argv[1]), lbryid=lbryid) - # Schedule the node to join the Kademlia/Entangled DHT + # Schedule the node to join the Kademlia/Entangled DHT node.joinNetwork(knownNodes) # Schedule the "storeValue() call to be invoked after 2.5 seconds, using KEY and VALUE as arguments #twisted.internet.reactor.callLater(2.5, storeValue, KEY, VALUE) diff --git a/lbrynet/lbrynet_console/Console.py b/lbrynet/lbrynet_console/Console.py index ab0841a8b..7a67c7409 100644 --- a/lbrynet/lbrynet_console/Console.py +++ b/lbrynet/lbrynet_console/Console.py @@ -72,7 +72,7 @@ class Console(): self.lbrycrd_dir = lbrycrd_dir if not self.lbrycrd_dir: if sys.platform == "darwin": - self.lbrycrd_dir = os.path.join(os.path.expanduser("~"), "Library/Application Support/lbrycrd") + self.lbrycrd_dir = os.path.join(os.path.expanduser("~"), "Library/Application Support/lbrycrd") else: self.lbrycrd_dir = os.path.join(os.path.expanduser("~"), ".lbrycrd") if not self.lbrycrd_conf: diff --git a/lbrynet/lbrynet_daemon/DaemonRequest.py b/lbrynet/lbrynet_daemon/DaemonRequest.py index dbfa45303..9eb080876 100644 --- a/lbrynet/lbrynet_daemon/DaemonRequest.py +++ b/lbrynet/lbrynet_daemon/DaemonRequest.py @@ -42,7 +42,7 @@ class DaemonRequest(server.Request): if self.do_log: print '%f Request Received' % time.time() - self.content.seek(0,0) + self.content.seek(0, 0) self.args = {} self.stack = [] @@ -74,7 +74,7 @@ class DaemonRequest(server.Request): args.update(parse_qs(self.content.read(), 1)) elif key == mfd: try: - self.content.seek(0,0) + self.content.seek(0, 0) args.update(self.parse_multipart(self.content, pdict)) #args.update(cgi.parse_multipart(self.content, pdict)) @@ -100,14 +100,13 @@ class DaemonRequest(server.Request): if self.do_log: print '%f Parsing Multipart data: ' % time.time() rewind = fp.tell() #save cursor - fp.seek(0,0) #reset cursor + fp.seek(0, 0) #reset cursor boundary = "" if 'boundary' in pdict: boundary = pdict['boundary'] if not cgi.valid_boundary(boundary): - raise ValueError, ('Invalid boundary in multipart form: %r' - % (boundary,)) + raise ValueError('Invalid boundary in multipart form: %r' % (boundary,)) nextpart = "--" + boundary lastpart = "--" + boundary + "--" @@ -175,7 +174,7 @@ class DaemonRequest(server.Request): else: # Unnamed parts are not returned at all. continue - data.seek(0,0) + data.seek(0, 0) if name in partdict: partdict[name].append(data) else: diff --git a/lbrynet/metadata/Metadata.py b/lbrynet/metadata/Metadata.py index a078d1f01..1af4b2d6f 100644 --- a/lbrynet/metadata/Metadata.py +++ b/lbrynet/metadata/Metadata.py @@ -33,7 +33,7 @@ class Metadata(StructuredDict): ] def __init__(self, metadata, migrate=True, target_version=None): - if not isinstance(metadata,dict): + if not isinstance(metadata, dict): raise TypeError("metadata is not a dictionary") starting_version = metadata.get('ver', '0.0.1') diff --git a/lbrynet/metadata/metadata_schemas.py b/lbrynet/metadata/metadata_schemas.py index 2f66a3c74..6165ccaa6 100644 --- a/lbrynet/metadata/metadata_schemas.py +++ b/lbrynet/metadata/metadata_schemas.py @@ -64,9 +64,9 @@ VER_001 = { }, 'fee': { 'properties': { - 'LBC': { '$ref': '#/definitions/fee_info' }, - 'BTC': { '$ref': '#/definitions/fee_info' }, - 'USD': { '$ref': '#/definitions/fee_info' } + 'LBC': {'$ref': '#/definitions/fee_info'}, + 'BTC': {'$ref': '#/definitions/fee_info'}, + 'USD': {'$ref': '#/definitions/fee_info'} } }, 'contact': { @@ -76,7 +76,8 @@ VER_001 = { 'type': 'string' }, }, - 'required': ['title', 'description', 'author', 'language', 'license', 'content-type', 'sources'], + 'required': [ + 'title', 'description', 'author', 'language', 'license', 'content-type', 'sources'], 'additionalProperties': False } @@ -147,9 +148,9 @@ VER_002 = { }, 'fee': { 'properties': { - 'LBC': { '$ref': '#/definitions/fee_info' }, - 'BTC': { '$ref': '#/definitions/fee_info' }, - 'USD': { '$ref': '#/definitions/fee_info' } + 'LBC': {'$ref': '#/definitions/fee_info'}, + 'BTC': {'$ref': '#/definitions/fee_info'}, + 'USD': {'$ref': '#/definitions/fee_info'} } }, 'contact': { @@ -167,7 +168,10 @@ VER_002 = { }, }, - 'required': ['ver', 'title', 'description', 'author', 'language', 'license', 'content-type', 'sources', 'nsfw'], + 'required': [ + 'ver', 'title', 'description', 'author', 'language', 'license', + 'content-type', 'sources', 'nsfw' + ], 'additionalProperties': False } @@ -238,9 +242,9 @@ VER_003 = { }, 'fee': { 'properties': { - 'LBC': { '$ref': '#/definitions/fee_info' }, - 'BTC': { '$ref': '#/definitions/fee_info' }, - 'USD': { '$ref': '#/definitions/fee_info' } + 'LBC': {'$ref': '#/definitions/fee_info'}, + 'BTC': {'$ref': '#/definitions/fee_info'}, + 'USD': {'$ref': '#/definitions/fee_info'} } }, 'contact': { @@ -260,7 +264,10 @@ VER_003 = { 'type': 'string' } }, - 'required': ['ver', 'title', 'description', 'author', 'language', 'license', 'content_type', 'sources', 'nsfw'], + 'required': [ + 'ver', 'title', 'description', 'author', 'language', 'license', + 'content_type', 'sources', 'nsfw' + ], 'additionalProperties': False, 'dependencies': { 'pubkey': ['sig'], diff --git a/lbrynet/reflector/server/server.py b/lbrynet/reflector/server/server.py index d1b04407e..2251b6db6 100644 --- a/lbrynet/reflector/server/server.py +++ b/lbrynet/reflector/server/server.py @@ -88,7 +88,7 @@ class ReflectorServer(Protocol): else: self.incoming_blob = blob self.blob_finished_d, self.blob_write, self.cancel_write = blob.open_for_writing(self.peer) - self.blob_finished_d.addCallback(lambda _ :self.blob_manager.blob_completed(blob)) + self.blob_finished_d.addCallback(lambda _: self.blob_manager.blob_completed(blob)) return {'send_blob': True} def close_blob(self): diff --git a/lbrynet/winhelpers/knownpaths.py b/lbrynet/winhelpers/knownpaths.py index 267e5eb7f..04deb4288 100644 --- a/lbrynet/winhelpers/knownpaths.py +++ b/lbrynet/winhelpers/knownpaths.py @@ -2,22 +2,26 @@ from __future__ import print_function import ctypes, sys from ctypes import windll, wintypes from uuid import UUID - -class GUID(ctypes.Structure): # [1] + +# http://msdn.microsoft.com/en-us/library/windows/desktop/aa373931.aspx +class GUID(ctypes.Structure): _fields_ = [ ("Data1", wintypes.DWORD), ("Data2", wintypes.WORD), ("Data3", wintypes.WORD), ("Data4", wintypes.BYTE * 8) - ] - + ] + def __init__(self, uuid_): ctypes.Structure.__init__(self) self.Data1, self.Data2, self.Data3, self.Data4[0], self.Data4[1], rest = uuid_.fields for i in range(2, 8): self.Data4[i] = rest>>(8 - i - 1)*8 & 0xff - -class FOLDERID: # [2] + + +# http://msdn.microsoft.com/en-us/library/windows/desktop/dd378457.aspx +class FOLDERID: + # pylint: disable=bad-whitespace AccountPictures = UUID('{008ca0b1-55b4-4c56-b8a8-4de4b299d3be}') AdminTools = UUID('{724EF170-A42D-4FEF-9F26-B60E846FBA4F}') ApplicationShortcuts = UUID('{A3918781-E5F2-4890-B3D9-A7E54332328C}') @@ -112,24 +116,34 @@ class FOLDERID: # [2] Videos = UUID('{18989B1D-99B5-455B-841C-AB7C74E4DDFC}') VideosLibrary = UUID('{491E922F-5643-4AF4-A7EB-4E7A138D8174}') Windows = UUID('{F38BF404-1D43-42F2-9305-67DE0B28FC23}') - -class UserHandle: # [3] + + +# http://msdn.microsoft.com/en-us/library/windows/desktop/bb762188.aspx +class UserHandle: current = wintypes.HANDLE(0) - common = wintypes.HANDLE(-1) - -_CoTaskMemFree = windll.ole32.CoTaskMemFree # [4] -_CoTaskMemFree.restype= None + common = wintypes.HANDLE(-1) + + +# http://msdn.microsoft.com/en-us/library/windows/desktop/ms680722.aspx +_CoTaskMemFree = windll.ole32.CoTaskMemFree +_CoTaskMemFree.restype = None _CoTaskMemFree.argtypes = [ctypes.c_void_p] - -_SHGetKnownFolderPath = windll.shell32.SHGetKnownFolderPath # [5] [3] + + +# http://msdn.microsoft.com/en-us/library/windows/desktop/bb762188.aspx +# http://www.themacaque.com/?p=954 +_SHGetKnownFolderPath = windll.shell32.SHGetKnownFolderPath _SHGetKnownFolderPath.argtypes = [ ctypes.POINTER(GUID), wintypes.DWORD, wintypes.HANDLE, ctypes.POINTER(ctypes.c_wchar_p) -] - -class PathNotFoundException(Exception): pass - +] + + +class PathNotFoundException(Exception): + pass + + def get_path(folderid, user_handle=UserHandle.common): - fid = GUID(folderid) + fid = GUID(folderid) pPath = ctypes.c_wchar_p() S_OK = 0 if _SHGetKnownFolderPath(ctypes.byref(fid), 0, user_handle, ctypes.byref(pPath)) != S_OK: @@ -137,18 +151,19 @@ def get_path(folderid, user_handle=UserHandle.common): path = pPath.value _CoTaskMemFree(pPath) return path - + + if __name__ == '__main__': if len(sys.argv) < 2 or sys.argv[1] in ['-?', '/?']: print('python knownpaths.py FOLDERID {current|common}') sys.exit(0) - + try: folderid = getattr(FOLDERID, sys.argv[1]) except AttributeError: print('Unknown folder id "%s"' % sys.argv[1], file=sys.stderr) sys.exit(1) - + try: if len(sys.argv) == 2: print(get_path(folderid)) @@ -157,9 +172,3 @@ if __name__ == '__main__': except PathNotFoundException: print('Folder not found "%s"' % ' '.join(sys.argv[1:]), file=sys.stderr) sys.exit(1) - -# [1] http://msdn.microsoft.com/en-us/library/windows/desktop/aa373931.aspx -# [2] http://msdn.microsoft.com/en-us/library/windows/desktop/dd378457.aspx -# [3] http://msdn.microsoft.com/en-us/library/windows/desktop/bb762188.aspx -# [4] http://msdn.microsoft.com/en-us/library/windows/desktop/ms680722.aspx -# [5] http://www.themacaque.com/?p=954 diff --git a/packaging/osx/lbry-osx-app/setup_app.sh b/packaging/osx/lbry-osx-app/setup_app.sh index 5fe6861a6..69bed5f3e 100755 --- a/packaging/osx/lbry-osx-app/setup_app.sh +++ b/packaging/osx/lbry-osx-app/setup_app.sh @@ -64,7 +64,7 @@ pip install pyOpenSSL pip install pylint pylint -E --disable=inherit-non-class --disable=no-member --ignored-modules=distutils \ - --enable=unused-import lbrynet packaging/osx/lbry-osx-app/lbrygui/ + --enable=unused-import --enable=bad-whitespace lbrynet packaging/osx/lbry-osx-app/lbrygui/ python setup.py install diff --git a/packaging/travis/install_dependencies_and_run_tests.sh b/packaging/travis/install_dependencies_and_run_tests.sh index ff1326af9..f2e5fac66 100755 --- a/packaging/travis/install_dependencies_and_run_tests.sh +++ b/packaging/travis/install_dependencies_and_run_tests.sh @@ -46,4 +46,4 @@ coveralls # Ignoring distutils because: https://github.com/PyCQA/pylint/issues/73 # TODO: as code quality improves, make pylint be more strict pylint -E --disable=inherit-non-class --disable=no-member --ignored-modules=distutils \ - --enable=unused-import lbrynet + --enable=unused-import --enable=bad-whitespace lbrynet diff --git a/packaging/windows/test.ps1 b/packaging/windows/test.ps1 index a6f317694..29534d8a0 100644 --- a/packaging/windows/test.ps1 +++ b/packaging/windows/test.ps1 @@ -2,5 +2,5 @@ C:\Python27\Scripts\pip.exe install mock C:\Python27\Scripts\pip.exe install pylint C:\Python27\python.exe C:\Python27\Scripts\trial.py C:\projects\lbry\tests\unit if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } -C:\Python27\Scripts\pylint.exe -E --disable=inherit-non-class --disable=no-member --ignored-modules=distutils --enable=unused-import lbrynet packaging/windows/lbry-win32-app/LBRYWin32App.py +C:\Python27\Scripts\pylint.exe -E --disable=inherit-non-class --disable=no-member --ignored-modules=distutils --enable=unused-import --enable=bad-whitespace lbrynet packaging/windows/lbry-win32-app/LBRYWin32App.py if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }