def macro_Regulatory(macro): _ = macro.request.getText request = macro.request f = macro.formatter country = request.form.get('alpha2', [None])[0] dbpath = '/tmp/db.txt' if hasattr(request.cfg, 'regdb_path'): dbpath = request.cfg.regdb_path result = [] if request.form.get('raw', [None])[0]: result.append(f.code_area(1, 'db-raw', show=1, start=1, step=1)) for line in open(dbpath): result.extend([ f.code_line(1), f.text(line.rstrip()), f.code_line(0), ]) result.append(f.code_area(0, 'db-raw')) result.append(macro.request.page.link_to(macro.request, 'return to country list')) return ''.join(result) warnings = [] countries = DBParser(warn=lambda x: warnings.append(x)).parse(open(dbpath)) if country: return _country(macro, countries, country) countries = countries.keys() countries = [(_get_iso_code(code), code) for code in countries] countries.sort() result.extend([ f.heading(1, 1), f.text('Countries'), f.heading(0, 1), ]) result.append(f.bullet_list(1)) for name, code in countries: result.extend([ f.listitem(1), request.page.link_to(request, name, querystr={'alpha2': code}), f.listitem(0), ]) result.append(f.bullet_list(0)) if warnings: result.append(f.heading(1, 2)) result.append(f.text("Warnings")) result.append(f.heading(0, 2)) result.append(f.preformatted(1)) result.extend(warnings) result.append(f.preformatted(0)) result.append(request.page.link_to(request, 'view raw database', querystr={'raw': 1})) return ''.join(result)