+# Title string normalization
+def title_string_norm(title):
+ title = title.lower()
+ title = map(lambda x: x in string.whitespace and '_' or x, title)
+ title = filter(lambda x: x in string.lowercase or x in string.digits or x == '_', title)
+ return ''.join(title)
+
+# Generic download step
+def download_step(return_data_flag, step_title, step_error, url, post_data=None):
+ try:
+ cond_print('%s... ' % step_title)
+ data = perform_request(url, post_data).read()
+ cond_print('done.\n')
+ if return_data_flag:
+ return data
+ return None
+
+ except (urllib2.URLError, ValueError, httplib.HTTPException, TypeError):
+ cond_print('failed.\n')
+ error_advice_exit(step_error)
+
+ except KeyboardInterrupt:
+ sys.exit('\n')
+
+# Generic extract step
+def extract_step(step_title, step_error, regexp, data):
+ try:
+ cond_print('%s... ' % step_title)
+ match = regexp.search(data)
+
+ if match is None:
+ cond_print('failed.\n')
+ error_advice_exit(step_error)
+
+ extracted_data = match.group(1)
+ cond_print('done.\n')
+ return extracted_data
+
+ except KeyboardInterrupt:
+ sys.exit('\n')
+