# Path: opentaxforms/config.py
# def parseCmdline():
# def getFileList(dirName):
# def setLogname(rootForms,cfg):
# def copyStaticDir(appname):
# def setupStaticDir(dirName):
# def setup(**overrideArgs):
# def unsetup():
# 
# Path: opentaxforms/irs.py
# def computeTitle(prefix, form = None):
#     '''
#     >>> computeTitle('f1040')
#     'Form 1040'
#     >>> computeTitle('f1040se')
#     'Form 1040 Schedule E'
#     >>> computeTitle('f1040ez')
#     'Form 1040EZ'
#     '''
#     m = re.match(r'(\w)(\d+)([^s].*)?(?:s(\w))?$', prefix)
#     if m:
#         typ, num, suffix, sched = m.groups()
#         suffix = suffix or ''
#         if typ == 'f':
#             doctype = 'Form'
#         else:
#             # todo temporary fallback for CRA forms
#             #raise Exception('unknown doctype [%s]' % (typ, ))
#             return form.docinfo['titl']
#         if suffix:
#             num += suffix.upper()  # .upper for eg 1040EZ
#         titleEls = [doctype, num]
#         if sched:
#             titleEls.extend(['Schedule', sched.upper()])
#         title = ' '.join(el for el in titleEls if el)
#     else:
#         title = prefix.capitalize()
#     return title
# 
# def computeFormId(formName):
#     '''
#         >>> computeFormId('1040')
#         '1040'
#         >>> computeFormId(('1040','SE'))
#         '1040sSE'
#         '''
#     try:
#         form, sched = formName
#         if sched is None:
#             idd = form
#         else:
#             idd = form + 's' + sched
#     except ValueError:
#         idd = formName
#     return idd
# 
# def sortableFieldname(fieldname):
#     '''
#         to avoid lexicographic malordering: f1_19,f1_2,f1_20
#         >>> sortableFieldname('f1_43_L0T')
#         ['f', 1, '_', 43, '_L', 0, 'T']
#         '''
# 
#     def intify(s):
#         try:
#             return int(s)
#         except ValueError:
#             return s
#     try:
#         segs = re.findall('(\D+|\d+)', fieldname)
#         segs = [intify(seg) for seg in segs]
#         return segs
#     except Exception:
#         excclass, exc, tb = sys.exc_info()
#         new_exc = Exception(
#             'sortableFieldname: new exception: fieldname= ' + fieldname)
#         raise new_exc.__class__(new_exc).with_traceback(tb)
# 
# Path: opentaxforms/ut.py
# NL = '\n'
# TAB = '\t'
# def merge(bb1, bb2):
# def numerify(s):
# def compactify(multilineRegex):
#     def crunch(seg):
# def pickle(data, pickleFilePrefix):
# def unpickle(pickleFilePrefix, default=None):
# def flattened(l):
# def hasdups(l, key=None):
# def uniqify(l):
# def uniqify2(l):
# def setupLogging(loggerId, args=None):
# def unsetupLogging():
# def logg(msg, outputs=None):
# def jj(*args, **kw):
# def jdb(*args, **kw):
# def run0(cmd):
# def run(cmd, logprefix='run', loglevel='INFO'):
#     def __init__(self, pkgname, fpath=None):
#     def path(self):
#     def content(self):
#     def keys(cls):
#     def vals(cls):
#     def items(cls):
#     def __init__(self):
#     def __call__(self, **kw):
#     def __init__(self, *maps, **kw):
#     def _getGetitems(self, mapp):
#     def __getitem__(self, key):
#     def __setitem__(self, key, val):
#     def __len__(self):
#     def __call__(self, *keys):
#     def clear(self):
#     def update(self, *maps):
#     def __add__(self, *maps):
#     def __iadd__(self, *maps):
#     def __iter__(self):
#     def iterkeys(self):
#     def keys(self):
#     def values(self):
#     def items(self):
#     def iteritems(self):
#     def get(self, key, dflt=None):
#     def __str__(self):
#     def __repr__(self):
# def notequalpatch(self, o):
#     def fromstring(cls, s):
#     def __hash__(self):
# def playQnty():
# def nth(n):
# def skip(s, substr):
# def until(s, substr):
# def ensure_dir(folder):
# def now(format=None):
# def readImgSize(fname, dirName):
# def asciiOnly(s):
# class NoSuchPickle(Exception):
# class PickleException(Exception):
# class Resource(object):
# class CharEnum(object):
# class ChainablyUpdatableOrderedDict(odict):
# class Bag(object):
# class Qnty(qq):


import os.path
import re
import traceback
        import doctest
from os import remove as removeFile
from itertools import chain
from . import ut
from .config import cfg, setup
from .irs import computeTitle, computeFormId, sortableFieldname
from .ut import log, jdb, Qnty, NL, pathjoin
    from PIL import Image
from __future__ import print_function, absolute_import



def computeFormFilename(form):
    try:
        # form may be eg ('1040','A')
        form, sched = form
        if sched is not None:
            form = '%ss%s' % (form, sched)

