# stdnum.wsgi - simple WSGI application to check numbers
#
# Copyright (C) 2017 Arthur de Jong.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
import cgi
import json
import os
import re
import sys
sys.stdout = sys.stderr
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'python-stdnum'))
from stdnum.util import (
get_number_modules, get_module_name, get_module_description)
_template = None
def info(module, number):
compactfn = getattr(module, 'compact', lambda x: x)
formatfn = getattr(module, 'format', compactfn)
return dict(
number=formatfn(number),
compact=compactfn(number),
valid=module.is_valid(number),
module=module.__name__.split('.', 1)[1],
name=get_module_name(module),
description=get_module_description(module))
def format(data):
description = cgi.escape(data['description']).replace('\n\n', '
\n')
description = re.sub(
r'^[*] (.*)$', r'
%s