[Pkg-mozext-commits] [adblock-plus] 51/87: Issue 3952 - Fix whitespaces for compliance with PEP-8
David Prévot
taffit at moszumanska.debian.org
Sat Apr 30 17:59:07 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit e5ec9266ec075d35512ef4fc6f8cff8f550a7fbc
Author: Sebastian Noack <sebastian at adblockplus.org>
Date: Mon Apr 18 19:17:11 2016 +0200
Issue 3952 - Fix whitespaces for compliance with PEP-8
---
addChecksum.py | 53 ++++++++++++++++++++++++++++---------------------
build.py | 10 ++++++----
validateChecksum.py | 57 +++++++++++++++++++++++++++++++----------------------
3 files changed, 70 insertions(+), 50 deletions(-)
diff --git a/addChecksum.py b/addChecksum.py
index 7fabe61..fc29942 100755
--- a/addChecksum.py
+++ b/addChecksum.py
@@ -30,38 +30,47 @@
# #
#############################################################################
-import sys, re, codecs, hashlib, base64
+import sys
+import re
+import codecs
+import hashlib
+import base64
checksumRegexp = re.compile(r'^\s*!\s*checksum[\s\-:]+([\w\+\/=]+).*\n', re.I | re.M)
+
def addChecksum(data):
- checksum = calculateChecksum(data)
- data = re.sub(checksumRegexp, '', data)
- data = re.sub(r'(\r?\n)', r'\1! Checksum: %s\1' % checksum, data, 1)
- return data
+ checksum = calculateChecksum(data)
+ data = re.sub(checksumRegexp, '', data)
+ data = re.sub(r'(\r?\n)', r'\1! Checksum: %s\1' % checksum, data, 1)
+ return data
+
def calculateChecksum(data):
- md5 = hashlib.md5()
- md5.update(normalize(data).encode('utf-8'))
- return base64.b64encode(md5.digest()).rstrip('=')
+ md5 = hashlib.md5()
+ md5.update(normalize(data).encode('utf-8'))
+ return base64.b64encode(md5.digest()).rstrip('=')
+
def normalize(data):
- data = re.sub(r'\r', '', data)
- data = re.sub(r'\n+', '\n', data)
- data = re.sub(checksumRegexp, '', data)
- return data
+ data = re.sub(r'\r', '', data)
+ data = re.sub(r'\n+', '\n', data)
+ data = re.sub(checksumRegexp, '', data)
+ return data
+
def readStream(stream):
- reader = codecs.getreader('utf8')(stream)
- try:
- return reader.read()
- except Exception, e:
- raise Exception('Failed reading data, most likely not encoded as UTF-8:\n%s' % e)
+ reader = codecs.getreader('utf8')(stream)
+ try:
+ return reader.read()
+ except Exception, e:
+ raise Exception('Failed reading data, most likely not encoded as UTF-8:\n%s' % e)
if __name__ == '__main__':
- if sys.platform == "win32":
- import os, msvcrt
- msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
+ if sys.platform == "win32":
+ import os
+ import msvcrt
+ msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
- data = addChecksum(readStream(sys.stdin))
- sys.stdout.write(data.encode('utf-8'))
+ data = addChecksum(readStream(sys.stdin))
+ sys.stdout.write(data.encode('utf-8'))
diff --git a/build.py b/build.py
index cca908e..8501ed1 100755
--- a/build.py
+++ b/build.py
@@ -1,16 +1,18 @@
#!/usr/bin/env python
# coding: utf-8
-import os, sys, subprocess
+import os
+import sys
+import subprocess
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DEPENDENCY_SCRIPT = os.path.join(BASE_DIR, "ensure_dependencies.py")
try:
- subprocess.check_call([sys.executable, DEPENDENCY_SCRIPT, BASE_DIR])
+ subprocess.check_call([sys.executable, DEPENDENCY_SCRIPT, BASE_DIR])
except subprocess.CalledProcessError as e:
- print >>sys.stderr, e
- print >>sys.stderr, "Failed to ensure dependencies being up-to-date!"
+ print >>sys.stderr, e
+ print >>sys.stderr, "Failed to ensure dependencies being up-to-date!"
import buildtools.build
buildtools.build.processArgs(BASE_DIR, sys.argv)
diff --git a/validateChecksum.py b/validateChecksum.py
index 844be9b..88d6345 100755
--- a/validateChecksum.py
+++ b/validateChecksum.py
@@ -30,42 +30,51 @@
# #
#############################################################################
-import sys, re, codecs, hashlib, base64
+import sys
+import re
+import codecs
+import hashlib
+import base64
checksumRegexp = re.compile(r'^\s*!\s*checksum[\s\-:]+([\w\+\/=]+).*\n', re.I | re.M)
+
def validate(data):
- checksum = extractChecksum(data)
- if not checksum:
- raise Exception('Data doesn\'t contain a checksum, nothing to validate')
+ checksum = extractChecksum(data)
+ if not checksum:
+ raise Exception('Data doesn\'t contain a checksum, nothing to validate')
+
+ expectedChecksum = calculateChecksum(data)
+ if checksum == expectedChecksum:
+ print 'Checksum is valid'
+ else:
+ print 'Wrong checksum: found %s, expected %s' % (checksum, expectedChecksum)
- expectedChecksum = calculateChecksum(data)
- if checksum == expectedChecksum:
- print 'Checksum is valid'
- else:
- print 'Wrong checksum: found %s, expected %s' % (checksum, expectedChecksum)
def extractChecksum(data):
- match = re.search(checksumRegexp, data)
- return match.group(1) if match else None
+ match = re.search(checksumRegexp, data)
+ return match.group(1) if match else None
+
def calculateChecksum(data):
- md5 = hashlib.md5()
- md5.update(normalize(data).encode('utf-8'))
- return base64.b64encode(md5.digest()).rstrip('=')
+ md5 = hashlib.md5()
+ md5.update(normalize(data).encode('utf-8'))
+ return base64.b64encode(md5.digest()).rstrip('=')
+
def normalize(data):
- data = re.sub(r'\r', '', data)
- data = re.sub(r'\n+', '\n', data)
- data = re.sub(checksumRegexp, '', data)
- return data
+ data = re.sub(r'\r', '', data)
+ data = re.sub(r'\n+', '\n', data)
+ data = re.sub(checksumRegexp, '', data)
+ return data
+
def readStream(stream):
- reader = codecs.getreader('utf8')(stream)
- try:
- return reader.read()
- except Exception, e:
- raise Exception('Failed reading data, most likely not encoded as UTF-8:\n%s' % e)
+ reader = codecs.getreader('utf8')(stream)
+ try:
+ return reader.read()
+ except Exception, e:
+ raise Exception('Failed reading data, most likely not encoded as UTF-8:\n%s' % e)
if __name__ == '__main__':
- validate(readStream(sys.stdin))
+ validate(readStream(sys.stdin))
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git
More information about the Pkg-mozext-commits
mailing list