Merge pull request #247 from lbryio/bad-whitespace

add bad-whitespace check to pylint
This commit is contained in:
Job Evers‐Meltzer 2016-11-09 11:27:45 -06:00 committed by GitHub
commit 37fee71898
16 changed files with 87 additions and 71 deletions

View file

@ -54,7 +54,7 @@ class InvalidStreamDescriptorError(Exception):
class InvalidStreamInfoError(Exception): class InvalidStreamInfoError(Exception):
def __init__(self, name, stream_info): 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) Exception.__init__(self, msg)
self.name = name self.name = name
self.stream_info = stream_info self.stream_info = stream_info

View file

@ -334,18 +334,14 @@ class Wallet(object):
def _log_success(claim_id): def _log_success(claim_id):
log.info("lbry://%s complies with %s, claimid: %s", name, metadata.version, claim_id) log.info("lbry://%s complies with %s, claimid: %s", name, metadata.version, claim_id)
return defer.succeed(None) return defer.succeed(None)
if 'error' in result: if 'error' in result:
log.warning("Got an error looking up a name: %s", result['error']) log.warning("Got an error looking up a name: %s", result['error'])
return Failure(UnknownNameError(name)) return Failure(UnknownNameError(name))
_check_result_fields(result) _check_result_fields(result)
try: try:
metadata = Metadata(json.loads(result['value'])) metadata = Metadata(json.loads(result['value']))
except (TypeError, ValueError, ValidationError): except (TypeError, ValueError, ValidationError):
return Failure(InvalidStreamInfoError(name,result['value'])) return Failure(InvalidStreamInfoError(name, result['value']))
txid = result['txid'] txid = result['txid']
sd_hash = metadata['sources']['lbry_sd_hash'] sd_hash = metadata['sources']['lbry_sd_hash']
d = self._save_name_metadata(name, txid, sd_hash) d = self._save_name_metadata(name, txid, sd_hash)

View file

@ -91,7 +91,7 @@ class CryptStreamBlobMaker(object):
def _write_buffer(self): def _write_buffer(self):
num_bytes_to_encrypt = (len(self.buff) // AES.block_size) * AES.block_size 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) encrypted_data = self.cipher.encrypt(data_to_encrypt)
self.blob.write(encrypted_data) self.blob.write(encrypted_data)
@ -107,3 +107,6 @@ class CryptStreamBlobMaker(object):
def _return_info(self, blob_hash): def _return_info(self, blob_hash):
return CryptBlobInfo(blob_hash, self.blob_num, self.length, binascii.hexlify(self.iv)) return CryptBlobInfo(blob_hash, self.blob_num, self.length, binascii.hexlify(self.iv))
def split(buff, cutoff):
return buff[:cutoff], buff[cutoff:]

View file

@ -590,7 +590,7 @@ class Node(object):
contacts = self._routingTable.findCloseNodes(key, constants.k, rpcSenderID) contacts = self._routingTable.findCloseNodes(key, constants.k, rpcSenderID)
contactTriples = [] contactTriples = []
for contact in contacts: for contact in contacts:
contactTriples.append( (contact.id, contact.address, contact.port) ) contactTriples.append((contact.id, contact.address, contact.port))
return contactTriples return contactTriples
@rpcmethod @rpcmethod

View file

@ -266,7 +266,8 @@ class KademliaProtocol(protocol.DatagramProtocol):
try: try:
##try: ##try:
## # Try to pass the sender's node id to the function... ## # 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: ##except TypeError:
## # ...or simply call it if that fails ## # ...or simply call it if that fails
## result = func(*args) ## result = func(*args)
@ -276,7 +277,7 @@ class KademliaProtocol(protocol.DatagramProtocol):
df.callback(result) df.callback(result)
else: else:
# No such exposed method # 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): def _msgTimeout(self, messageID):
""" Called when an RPC request message times out """ """ Called when an RPC request message times out """

View file

@ -419,4 +419,5 @@ class OptimizedTreeRoutingTable(TreeRoutingTable):
# Replace this stale contact with one from our replacemnent cache, if we have any # Replace this stale contact with one from our replacemnent cache, if we have any
if self._replacementCache.has_key(bucketIndex): if self._replacementCache.has_key(bucketIndex):
if len(self._replacementCache[bucketIndex]) > 0: if len(self._replacementCache[bucketIndex]) > 0:
self._buckets[bucketIndex].addContact( self._replacementCache[bucketIndex].pop() ) self._buckets[bucketIndex].addContact(
self._replacementCache[bucketIndex].pop())

View file

@ -145,7 +145,7 @@ if __name__ == '__main__':
# If you wish to have a pure Kademlia network, use the entangled.kademlia.node.Node class instead # If you wish to have a pure Kademlia network, use the entangled.kademlia.node.Node class instead
print 'Creating Node...' print 'Creating Node...'
#node = EntangledNode( udpPort=int(sys.argv[1]), dataStore=dataStore ) #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) node.joinNetwork(knownNodes)

View file

@ -72,7 +72,7 @@ class Console():
self.lbrycrd_dir = lbrycrd_dir self.lbrycrd_dir = lbrycrd_dir
if not self.lbrycrd_dir: if not self.lbrycrd_dir:
if sys.platform == "darwin": 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: else:
self.lbrycrd_dir = os.path.join(os.path.expanduser("~"), ".lbrycrd") self.lbrycrd_dir = os.path.join(os.path.expanduser("~"), ".lbrycrd")
if not self.lbrycrd_conf: if not self.lbrycrd_conf:

View file

@ -42,7 +42,7 @@ class DaemonRequest(server.Request):
if self.do_log: if self.do_log:
print '%f Request Received' % time.time() print '%f Request Received' % time.time()
self.content.seek(0,0) self.content.seek(0, 0)
self.args = {} self.args = {}
self.stack = [] self.stack = []
@ -74,7 +74,7 @@ class DaemonRequest(server.Request):
args.update(parse_qs(self.content.read(), 1)) args.update(parse_qs(self.content.read(), 1))
elif key == mfd: elif key == mfd:
try: try:
self.content.seek(0,0) self.content.seek(0, 0)
args.update(self.parse_multipart(self.content, pdict)) args.update(self.parse_multipart(self.content, pdict))
#args.update(cgi.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: if self.do_log:
print '%f Parsing Multipart data: ' % time.time() print '%f Parsing Multipart data: ' % time.time()
rewind = fp.tell() #save cursor rewind = fp.tell() #save cursor
fp.seek(0,0) #reset cursor fp.seek(0, 0) #reset cursor
boundary = "" boundary = ""
if 'boundary' in pdict: if 'boundary' in pdict:
boundary = pdict['boundary'] boundary = pdict['boundary']
if not cgi.valid_boundary(boundary): if not cgi.valid_boundary(boundary):
raise ValueError, ('Invalid boundary in multipart form: %r' raise ValueError('Invalid boundary in multipart form: %r' % (boundary,))
% (boundary,))
nextpart = "--" + boundary nextpart = "--" + boundary
lastpart = "--" + boundary + "--" lastpart = "--" + boundary + "--"
@ -175,7 +174,7 @@ class DaemonRequest(server.Request):
else: else:
# Unnamed parts are not returned at all. # Unnamed parts are not returned at all.
continue continue
data.seek(0,0) data.seek(0, 0)
if name in partdict: if name in partdict:
partdict[name].append(data) partdict[name].append(data)
else: else:

View file

@ -33,7 +33,7 @@ class Metadata(StructuredDict):
] ]
def __init__(self, metadata, migrate=True, target_version=None): 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") raise TypeError("metadata is not a dictionary")
starting_version = metadata.get('ver', '0.0.1') starting_version = metadata.get('ver', '0.0.1')

View file

@ -64,9 +64,9 @@ VER_001 = {
}, },
'fee': { 'fee': {
'properties': { 'properties': {
'LBC': { '$ref': '#/definitions/fee_info' }, 'LBC': {'$ref': '#/definitions/fee_info'},
'BTC': { '$ref': '#/definitions/fee_info' }, 'BTC': {'$ref': '#/definitions/fee_info'},
'USD': { '$ref': '#/definitions/fee_info' } 'USD': {'$ref': '#/definitions/fee_info'}
} }
}, },
'contact': { 'contact': {
@ -76,7 +76,8 @@ VER_001 = {
'type': 'string' 'type': 'string'
}, },
}, },
'required': ['title', 'description', 'author', 'language', 'license', 'content-type', 'sources'], 'required': [
'title', 'description', 'author', 'language', 'license', 'content-type', 'sources'],
'additionalProperties': False 'additionalProperties': False
} }
@ -147,9 +148,9 @@ VER_002 = {
}, },
'fee': { 'fee': {
'properties': { 'properties': {
'LBC': { '$ref': '#/definitions/fee_info' }, 'LBC': {'$ref': '#/definitions/fee_info'},
'BTC': { '$ref': '#/definitions/fee_info' }, 'BTC': {'$ref': '#/definitions/fee_info'},
'USD': { '$ref': '#/definitions/fee_info' } 'USD': {'$ref': '#/definitions/fee_info'}
} }
}, },
'contact': { '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 'additionalProperties': False
} }
@ -238,9 +242,9 @@ VER_003 = {
}, },
'fee': { 'fee': {
'properties': { 'properties': {
'LBC': { '$ref': '#/definitions/fee_info' }, 'LBC': {'$ref': '#/definitions/fee_info'},
'BTC': { '$ref': '#/definitions/fee_info' }, 'BTC': {'$ref': '#/definitions/fee_info'},
'USD': { '$ref': '#/definitions/fee_info' } 'USD': {'$ref': '#/definitions/fee_info'}
} }
}, },
'contact': { 'contact': {
@ -260,7 +264,10 @@ VER_003 = {
'type': 'string' '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, 'additionalProperties': False,
'dependencies': { 'dependencies': {
'pubkey': ['sig'], 'pubkey': ['sig'],

View file

@ -88,7 +88,7 @@ class ReflectorServer(Protocol):
else: else:
self.incoming_blob = blob self.incoming_blob = blob
self.blob_finished_d, self.blob_write, self.cancel_write = blob.open_for_writing(self.peer) 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} return {'send_blob': True}
def close_blob(self): def close_blob(self):

View file

@ -3,7 +3,8 @@ import ctypes, sys
from ctypes import windll, wintypes from ctypes import windll, wintypes
from uuid import UUID 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_ = [ _fields_ = [
("Data1", wintypes.DWORD), ("Data1", wintypes.DWORD),
("Data2", wintypes.WORD), ("Data2", wintypes.WORD),
@ -17,7 +18,10 @@ class GUID(ctypes.Structure): # [1]
for i in range(2, 8): for i in range(2, 8):
self.Data4[i] = rest>>(8 - i - 1)*8 & 0xff 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}') AccountPictures = UUID('{008ca0b1-55b4-4c56-b8a8-4de4b299d3be}')
AdminTools = UUID('{724EF170-A42D-4FEF-9F26-B60E846FBA4F}') AdminTools = UUID('{724EF170-A42D-4FEF-9F26-B60E846FBA4F}')
ApplicationShortcuts = UUID('{A3918781-E5F2-4890-B3D9-A7E54332328C}') ApplicationShortcuts = UUID('{A3918781-E5F2-4890-B3D9-A7E54332328C}')
@ -113,20 +117,30 @@ class FOLDERID: # [2]
VideosLibrary = UUID('{491E922F-5643-4AF4-A7EB-4E7A138D8174}') VideosLibrary = UUID('{491E922F-5643-4AF4-A7EB-4E7A138D8174}')
Windows = UUID('{F38BF404-1D43-42F2-9305-67DE0B28FC23}') Windows = UUID('{F38BF404-1D43-42F2-9305-67DE0B28FC23}')
class UserHandle: # [3]
current = wintypes.HANDLE(0)
common = wintypes.HANDLE(-1)
_CoTaskMemFree = windll.ole32.CoTaskMemFree # [4] # http://msdn.microsoft.com/en-us/library/windows/desktop/bb762188.aspx
_CoTaskMemFree.restype= None class UserHandle:
current = wintypes.HANDLE(0)
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] _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 = [ _SHGetKnownFolderPath.argtypes = [
ctypes.POINTER(GUID), wintypes.DWORD, wintypes.HANDLE, ctypes.POINTER(ctypes.c_wchar_p) 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): def get_path(folderid, user_handle=UserHandle.common):
fid = GUID(folderid) fid = GUID(folderid)
@ -138,6 +152,7 @@ def get_path(folderid, user_handle=UserHandle.common):
_CoTaskMemFree(pPath) _CoTaskMemFree(pPath)
return path return path
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) < 2 or sys.argv[1] in ['-?', '/?']: if len(sys.argv) < 2 or sys.argv[1] in ['-?', '/?']:
print('python knownpaths.py FOLDERID {current|common}') print('python knownpaths.py FOLDERID {current|common}')
@ -157,9 +172,3 @@ if __name__ == '__main__':
except PathNotFoundException: except PathNotFoundException:
print('Folder not found "%s"' % ' '.join(sys.argv[1:]), file=sys.stderr) print('Folder not found "%s"' % ' '.join(sys.argv[1:]), file=sys.stderr)
sys.exit(1) 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

View file

@ -64,7 +64,7 @@ pip install pyOpenSSL
pip install pylint pip install pylint
pylint -E --disable=inherit-non-class --disable=no-member --ignored-modules=distutils \ 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 python setup.py install

View file

@ -46,4 +46,4 @@ coveralls
# Ignoring distutils because: https://github.com/PyCQA/pylint/issues/73 # Ignoring distutils because: https://github.com/PyCQA/pylint/issues/73
# TODO: as code quality improves, make pylint be more strict # TODO: as code quality improves, make pylint be more strict
pylint -E --disable=inherit-non-class --disable=no-member --ignored-modules=distutils \ pylint -E --disable=inherit-non-class --disable=no-member --ignored-modules=distutils \
--enable=unused-import lbrynet --enable=unused-import --enable=bad-whitespace lbrynet

View file

@ -2,5 +2,5 @@ C:\Python27\Scripts\pip.exe install mock
C:\Python27\Scripts\pip.exe install pylint C:\Python27\Scripts\pip.exe install pylint
C:\Python27\python.exe C:\Python27\Scripts\trial.py C:\projects\lbry\tests\unit C:\Python27\python.exe C:\Python27\Scripts\trial.py C:\projects\lbry\tests\unit
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } 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) } if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }