summaryrefslogtreecommitdiff
path: root/scripts/make_errorcodes.py
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2016-10-11 00:10:53 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2016-10-11 00:11:55 +0100
commit91d2158de7954daccb0a22885021c8416d1d5c6c (patch)
tree0c6d537c377ee095d7d4d451477931d7a310dd11 /scripts/make_errorcodes.py
parent4458c9b4c94e524237fb39c7821b248fc2a85e35 (diff)
downloadpsycopg2-91d2158de7954daccb0a22885021c8416d1d5c6c.tar.gz
Python source cleanup using flake8
Diffstat (limited to 'scripts/make_errorcodes.py')
-rwxr-xr-xscripts/make_errorcodes.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/scripts/make_errorcodes.py b/scripts/make_errorcodes.py
index 58d05b8..26f7e68 100755
--- a/scripts/make_errorcodes.py
+++ b/scripts/make_errorcodes.py
@@ -23,6 +23,7 @@ from collections import defaultdict
from BeautifulSoup import BeautifulSoup as BS
+
def main():
if len(sys.argv) != 2:
print >>sys.stderr, "usage: %s /path/to/errorcodes.py" % sys.argv[0]
@@ -41,6 +42,7 @@ def main():
for line in generate_module_data(classes, errors):
print >>f, line
+
def read_base_file(filename):
rv = []
for line in open(filename):
@@ -50,6 +52,7 @@ def read_base_file(filename):
raise ValueError("can't find the separator. Is this the right file?")
+
def parse_errors_txt(url):
classes = {}
errors = defaultdict(dict)
@@ -84,6 +87,7 @@ def parse_errors_txt(url):
return classes, errors
+
def parse_errors_sgml(url):
page = BS(urllib2.urlopen(url))
table = page('table')[1]('tbody')[0]
@@ -92,7 +96,7 @@ def parse_errors_sgml(url):
errors = defaultdict(dict)
for tr in table('tr'):
- if tr.td.get('colspan'): # it's a class
+ if tr.td.get('colspan'): # it's a class
label = ' '.join(' '.join(tr(text=True)).split()) \
.replace(u'\u2014', '-').encode('ascii')
assert label.startswith('Class')
@@ -100,7 +104,7 @@ def parse_errors_sgml(url):
assert len(class_) == 2
classes[class_] = label
- else: # it's an error
+ else: # it's an error
errcode = tr.tt.string.encode("ascii")
assert len(errcode) == 5
@@ -124,11 +128,12 @@ def parse_errors_sgml(url):
return classes, errors
errors_sgml_url = \
- "http://www.postgresql.org/docs/%s/static/errcodes-appendix.html"
+ "http://www.postgresql.org/docs/%s/static/errcodes-appendix.html"
errors_txt_url = \
- "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;" \
- "f=src/backend/utils/errcodes.txt;hb=REL%s_STABLE"
+ "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;" \
+ "f=src/backend/utils/errcodes.txt;hb=REL%s_STABLE"
+
def fetch_errors(versions):
classes = {}
@@ -148,14 +153,15 @@ def fetch_errors(versions):
return classes, errors
+
def generate_module_data(classes, errors):
yield ""
yield "# Error classes"
for clscode, clslabel in sorted(classes.items()):
err = clslabel.split(" - ")[1].split("(")[0] \
- .strip().replace(" ", "_").replace('/', "_").upper()
+ .strip().replace(" ", "_").replace('/', "_").upper()
yield "CLASS_%s = %r" % (err, clscode)
-
+
for clscode, clslabel in sorted(classes.items()):
yield ""
yield "# %s" % clslabel
@@ -163,7 +169,6 @@ def generate_module_data(classes, errors):
for errcode, errlabel in sorted(errors[clscode].items()):
yield "%s = %r" % (errlabel, errcode)
+
if __name__ == '__main__':
sys.exit(main())
-
-