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

@ -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

@ -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)

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

@ -106,8 +106,7 @@ class DaemonRequest(server.Request):
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 + "--"

View file

@ -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
} }
@ -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
} }
@ -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

@ -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]
# http://msdn.microsoft.com/en-us/library/windows/desktop/bb762188.aspx
class UserHandle:
current = wintypes.HANDLE(0) current = wintypes.HANDLE(0)
common = wintypes.HANDLE(-1) common = wintypes.HANDLE(-1)
_CoTaskMemFree = windll.ole32.CoTaskMemFree # [4]
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms680722.aspx
_CoTaskMemFree = windll.ole32.CoTaskMemFree
_CoTaskMemFree.restype = None _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) }