# Path: opentaxforms/config.py
# def parseCmdline():
# def getFileList(dirName):
# def setLogname(rootForms,cfg):
# def copyStaticDir(appname):
# def setupStaticDir(dirName):
# def setup(**overrideArgs):
# def unsetup():
# 
# Path: opentaxforms/irs.py
# def computeTitle(prefix, form = None):
#     '''
#     >>> computeTitle('f1040')
#     'Form 1040'
#     >>> computeTitle('f1040se')
#     'Form 1040 Schedule E'
#     >>> computeTitle('f1040ez')
#     'Form 1040EZ'
#     '''
#     m = re.match(r'(\w)(\d+)([^s].*)?(?:s(\w))?$', prefix)
#     if m:
#         typ, num, suffix, sched = m.groups()
#         suffix = suffix or ''
#         if typ == 'f':
#             doctype = 'Form'
#         else:
#             # todo temporary fallback for CRA forms
#             #raise Exception('unknown doctype [%s]' % (typ, ))
#             return form.docinfo['titl']
#         if suffix:
#             num += suffix.upper()  # .upper for eg 1040EZ
#         titleEls = [doctype, num]
#         if sched:
#             titleEls.extend(['Schedule', sched.upper()])
#         title = ' '.join(el for el in titleEls if el)
#     else:
#         title = prefix.capitalize()
#     return title
# 
# def computeFormId(formName):
#     '''
#         >>> computeFormId('1040')
#         '1040'
#         >>> computeFormId(('1040','SE'))
#         '1040sSE'
#         '''
#     try:
#         form, sched = formName
#         if sched is None:
#             idd = form
#         else:
#             idd = form + 's' + sched
#     except ValueError:
#         idd = formName
#     return idd
# 
# def sortableFieldname(fieldname):
#     '''
#         to avoid lexicographic malordering: f1_19,f1_2,f1_20
#         >>> sortableFieldname('f1_43_L0T')
#         ['f', 1, '_', 43, '_L', 0, 'T']
#         '''
# 
#     def intify(s):
#         try:
#             return int(s)
#         except ValueError:
#             return s
#     try:
#         segs = re.findall('(\D+|\d+)', fieldname)
#         segs = [intify(seg) for seg in segs]
#         return segs
#     except Exception:
#         excclass, exc, tb = sys.exc_info()
#         new_exc = Exception(
#             'sortableFieldname: new exception: fieldname= ' + fieldname)
#         raise new_exc.__class__(new_exc).with_traceback(tb)
# 
# Path: opentaxforms/ut.py
# NL = '\n'
# TAB = '\t'
# def merge(bb1, bb2):
# def numerify(s):
# def compactify(multilineRegex):
#     def crunch(seg):
# def pickle(data, pickleFilePrefix):
# def unpickle(pickleFilePrefix, default=None):
# def flattened(l):
# def hasdups(l, key=None):
# def uniqify(l):
# def uniqify2(l):
# def setupLogging(loggerId, args=None):
# def unsetupLogging():
# def logg(msg, outputs=None):
# def jj(*args, **kw):
# def jdb(*args, **kw):
# def run0(cmd):
# def run(cmd, logprefix='run', loglevel='INFO'):
#     def __init__(self, pkgname, fpath=None):
#     def path(self):
#     def content(self):
#     def keys(cls):
#     def vals(cls):
#     def items(cls):
#     def __init__(self):
#     def __call__(self, **kw):
#     def __init__(self, *maps, **kw):
#     def _getGetitems(self, mapp):
#     def __getitem__(self, key):
#     def __setitem__(self, key, val):
#     def __len__(self):
#     def __call__(self, *keys):
#     def clear(self):
#     def update(self, *maps):
#     def __add__(self, *maps):
#     def __iadd__(self, *maps):
#     def __iter__(self):
#     def iterkeys(self):
#     def keys(self):
#     def values(self):
#     def items(self):
#     def iteritems(self):
#     def get(self, key, dflt=None):
#     def __str__(self):
#     def __repr__(self):
# def notequalpatch(self, o):
#     def fromstring(cls, s):
#     def __hash__(self):
# def playQnty():
# def nth(n):
# def skip(s, substr):
# def until(s, substr):
# def ensure_dir(folder):
# def now(format=None):
# def readImgSize(fname, dirName):
# def asciiOnly(s):
# class NoSuchPickle(Exception):
# class PickleException(Exception):
# class Resource(object):
# class CharEnum(object):
# class ChainablyUpdatableOrderedDict(odict):
# class Bag(object):
# class Qnty(qq):


# Path: opentaxforms/html.py
import os.path
import re
import traceback
        import doctest
from os import remove as removeFile
from itertools import chain
from . import ut
from .config import cfg, setup
from .irs import computeTitle, computeFormId, sortableFieldname
from .ut import log, jdb, Qnty, NL, pathjoin
    from PIL import Image

from __future__ import print_function, absolute_import



def computeFormFilename(form):
    try:
        # form may be eg ('1040','A')
        form, sched = form
        if sched is not None:
            form = '%ss%s' % (form, sched)

    except Exception: