xbrlkit 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. xbrlkit/__init__.py +24 -0
  2. xbrlkit/_vendor/arelle_plugins/EDGAR/__init__.py +3 -0
  3. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/__init__.py +308 -0
  4. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/conf/README.md +39 -0
  5. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/conf/extractTestcase.sh +2 -0
  6. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/conf/extractTestcase.xsl +109 -0
  7. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/conf/runIxtSecTests.sh +16 -0
  8. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/conf/saxon9.jar +0 -0
  9. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/conf/testcase.xml +7117 -0
  10. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/conf/tests.xml +848 -0
  11. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/conf/tests.xsd +50 -0
  12. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/text2num.py +110 -0
  13. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/transformationRegistry/registry/ixt-sec-boolballotbox.xml +66 -0
  14. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/transformationRegistry/registry/ixt-sec-countrynameen.xml +65 -0
  15. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/transformationRegistry/registry/ixt-sec-datequarterend.xml +66 -0
  16. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/transformationRegistry/registry/ixt-sec-durday.xml +61 -0
  17. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/transformationRegistry/registry/ixt-sec-durhour.xml +69 -0
  18. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/transformationRegistry/registry/ixt-sec-durmonth.xml +71 -0
  19. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/transformationRegistry/registry/ixt-sec-durweek.xml +70 -0
  20. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/transformationRegistry/registry/ixt-sec-durwordsen.xml +56 -0
  21. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/transformationRegistry/registry/ixt-sec-duryear.xml +64 -0
  22. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/transformationRegistry/registry/ixt-sec-edgarprovcountryen.xml +65 -0
  23. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/transformationRegistry/registry/ixt-sec-entityfilercategoryen.xml +63 -0
  24. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/transformationRegistry/registry/ixt-sec-exchnameen.xml +86 -0
  25. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/transformationRegistry/registry/ixt-sec-numwordsen.xml +55 -0
  26. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/transformationRegistry/registry/ixt-sec-stateprovnameen.xml +64 -0
  27. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/transformationRegistry/registry/ixt-sec-yesnoballotbox.xml +66 -0
  28. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/transformationRegistry/registry/transform-registry.xml +314 -0
  29. xbrlkit/_vendor/arelle_plugins/EDGAR/transform/transformationRegistry/schema/inlinexbrl-sec-transformation.xsd +418 -0
  30. xbrlkit/_vendor/ontology/v1/context.jsonld +397 -0
  31. xbrlkit/_vendor/ontology/v1/shapes.ttl +115 -0
  32. xbrlkit/cli.py +261 -0
  33. xbrlkit/config.py +50 -0
  34. xbrlkit/edgar/__init__.py +13 -0
  35. xbrlkit/edgar/client.py +186 -0
  36. xbrlkit/edgar/download.py +102 -0
  37. xbrlkit/edgar/rate_limit.py +33 -0
  38. xbrlkit/model.py +190 -0
  39. xbrlkit/namespaces.py +62 -0
  40. xbrlkit/parse/__init__.py +18 -0
  41. xbrlkit/parse/arelle_load.py +145 -0
  42. xbrlkit/parse/ids.py +67 -0
  43. xbrlkit/parse/to_model.py +571 -0
  44. xbrlkit/py.typed +1 -0
  45. xbrlkit/query.py +139 -0
  46. xbrlkit/serialize/__init__.py +24 -0
  47. xbrlkit/serialize/_kernel/__init__.py +0 -0
  48. xbrlkit/serialize/_kernel/bundle.py +322 -0
  49. xbrlkit/serialize/_kernel/context.py +286 -0
  50. xbrlkit/serialize/_kernel/holon.py +213 -0
  51. xbrlkit/serialize/_kernel/jsonld.py +627 -0
  52. xbrlkit/serialize/classify.py +87 -0
  53. xbrlkit/serialize/graph.py +526 -0
  54. xbrlkit/serialize/holon.py +26 -0
  55. xbrlkit/serialize/tavi.py +855 -0
  56. xbrlkit-0.2.0.dist-info/METADATA +161 -0
  57. xbrlkit-0.2.0.dist-info/RECORD +60 -0
  58. xbrlkit-0.2.0.dist-info/WHEEL +4 -0
  59. xbrlkit-0.2.0.dist-info/entry_points.txt +2 -0
  60. xbrlkit-0.2.0.dist-info/licenses/LICENSE +21 -0
xbrlkit/__init__.py ADDED
@@ -0,0 +1,24 @@
1
+ """xbrlkit — a SEC XBRL filing to a portable ``holon.jsonld``.
2
+
3
+ Fetch a filing from EDGAR, parse it into the neutral :class:`XbrlModel`, and
4
+ project that into the canonical scene/boundary/projection holon that renders
5
+ offline in the RoboSystems holon viewer.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from importlib.metadata import PackageNotFoundError, version
11
+
12
+ from .model import XbrlModel
13
+
14
+
15
+ def _get_version() -> str:
16
+ try:
17
+ return version("xbrlkit")
18
+ except PackageNotFoundError:
19
+ return "0.0.0+development"
20
+
21
+
22
+ __version__ = _get_version()
23
+
24
+ __all__ = ("XbrlModel", "__version__")
@@ -0,0 +1,3 @@
1
+ """Minimal EDGAR package shim so Arelle can load the vendored ``EDGAR.transform``
2
+ plugin (the SEC inline-XBRL transformation registry) without the full EDGAR
3
+ plugin (which pulls in the matplotlib-backed renderer we do not need)."""
@@ -0,0 +1,308 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ Custom transforms for SEC
4
+
5
+ Created by staff of the U.S. Securities and Exchange Commission.
6
+ Data and content created by government employees within the scope of their employment
7
+ are not subject to domestic copyright protection. 17 U.S.C. 105.
8
+
9
+ See COPYRIGHT.md for copyright information.
10
+
11
+ Local copy of text2num.py was obtained from https://github.com/ghewgill/text2num
12
+
13
+ '''
14
+ import datetime
15
+ from arelle.ModelValue import qname, lastDayOfMonth
16
+ from arelle.Version import authorLabel, copyrightLabel
17
+ from arelle.formula.XPathContext import FunctionArgType
18
+
19
+ #local copy of text2num.py from https://github.com/ghewgill/text2num
20
+ from .text2num import text2num, NumberException
21
+
22
+ from regex import compile as re_compile
23
+
24
+ # these five transformations take as input a number and output either an exception, or a value in xs:duration type
25
+ # they handle zero values and also negative values
26
+
27
+ # if arg is not an integer, the rest can spill into months and days, but nothing lower
28
+ def duryear(arg):
29
+ n, sign = getValue(arg)
30
+ years = int(n)
31
+ months = (n - years) * 12
32
+ days = int((months - int(months)) * 30.4375)
33
+ months = int(months)
34
+ return durationValue(years, months, days, None, sign)
35
+
36
+ # if arg is not an integer, the rest can spill into days, but nothing lower
37
+ def durmonth(arg):
38
+ n, sign = getValue(arg)
39
+ months = int(n)
40
+ days = int((n - months) * 30.4375)
41
+ return durationValue(None, months, days, None, sign)
42
+
43
+ # the output will only be in days, nothing lower
44
+ # xs:durationType doesn't have weeks, only years, months and days, so we display it all in days
45
+ def durweek(arg):
46
+ n, sign = getValue(arg)
47
+ days = int(n * 7)
48
+ return durationValue(None, None, days, None, sign)
49
+
50
+ # if arg is not an integer, the rest can spill into hours, but nothing lower
51
+ def durday(arg):
52
+ n, sign = getValue(arg)
53
+ days = int(n)
54
+ hours = int((n - days) * 24)
55
+ return durationValue(None, None, days, hours, sign)
56
+
57
+ # the output will only be in hours, nothing lower
58
+ def durhour(arg):
59
+ n, sign = getValue(arg)
60
+ hours = int(n)
61
+ return durationValue(None, None, None, hours, sign)
62
+
63
+ dateQuarterEndPattern = re_compile(r"(^[ \t\n\r]*(?:(?![0-9]{2})\w[^0-9]*)?(1|[Ff]irst|2|[Ss]econd|3|[Tt]hird|4|[Ff]ourth|[Ll]ast)[^0-9]*([0-9]{4})[ \t\n\r]*$)|(^[ \t\n\r]*([0-9]{4})[^0-9]*(1|[Ff]irst|2|[Ss]econd|3|[Tt]hird|4|[Ff]ourth|[Ll]ast)((?![0-9]).*\w+)?[ \t\n\r]*$)")
64
+
65
+ # the output is a date value of a calendar quarter end
66
+ def datequarterend(arg):
67
+ try:
68
+ m = dateQuarterEndPattern.match(arg)
69
+ year = int(m.group(3) or m.group(5)) # year pattern, raises AttributeError if no pattern match
70
+ month = {"first":3, "1":3, "second":6, "2":6, "third":9, "3":9, "fourth":12, "last":12, "4":12
71
+ }[(m.group(2) or m.group(6)).lower()]
72
+ return str(datetime.date(year, month, lastDayOfMonth(year, month)))
73
+ except (AttributeError, ValueError, KeyError):
74
+ raise FunctionArgType(0, "xs:date")
75
+
76
+ decimalValuePattern = re_compile(r"^[ \t\n\r]*[+-]?([0-9]+(\.[0-9]*)?|\.[0-9]+)[ \t\n\r]*$")
77
+
78
+ def getValue(arg):
79
+ if not decimalValuePattern.match(arg):
80
+ raise FunctionArgType(0, "xs:duration")
81
+ try:
82
+ n = float(arg) # could cause a ValueError exception
83
+ if n < 0:
84
+ return (abs(n), '-') # add a negative sign
85
+ return (n, '') # don't add a sign
86
+ except ValueError:
87
+ raise FunctionArgType(0, "xs:duration")
88
+
89
+ def durationValue(y, m, d, h, sign):
90
+
91
+ # preprocess each value so we don't print P0Y0M0D or something like that.
92
+ # in this case, we should print P0Y, and leave out the months and days.
93
+ if all(i == 0 or i is None for i in [y, m, d, h]):
94
+ sign = '' # don't need to print -P0Y, just print P0Y
95
+ hitFirstZeroYet = False
96
+ if y is not None and y == 0:
97
+ hitFirstZeroYet = True
98
+ if m is not None and m == 0:
99
+ if hitFirstZeroYet:
100
+ m = None
101
+ else:
102
+ hitFirstZeroYet = True
103
+ if d is not None and d == 0:
104
+ if hitFirstZeroYet:
105
+ d = None
106
+ else:
107
+ hitFirstZeroYet = True
108
+ if h is not None and h == 0 and hitFirstZeroYet:
109
+ h = None
110
+
111
+ output = sign + "P"
112
+ if y is not None:
113
+ output += str(y) + 'Y'
114
+ if m is not None and (m != 0 or y is None):
115
+ output += str(m) + 'M'
116
+ if d is not None and (d != 0 or (y is None and m is None)):
117
+ output += str(d) + 'D'
118
+ if h is not None and (h != 0 or (y is None and m is None and d is None)):
119
+ output += 'T' + str(h) + 'H'
120
+ return output
121
+
122
+ def numinf(arg):
123
+ return "INF"
124
+
125
+ def numneginf(arg):
126
+ return "-INF"
127
+
128
+ def numnan(arg):
129
+ return "NaN"
130
+
131
+ numwordsenPattern = re_compile(r"^[ \t\n\r]*(((((([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)\s+[Hh]undred(\s+(and\s+)?(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))?)|(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))\s+[Qq]uintillion(\s*,\s*|\s+|$))?(((([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)\s+[Hh]undred(\s+(and\s+)?(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))?)|(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))\s+[Qq]uadrillion(\s*,\s*|\s+|$))?(((([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)\s+[Hh]undred(\s+(and\s+)?(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))?)|(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))\s+[Tt]rillion(\s*,\s*|\s+|$))?(((([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)\s+[Hh]undred(\s+(and\s+)?(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))?)|(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))\s+[Bb]illion(\s*,\s*|\s+|$))?(((([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)\s+[Hh]undred(\s+(and\s+)?(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))?)|(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))\s+[Mm]illion(\s*,\s*|\s+|$))?((((([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)\s+[Hh]undred(\s+(and\s+)?(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))?)|(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))\s+[Tt]housand((\s*,\s*|\s+)((([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)\s+[Hh]undred(\s+(and\s+)?(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))?)|(and\s+)?(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?)))?)|(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)\s+[Hh]undred(\s+(and\s+)?(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))?)|(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))?)|[Zz]ero|[Nn]o(ne)?|[Nn]il)[ \t\n\r]*$")
132
+
133
+ numwordsNoPattern = re_compile(r"^[ \t\n\r]*([Nn]o(ne)?|[Nn]il)[ \t\n\r]*$")
134
+
135
+ commaAndPattern = re_compile(r",|\sand\s") # substitute whitespace for comma or and
136
+
137
+ def numwordsen(arg):
138
+ if not numwordsenPattern.match(arg) or len(arg) == 0:
139
+ raise FunctionArgType(0, "numwordsen lexical error")
140
+ elif numwordsNoPattern.match(arg): # match "no" or "none"
141
+ return "0"
142
+ try:
143
+ return str(text2num(commaAndPattern.sub(" ", arg.strip().lower()))) # must be returned as a string
144
+ except (NumberException, TypeError, ValueError) as ex:
145
+ raise FunctionArgType(0, str(ex))
146
+
147
+ durwordsenPattern = re_compile(r"^[ \t\n\r]*((((([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)[Hh]undred(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)(and\s+)?(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))?)|(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))|[Zz]ero|[Nn]o|[0-9][0-9]{0,3})([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)[Yy]ears?(,?([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)(and\s+)?|$))?((((([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)[Hh]undred(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)(and\s+)?(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))?)|(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))|[Zz]ero|[Nn]o|[0-9][0-9]{0,3})([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)[Mm]onths?(,?([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)(and\s+)?|$))?((((([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)[Hh]undred(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)(and\s+)?(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))?)|(([Oo]ne|[Tt](wo|hree|en|welve|hirteen)|[Ff](our(teen)?|ive|ifteen)|[Ss](ix(teen)?|even(teen)?)|[Ee](ight(een)?|leven)|[Nn]ine(teen)?)|([Tt](wenty|hirty)|[Ff](orty|ifty)|[Ss](ixty|eventy)|[Ee]ighty|[Nn]inety)(([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)([Oo]ne|[Tt](wo|hree)|[Ff](our|ive)|[Ss](ix|even)|[Ee]ight|[Nn]ine))?))|[Zz]ero|[Nn]o|[0-9][0-9]{0,3})([\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]|\s+)[Dd]ays?)?[ \t\n\r]*$")
148
+
149
+ durwordZeroNoPattern = re_compile(r"^[ \t\n\r]*[\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]?([Zz]ero|[Nn]o(ne)?)[\u058A\u05BE\u2010\u2011\u2012\u2013\u2014\u2015\uFE58\uFE63\uFF0D-]?[ \t\n\r]*$")
150
+
151
+
152
+ def durwordsen(arg):
153
+ durWordsMatch = durwordsenPattern.match(arg)
154
+ if not durWordsMatch or len(arg.strip()) == 0:
155
+ raise FunctionArgType(1, "durwordsen lexical error")
156
+ try:
157
+ dur = 'P'
158
+ durWordsMatchGroups = durWordsMatch.groups()
159
+ for groupIndex, groupSuffix in ((1,"Y"), (65,"M"), (129, "D")):
160
+ groupPart = durWordsMatchGroups[groupIndex]
161
+ if groupPart and not durwordZeroNoPattern.match(groupPart):
162
+ if groupPart.isnumeric():
163
+ dur += groupPart + groupSuffix
164
+ else:
165
+ dur += str(text2num(commaAndPattern.sub(" ", groupPart.strip().lower()))) + groupSuffix
166
+ return dur if len(dur) > 1 else "P0D" # must have at least one number and designator
167
+ except (NumberException, TypeError, ValueError) as ex:
168
+ raise FunctionArgType(0, str(ex))
169
+
170
+ ballotboxPattern = re_compile(r"^[ \t\n\r]*([\u2610-\u2612])[ \t\n\r]*$")
171
+
172
+ def boolballotbox(arg):
173
+ ballotboxMatch = ballotboxPattern.match(arg)
174
+ if not ballotboxMatch or len(arg.strip()) == 0:
175
+ raise FunctionArgType(1, "boolballotboxMatch lexical error")
176
+ try:
177
+ return ("false", "true", "true")[ord(ballotboxMatch.group(1)[0]) - ord('\u2610')]
178
+ except (IndexException, TypeError) as ex:
179
+ raise FunctionArgType(0, str(ex))
180
+
181
+ def yesnoballotbox(arg):
182
+ ballotboxMatch = ballotboxPattern.match(arg)
183
+ if not ballotboxMatch or len(arg.strip()) == 0:
184
+ raise FunctionArgType(1, "yesnoballotboxMatch lexical error")
185
+ try:
186
+ return ("No", "Yes", "Yes")[ord(ballotboxMatch.group(1)[0]) - ord('\u2610')]
187
+ except (IndexException, TypeError) as ex:
188
+ raise FunctionArgType(0, str(ex))
189
+
190
+ def codeIndex(match):
191
+ groups = match.groups()
192
+ for grpNbr in range(1, len(groups)):
193
+ if groups[grpNbr] is not None:
194
+ # ith group matched, get pattern's code position
195
+ parenNbr = 0 # outer paren is for the enclosure of all the groups
196
+ for codeIndex, patternForCode in enumerate(match.re.pattern.split(")|")):
197
+ inCharacterClass = False
198
+ for c in patternForCode:
199
+ if c == "[":
200
+ inCharacterClass = True
201
+ elif c == "]":
202
+ inCharacterClass = False
203
+ if c == "(" and not inCharacterClass:
204
+ if parenNbr == grpNbr:
205
+ return codeIndex # this is the code which matched
206
+ parenNbr += 1
207
+ return None # no match
208
+
209
+
210
+ countryNamePattern = re_compile(r"^[ \t\n\r]*(([Aa]fghanistan)|([ÅåAa]land\s+[Ii]slands)|([Aa]lbania)|([Aa]lgeria)|([Aa]merican\s+[Ss]amoa)|([Aa]ndorra)|([Aa]ngola)|([Aa]nguilla)|([Aa]ntarctica)|([Aa]ntigua\s+[Aa]nd\s+[Bb]arbuda)|((([Tt]he\s+)?[Rr]epublic\s+[Oo]f\s+)?[Aa]rgentina)|([Aa]rmenia)|([Aa]ruba)|([Aa]ustralia)|([Aa]ustria)|([Aa]zerbaijan)|([Bb]ahamas)|([Bb]ahrain)|([Bb]angladesh)|([Bb]arbados)|([Bb]elarus)|([Bb]elgium)|([Bb]elize)|([Bb]enin)|([Bb]ermuda)|([Bb]hutan)|([Bb]olivia)|([Bb]onaire,\s+[Ss]int\s+[Ee]ustatius\s+[Aa]nd\s+[Ss]aba)|([Bb]osnia\s+[Aa]nd\s+[Hh]erzegovina)|([Bb]otswana)|([Bb]ouvet\s+[Ii]sland)|((([Tt]he\s+)?[Ff]ederative\s+[Rr]epublic\s+[Oo]f\s+)?[Bb]ra[sz]il)|([Bb]ritish\s+[Ii]ndian\s+[Oo]cean\s+[Tt]erritory)|([Bb]runei\s+[Dd]arussalam)|([Bb]ulgaria)|([Bb]urkina\s+[Ff]aso)|([Bb]urundi)|([Cc]abo\s+[Vv]erde)|([Cc]ambodia)|([Cc]ameroon)|([Cc]anada)|([Cc]ayman\s+[Ii]slands)|([Cc]entral\s+[Aa]frican\s+[Rr]epublic)|([Cc]had)|([Cc]hile)|((([Tt]he\s+)?[Pp]eople['’]?s\s+[Rr]epublic\s+[Oo]f\s+)?[Cc]hina)|([Cc]hristmas\s+[Ii]sland)|([Cc]ocos\s+(.[Kk]eeling.\s+)?[Ii]slands)|((([Tt]he\s+)?[Rr]epublic\s+[Oo]f\s+)?[Cc]olombia)|([Cc]omoros)|([Dd]emocratic\s+[Rr]epublic\s+[Oo]f\s+([Tt]he\s+)?[Cc]ongo)|([Cc]ongo)|([Cc]ook\s+[Ii]slands)|([Cc]osta\s+[Rr]ica)|([Cc][ôo]te\s+d['’][Ii]voire)|([Cc]roatia)|([Cc]uba)|([Cc]ura[çc]ao)|([Cc]yprus)|([Cc]zechia|[Cc]zech\s+[Rr]epublic)|((([Tt]he\s+)?[Kk]ingdom\s+[Oo]f\s+)?[Dd]enmark)|([Dd]jibouti)|([Dd]ominica)|([Dd]ominican\s+[Rr]epublic)|([Ee]cuador)|([Ee]gypt)|([Ee]l\s+[Ss]alvador)|([Ee]quatorial\s+[Gg]uinea)|([Ee]ritrea)|([Ee]stonia)|([Ee]swatini)|([Ee]thiopia)|(([Tt]he\s+)?[Ff]alkland\s+[Ii]slands(\s+.[Mm]alvinas.)?|([Ii]slas\s+)?[Mm]alvinas(\s+[Ii]slands)?)|([Ff]aroe\s+[Ii]slands)|([Ff]iji)|([Ff]inland)|([Ff]rance)|([Ff]rench\s+[Gg]uiana)|([Ff]rench\s+[Pp]olynesia)|([Ff]rench\s+[Ss]outhern\s+[Tt]erritories)|([Gg]abon)|([Gg]ambia)|([Gg]eorgia)|([Gg]ermany)|([Gg]hana)|([Gg]ibraltar)|([Gg]reece)|([Gg]reenland)|([Gg]renada)|([Gg]uadeloupe)|([Gg]uam)|([Gg]uatemala)|([Gg]uernsey)|([Gg]uinea)|([Gg]uinea-[Bb]issau)|([Gg]uyana)|([Hh]aiti)|([Hh]eard\s+[Ii]sland\s+[Aa]nd\s+[Mm]cDonald\s+[Ii]slands)|(([Tt]he\s+)?[Hh]oly\s+[Ss]ee|[Vv]atican\s+[Cc]ity)|([Hh]onduras)|([Hh]ong\s+[Kk]ong)|([Hh]ungary)|([Ii]celand)|([Ii]ndia)|([Ii]ndonesia)|((([Tt]he\s+)?[Ii]slamic\s+[Rr]epublic\s+of\s+)?[Ii]ran)|([Ii]raq)|([Ii]reland)|([Ii]sle\s+[Oo]f\s+[Mm]an)|([Ii]srael)|([Ii]taly)|([Jj]amaica)|([Jj]apan)|([Jj]ersey)|([Jj]ordan)|([Kk]azakhstan)|([Kk]enya)|([Kk]iribati)|(([Nn]orth|[Dd]emocratic\s+[Pp]eople['’]?s\s+[Rr]epublic\s+[Oo]f)\s+[Kk]orea)|(([Ss]outh|[Rr]epublic\s+[Oo]f)\s+[Kk]orea)|([Kk]uwait)|([Kk]yrgyzstan)|([Ll]ao\s+[Pp]eople['’]?s\s+[Dd]emocratic\s+[Rr]epublic)|([Ll]atvia)|([Ll]ebanon)|([Ll]esotho)|([Ll]iberia)|((([Tt]he\s+)?[Ss]tate\s+[Oo]f\s+)?[Ll]ibya)|([Ll]iechtenstein)|([Ll]ithuania)|((([Tt]he\s+)?([Gg]rand\s+)?[Dd]uchy\s+[Oo]f\s+)?[Ll]uxembourg)|([Mm]aca[ou])|([Mm]adagascar)|([Mm]alawi)|([Mm]alaysia)|([Mm]aldives)|([Mm]ali)|([Mm]alta)|((([Tt]he\s+)?[Rr]epublic\s+[Oo]f\s+([Tt]he\s+)?)?[Mm]arshall\s+[Ii]slands)|([Mm]artinique)|([Mm]auritania)|([Mm]auritius)|([Mm]ayotte)|([Mm]exico|[Uu]nited\s+[Mm]exican\s+[Ss]tates)|((([Tt]he\s+)?[Ff]ederated\s+[Ss]tates\s+[Oo]f\s+)?[Mm]icronesia)|((([Tt]he\s+)?[Rr]epublic\s+[Oo]f\s+)?[Mm]oldova)|([Mm]onaco)|([Mm]ongolia)|([Mm]ontenegro)|([Mm]ontserrat)|([Mm]orocco)|([Mm]ozambique)|([Mm]yanmar)|([Nn]amibia)|([Nn]auru)|([Nn]epal)|([Nn]etherlands)|([Nn]ew\s+[Cc]aledonia)|([Nn]ew\s+[Zz]ealand)|([Nn]icaragua)|([Nn]iger)|([Nn]igeria)|([Nn]iue)|([Nn]orfolk\s+[Ii]sland)|((([Tt]he\s+)?[Rr]epublic\s+[Oo]f\s+)?[Nn]orth\s+[Mm]acedonia)|([Nn]orthern\s+[Mm]ariana\s+[Ii]slands)|([Nn]orway)|([Oo]man)|([Pp]akistan)|([Pp]alau)|((([Tt]he\s+)?[Ss]tate\s+[Oo]f\s+)?[Pp]alestine)|([Pp]anama)|([Pp]apua\s+[Nn]ew\s+[Gg]uinea)|([Pp]araguay)|([Pp]eru)|([Pp]hilippines)|([Pp]itcairn)|([Pp]oland)|([Pp]ortugal)|([Pp]uerto\s+[Rr]ico)|([Qq]atar)|([Rr][ée]union)|([Rr]omania)|([Rr]ussian\s+[Ff]ederation)|([Rr]wanda)|([Ss]aint\s+[Bb]arth[ée]lemy)|([Ss]aint\s+[Hh]elena(,\s+[Aa]scension,?\s+[Aa]nd\s+[Tt]ristan(\s+[Dd]a\s+[Cc]unha)?)?)|([Ss]aint\s+[Kk]itts\s+[Aa]nd\s+[Nn]evis)|([Ss]aint\s+[Ll]ucia)|([Ss]aint\s+[Mm]artin)|([Ss]aint\s+[Pp]ierre\s+[Aa]nd\s+[Mm]iquelon)|([Ss]aint\s+[Vv]incent(\s+[Aa]nd\s+([Tt]he\s+)?[Gg]renadines)?)|([Ss]amoa)|([Ss]an\s+[Mm]arino)|([Ss]ao\s+[Tt]ome\s+[Aa]nd\s+[Pp]rincipe)|([Ss]audi\s+[Aa]rabia)|([Ss]enegal)|([Ss]erbia)|([Ss]eychelles)|([Ss]ierra\s+[Ll]eone)|([Ss]ingapore)|([Ss]int\s+[Mm]aarten)|([Ss]lovakia)|([Ss]lovenia)|([Ss]olomon\s+[Ii]slands)|([Ss]omalia)|((([Tt]he\s+)?[Rr]epublic\s+[Oo]f\s+)?[Ss]outh\s+[Aa]frica)|([Ss]outh\s+[Gg]eorgia\s+[Aa]nd\s+([Tt]he\s+)?[Ss]outh\s+[Ss]andwich\s+[Ii]slands)|([Ss]outh\s+[Ss]udan)|((([Tt]he\s+)?[Kk]ingdom\s+[Oo]f\s+)?[Ss]pain|[Ee]spa[ñn]a)|([Ss]ri\s+[Ll]anka)|([Ss]udan)|([Ss]uriname)|([Ss]valbard\s+[Aa]nd\s+[Jj]an\s+[Mm]ayen)|([Ss]weden)|([Ss]witzerland)|([Ss]yria(n\s+[Aa]rab\s+[Rr]epublic)?)|([Tt]aiwan(,?\s+[Pp]rovince\s+[Oo]f\s+[Cc]hina)?)|([Tt]ajikistan)|((([Tt]he\s+)?[Uu]nited\s+[Rr]epublic\s+[Oo]f\s+)?[Tt]anzania)|([Tt]hailand)|([Tt]imor-[Ll]este)|([Tt]ogo)|([Tt]okelau)|([Tt]onga)|([Tt]rinidad\s+[Aa]nd\s+[Tt]obago)|([Tt]unisia)|([Tt][uü]rk(ey|iye))|([Tt]urkmenistan)|([Tt]urks\s+[Aa]nd\s+[Cc]aicos\s+[Ii]slands)|([Tt]uvalu)|([Uu]ganda)|([Uu]kraine)|(UAE|[Uu]nited\s+[Aa]rab\s+[Ee]mirates)|(U[.]?K[.]?|[Bb]ritain|[Gg]reat\s+[BBb]ritain|[Uu]nited\s+[Kk]ingdom(\s+[Oo]f\s+[Gg]reat\s+[Bb]ritain\s+[Aa]nd\s+[Nn]orthern\s+[Ii]reland)?|[Ee]ngland(\s+[Aa]nd\s+[Ww]ales)?)|([Uu]nited\s+[Ss]tates\s+[Mm]inor\s+[Oo]utlying\s+[Ii]slands)|(U[.]?S[.]?A[.]?|[Uu]nited\s+[Ss]tates(\s+[Oo]f\s+[Aa]merica)?)|([Uu]ruguay)|([Uu]zbekistan)|([Vv]anuatu)|([Vv]enezuela)|([Vv]iet\s+[Nn]am)|([Bb]ritish\s+[Vv]irgin\s+[Ii]slands)|([Uu][.]?[Ss][.]?\s+[Vv]irgin\s+[Ii]slands)|([Ww]allis\s+[Aa]nd\s+[Ff]utuna)|([Ww]estern\s+[Ss]ahara*)|([Yy]emen)|([Zz]ambia)|([Zz]imbabwe))[ \t\n\r]*$")
211
+
212
+ countryCodes = ("AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BQ", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "CV", "KH", "CM", "CA", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CD", "CG", "CK", "CR", "CI", "HR", "CU", "CW", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "SZ", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "KP", "KR", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MK", "MP", "NO", "OM", "PK", "PW", "PS", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "BL", "SH", "KN", "LC", "MF", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", "SX", "SK", "SI", "SB", "SO", "ZA", "GS", "SS", "ES", "LK", "SD", "SR", "SJ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "UM", "US", "UY", "UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW")
213
+
214
+ def countrynameen(arg):
215
+ countryMatch = countryNamePattern.match(arg)
216
+ if not countryMatch or len(arg.strip()) == 0:
217
+ raise FunctionArgType(1, "countrynameen lexical error")
218
+ try:
219
+ return countryCodes[codeIndex(countryMatch)]
220
+ except (IndexException, TypeError) as ex:
221
+ raise FunctionArgType(0, str(ex))
222
+
223
+ stateProvNamePattern = re_compile(r"^[ \t\n\r]*(([Aa]labama)|([Aa]laska)|([Aa]rizona)|([Aa]rkansas)|([Cc]alifornia)|([Cc]olorado)|([Cc]onnecticut)|([Dd]elaware)|([Ff]lorida)|([Gg]eorgia)|([Hh]awaii)|([Ii]daho)|([Ii]llinois)|([Ii]ndiana)|([Ii]owa)|([Kk]ansas)|([Kk]entucky)|([Ll]ouisiana)|([Mm]aine)|([Mm]aryland)|([Mm]assachusetts)|([Mm]ichigan)|([Mm]innesota)|([Mm]ississippi)|([Mm]issouri)|([Mm]ontana)|([Nn]ebraska)|([Nn]evada)|([Nn]ew\s+[Hh]ampshire)|([Nn]ew\s+[Jj]ersey)|([Nn]ew\s+[Mm]exico)|([Nn]ew\s+[Yy]ork)|([Nn]orth\s+[Cc]arolina)|([Nn]orth\s+[Dd]akota)|([Oo]hio)|([Oo]klahoma)|([Oo]regon)|([Pp]ennsylvania)|([Rr]hode\s+[Ii]sland)|([Ss]outh\s+[Cc]arolina)|([Ss]outh\s+[Dd]akota)|([Tt]ennessee)|([Tt]exas)|([Uu]tah)|([Vv]ermont)|([Vv]irginia)|([Ww]ashington)|([Ww]est\s+[Vv]irginia)|([Ww]isconsin)|([Ww]yoming)|([Dd]istrict\s+[Oo]f\s+[Cc]olumbia)|(([Aa]merican\s+)?[Ss]amoa)|([Gg]uam)|([Nn]orthern\s+[Mm]ariana\s+[Ii]slands)|([Pp]uerto\s+[Rr]ico)|([Uu]nited\s+[Ss]tates\s+[Mm]inor\s+[Oo]utlying\s+[Ii]slands)|([Vv]irgin\s+[Ii]slands,\s+U[.]S[.])|([Aa]lberta)|([Bb]ritish\s+[Cc]olumbia)|([Mm]anitoba)|([Nn]ew\s+[Bb]runswick)|([Nn]ewfoundland(\s+[Aa]nd\s+[Ll]abrador)?)|([Nn]ova\s+[Ss]cotia)|([Nn]orthwest\s+[Tt]erritories)|([Nn]unavut)|([Oo]ntario)|([Pp]rince\s+[Ee]dward\s+[Ii]sland)|([Qq]u[eé]bec)|([Ss]askatchewan)|([Yy]ukon))[ \t\n\r]*$")
224
+
225
+ stateProvCodes = ("AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY", "DC", "AS", "GU", "MP", "PR", "UM", "VI", "AB", "BC", "MB", "NB", "NL", "NS", "NT", "NU", "ON", "PE", "QC", "SK", "YT")
226
+
227
+ def stateprovnameen(arg):
228
+ stateProvMatch = stateProvNamePattern.match(arg)
229
+ if not stateProvMatch or len(arg.strip()) == 0:
230
+ raise FunctionArgType(1, "stateprovnameen lexical error")
231
+ try:
232
+ return stateProvCodes[codeIndex(stateProvMatch)]
233
+ except (IndexException, TypeError) as ex:
234
+ raise FunctionArgType(0, str(ex))
235
+
236
+ edgarProvCountryNamePattern = re_compile(r"^[ \t\n\r]*(([Aa]merican\s+[Ss]amoa)|([Gg]uam)|([Pp]uerto\s+[Rr]ico)|([Uu]nited\s+[Ss]tates\s+[Mm]inor\s+[Oo]utlying\s+[Ii]slands)|([Vv]irgin\s+[Ii]slands,\s+U[.]?S[.]?|U([.]\s*)?S[.]?\s+[Vv]irgin\s+[Ii]slands)|([Aa]lberta(,?\s+[Cc]anada)?)|([Bb]ritish\s+[Cc]olumbia(,?\s+[Cc]anada)?)|([Mm]anitoba(,?\s+[Cc]anada)?)|([Nn]ew\s+[Bb]runswick(,?\s+[Cc]anada)?)|([Nn]ewfoundland(\s+[Aa]nd\s+[Ll]abrador)?(,?\s+[Cc]anada)?)|([Nn]ova\s+[Ss]cotia(,?\s+[Cc]anada)?)|([Oo]ntario(,?\s+[Cc]anada)?)|([Pp]rince\s+[Ee]dward\s+[Ii]sland(,?\s+[Cc]anada)?)|([Qq]u[eé]bec(,?\s+[Cc]anada)?)|([Ss]askatchewan(,?\s+[Cc]anada)?)|([Yy]ukon(,?\s+[Cc]anada)?)|([Aa]fghanistan)|([ÅåAa]land\s+[Ii]slands)|([Aa]lbania)|([Aa]lgeria)|([Aa]merican\s+[Ss]amoa)|([Aa]ndorra)|([Aa]ngola)|([Aa]nguilla)|([Aa]ntarctica)|([Aa]ntigua\s+[Aa]nd\s+[Bb]arbuda)|((([Tt]he\s+)?[Rr]epublic\s+[Oo]f\s+)?[Aa]rgentina)|([Aa]rmenia)|([Aa]ruba)|([Aa]ustralia)|([Aa]ustria)|([Aa]zerbaijan)|([Bb]ahamas)|([Bb]ahrain)|([Bb]angladesh)|([Bb]arbados)|([Bb]elarus)|([Bb]elgium)|([Bb]elize)|([Bb]enin)|([Bb]ermuda)|([Bb]hutan)|([Bb]olivia)|([Bb]osnia\s+[Aa]nd\s+[Hh]erzegovina)|([Bb]otswana)|([Bb]ouvet\s+[Ii]sland)|((([Tt]he\s+)?[Ff]ederative\s+[Rr]epublic\s+[Oo]f\s+)?[Bb]ra[sz]il)|([Bb]ritish\s+[Ii]ndian\s+[Oo]cean\s+[Tt]erritory)|([Bb]runei\s+[Dd]arussalam)|([Bb]ulgaria)|([Bb]urkina\s+[Ff]aso)|([Bb]urundi)|([Cc]a(bo|pe)\s+[Vv]erde)|([Cc]ambodia)|([Cc]ameroon)|([Cc]anada)|([Cc]ayman\s+[Ii]slands)|([Cc]entral\s+[Aa]frican\s+[Rr]epublic)|([Cc]had)|([Cc]hile)|((([Tt]he\s+)?[Pp]eople['’]?s\s+[Rr]epublic\s+[Oo]f\s+)?[Cc]hina)|([Cc]hristmas\s+[Ii]sland)|([Cc]ocos\s+(.[Kk]eeling.\s+)?[Ii]slands)|((([Tt]he\s+)?[Rr]epublic\s+[Oo]f\s+)?[Cc]olombia)|([Cc]omoros)|([Dd]emocratic\s+[Rr]epublic\s+[Oo]f\s+([Tt]he\s+)?[Cc]ongo)|([Cc]ongo)|([Cc]ook\s+[Ii]slands)|([Cc]osta\s+[Rr]ica)|([Cc][ôo]te\s+d['’][Ii]voire)|([Cc]roatia)|([Cc]uba)|([Cc]yprus)|([Cc]zechia|[Cc]zech\s+[Rr]epublic)|((([Tt]he\s+)?[Kk]ingdom\s+[Oo]f\s+)?[Dd]enmark)|([Dd]jibouti)|([Dd]ominica)|([Dd]ominican\s+[Rr]epublic)|([Ee]cuador)|([Ee]gypt)|([Ee]l\s+[Ss]alvador)|([Ee]quatorial\s+[Gg]uinea)|([Ee]ritrea)|([Ee]stonia)|([Ee]thiopia)|(([Tt]he\s+)?[Ff]alkland\s+[Ii]slands(\s+.[Mm]alvinas.)?|([Ii]slas\s+)?[Mm]alvinas(\s+[Ii]slands)?)|([Ff]aroe\s+[Ii]slands)|([Ff]iji)|([Ff]inland)|([Ff]rance)|([Ff]rench\s+[Gg]uiana)|([Ff]rench\s+[Pp]olynesia)|([Ff]rench\s+[Ss]outhern\s+[Tt]erritories)|([Gg]abon)|([Gg]ambia)|([Gg]eorgia)|([Gg]ermany)|([Gg]hana)|([Gg]ibraltar)|([Gg]reece)|([Gg]reenland)|([Gg]renada)|([Gg]uadeloupe)|([Gg]uatemala)|([Gg]uernsey)|([Gg]uinea)|([Gg]uinea-[Bb]issau)|([Gg]uyana)|([Hh]aiti)|([Hh]eard\s+[Ii]sland\s+[Aa]nd\s+[Mm]cDonald\s+[Ii]slands)|(([Tt]he\s+)?[Hh]oly\s+[Ss]ee|[Vv]atican\s+[Cc]ity)|([Hh]onduras)|([Hh]ong\s+[Kk]ong)|([Hh]ungary)|([Ii]celand)|([Ii]ndia)|([Ii]ndonesia)|((([Tt]he\s+)?[Ii]slamic\s+[Rr]epublic\s+of\s+)?[Ii]ran)|([Ii]raq)|([Ii]reland)|([Ii]sle\s+[Oo]f\s+[Mm]an)|([Ii]srael)|([Ii]taly)|([Jj]amaica)|([Jj]apan)|([Jj]ersey)|([Jj]ordan)|([Kk]azakhstan)|([Kk]enya)|([Kk]iribati)|(([Nn]orth|[Dd]emocratic\s+[Pp]eople['’]?s\s+[Rr]epublic\s+[Oo]f)\s+[Kk]orea)|(([Ss]outh|[Rr]epublic\s+[Oo]f)\s+[Kk]orea)|([Kk]uwait)|([Kk]yrgyzstan)|([Ll]ao\s+[Pp]eople['’]?s\s+[Dd]emocratic\s+[Rr]epublic)|([Ll]atvia)|([Ll]ebanon)|([Ll]esotho)|([Ll]iberia)|((([Tt]he\s+)?[Ss]tate\s+[Oo]f\s+)?[Ll]ibya)|([Ll]iechtenstein)|([Ll]ithuania)|((([Tt]he\s+)?([Gg]rand\s+)?[Dd]uchy\s+[Oo]f\s+)?[Ll]uxembourg)|([Mm]aca[ou])|([Mm]adagascar)|([Mm]alawi)|([Mm]alaysia)|([Mm]aldives)|([Mm]ali)|([Mm]alta)|((([Tt]he\s+)?[Rr]epublic\s+[Oo]f\s+([Tt]he\s+)?)?[Mm]arshall\s+[Ii]slands)|([Mm]artinique)|([Mm]auritania)|([Mm]auritius)|([Mm]ayotte)|([Mm]exico|[Uu]nited\s+[Mm]exican\s+[Ss]tates)|((([Tt]he\s+)?[Ff]ederated\s+[Ss]tates\s+[Oo]f\s+)?[Mm]icronesia)|((([Tt]he\s+)?[Rr]epublic\s+[Oo]f\s+)?[Mm]oldova)|([Mm]onaco)|([Mm]ongolia)|([Mm]ontenegro)|([Mm]ontserrat)|([Mm]orocco)|([Mm]ozambique)|([Mm]yanmar)|([Nn]amibia)|([Nn]auru)|([Nn]epal)|([Nn]etherlands\s+[Aa]ntilles)|([Nn]etherlands)|([Nn]ew\s+[Cc]aledonia)|([Nn]ew\s+[Zz]ealand)|([Nn]icaragua)|([Nn]iger)|([Nn]igeria)|([Nn]iue)|([Nn]orfolk\s+[Ii]sland)|((([Tt]he\s+)?[Rr]epublic\s+[Oo]f\s+)?([Nn]orth\s+)?[Mm]acedonia)|([Nn]orthern\s+[Mm]ariana\s+[Ii]slands)|([Nn]orway)|([Oo]man)|([Pp]akistan)|([Pp]alau)|((([Tt]he\s+)?[Ss]tate\s+[Oo]f\s+)?[Pp]alestine)|([Pp]anama)|([Pp]apua\s+[Nn]ew\s+[Gg]uinea)|([Pp]araguay)|([Pp]eru)|([Pp]hilippines)|([Pp]itcairn)|([Pp]oland)|([Pp]ortugal)|([Qq]atar)|([Rr][ée]union)|([Rr]omania)|([Rr]ussian\s+[Ff]ederation)|([Rr]wanda)|([Ss]aint\s+[Bb]arth[ée]lemy)|([Ss]aint\s+[Hh]elena(,\s+[Aa]scension,?\s+[Aa]nd\s+[Tt]ristan(\s+[Dd]a\s+[Cc]unha)?)?)|([Ss]aint\s+[Kk]itts\s+[Aa]nd\s+[Nn]evis)|([Ss]aint\s+[Ll]ucia)|([Ss]aint\s+[Mm]artin)|([Ss]aint\s+[Pp]ierre\s+[Aa]nd\s+[Mm]iquelon)|([Ss]aint\s+[Vv]incent(\s+[Aa]nd\s+([Tt]he\s+)?[Gg]renadines)?)|([Ss]amoa)|([Ss]an\s+[Mm]arino)|([Ss]ao\s+[Tt]ome\s+[Aa]nd\s+[Pp]rincipe)|([Ss]audi\s+[Aa]rabia)|([Ss]enegal)|([Ss]erbia)|([Ss]eychelles)|([Ss]ierra\s+[Ll]eone)|([Ss]ingapore)|([Ss]lovakia)|([Ss]lovenia)|([Ss]olomon\s+[Ii]slands)|([Ss]omalia)|((([Tt]he\s+)?[Rr]epublic\s+[Oo]f\s+)?[Ss]outh\s+[Aa]frica)|([Ss]outh\s+[Gg]eorgia\s+[Aa]nd\s+([Tt]he\s+)?[Ss]outh\s+[Ss]andwich\s+[Ii]slands)|((([Tt]he\s+)?[Kk]ingdom\s+[Oo]f\s+)?[Ss]pain|[Ee]spa[ñn]a)|([Ss]ri\s+[Ll]anka)|([Ss]udan)|([Ss]uriname)|([Ss]valbard\s+[Aa]nd\s+[Jj]an\s+[Mm]ayen)|([Ss]waziland)|([Ss]weden)|([Ss]witzerland)|([Ss]yria(n\s+[Aa]rab\s+[Rr]epublic)?)|([Tt]aiwan(,?\s+[Pp]rovince\s+[Oo]f\s+[Cc]hina)?)|([Tt]ajikistan)|((([Tt]he\s+)?[Uu]nited\s+[Rr]epublic\s+[Oo]f\s+)?[Tt]anzania)|([Tt]hailand)|([Tt]imor-[Ll]este)|([Tt]ogo)|([Tt]okelau)|([Tt]onga)|([Tt]rinidad\s+[Aa]nd\s+[Tt]obago)|([Tt]unisia)|([Tt][uü]rk(ey|iye))|([Tt]urkmenistan)|([Tt]urks\s+[Aa]nd\s+[Cc]aicos\s+[Ii]slands)|([Tt]uvalu)|([Uu]ganda)|([Uu]kraine)|(UAE|[Uu]nited\s+[Aa]rab\s+[Ee]mirates)|(U[.]?K[.]?|[Bb]ritain|[Gg]reat\s+[BBb]ritain|[Uu]nited\s+[Kk]ingdom(\s+[Oo]f\s+[Gg]reat\s+[Bb]ritain\s+[Aa]nd\s+[Nn]orthern\s+[Ii]reland)?|[Ee]ngland(\s+[Aa]nd\s+[Ww]ales)?)|([Uu]nited\s+[Ss]tates\s+[Mm]inor\s+[Oo]utlying\s+[Ii]slands)|(U[.]?S[.]?A[.]?|[Uu]nited\s+[Ss]tates(\s+[Oo]f\s+[Aa]merica)?)|([Uu]ruguay)|([Uu]zbekistan)|([Vv]anuatu)|([Vv]enezuela)|([Vv]iet\s+[Nn]am)|([Bb]ritish\s+[Vv]irgin\s+[Ii]slands|[Vv]irgin\s+[Ii]slands,?\s+[Bb]ritish)|([Ww]allis\s+[Aa]nd\s+[Ff]utuna)|([Ww]estern\s+[Ss]ahara*)|([Yy]emen)|([Zz]ambia)|([Zz]imbabwe)|([Uu]nknown))[ \t\n\r]*$")
237
+
238
+ edgarProvCountryCodes = ("B5", "GU", "PR", "2J", "VI", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "B0", "B2", "Y6", "B3", "B4", "B5", "B6", "B7", "1A", "B8", "B9", "C1", "1B", "1C", "C3", "C4", "1D", "C5", "C6", "C7", "C8", "1F", "C9", "D1", "G6", "D0", "D2", "D3", "1E", "B1", "D4", "D5", "D6", "D9", "E0", "X2", "E2", "E8", "E3", "E4", "Z4", "E9", "F0", "F2", "F3", "F4", "F6", "F7", "F8", "F9", "Y3", "G0", "G1", "G2", "L7", "1M", "G3", "G4", "2N", "G7", "1G", "G9", "G8", "H1", "H2", "H3", "H4", "1J", "1H", "H5", "H7", "H6", "H8", "H9", "I0", "I3", "I4", "2C", "I5", "I6", "2Q", "2M", "J0", "J1", "J3", "J4", "J5", "J6", "J8", "Y7", "J9", "S0", "K0", "K1", "K4", "X4", "K2", "K3", "K5", "K6", "K7", "K8", "K9", "L0", "L2", "Y8", "L3", "L6", "L8", "M0", "Y9", "M2", "1P", "M3", "J2", "M4", "M5", "M6", "1N", "M7", "1R", "M8", "M9", "N0", "N1", "N2", "1Q", "N4", "N5", "N6", "N7", "N8", "N9", "O0", "O1", "1T", "O2", "O3", "O4", "2P", "O5", "1K", "1S", "O9", "P0", "Z5", "P1", "P2", "P3", "E1", "T6", "P5", "P6", "P8", "P7", "1W", "Q2", "Q3", "Q4", "Q5", "Q6", "Q7", "1U", "1V", "Q8", "P4", "R0", "1Y", "1X", "R1", "R2", "R4", "R5", "R6", "R8", "R9", "S1", "S3", "S4", "S5", "1Z", "S6", "Z0", "U8", "U7", "U9", "Z1", "V0", "V1", "Y0", "S8", "S9", "T0", "T1", "Z2", "T2", "T8", "U0", "2B", "2A", "D7", "U1", "T3", "1L", "U3", "F1", "V2", "V3", "L9", "V6", "V7", "V8", "V9", "F5", "2D", "W0", "W1", "Z3", "W2", "W3", "W4", "W5", "W6", "W8", "2E", "W7", "2G", "W9", "2H", "C0", "X0", "2J", "X1", "X3", "2K", "2L", "X5", "Q1", "D8", "X8", "U5", "T7", "Y4", "Y5", "XX")
239
+
240
+ def edgarprovcountryen(arg):
241
+ edgarProvCountryMatch = edgarProvCountryNamePattern.match(arg)
242
+ if not edgarProvCountryMatch or len(arg.strip()) == 0:
243
+ raise FunctionArgType(1, "stateorcountrynameen lexical error")
244
+ try:
245
+ return edgarProvCountryCodes[codeIndex(edgarProvCountryMatch)]
246
+ except (IndexException, TypeError) as ex:
247
+ raise FunctionArgType(0, str(ex))
248
+
249
+ exchNamePattern = re_compile(r"^[ \t\n\r]*((([Tt]he\s+)?[Bb][Oo][Xx]\s+[Ee]xchange(,?\s+[Ll][Ll][Cc])?)|(([Tt]he\s+)?[Cc]boe\s+[Bb][Yy][Xx]\s+[Ee]xchange(,?\s+[Ii]nc[.]?)?)|(([Tt]he\s+)?[Cc]boe\s+[Bb][Zz][Xx]\s+[Ee]xchange(,?\s+[Ii]nc[.]?)?)|(([Tt]he\s+)?[Cc]boe\s+[Cc]2\s+[Ee]xchange(,?\s+[Ii]nc[.]?)?)|(([Tt]he\s+)?[Cc]boe\s+[Ee][Dd][Gg][Aa]\s+[Ee]xchange(,?\s+[Ii]nc[.]?)?)|(([Tt]he\s+)?[Cc]boe\s+[Ee][Dd][Gg][Xx]\s+[Ee]xchange(,?\s+[Ii]nc[.]?)?)|(([Tt]he\s+)?[Cc]boe\s+[Ee]xchange(,?\s+[Ii]nc[.]?)?)|(([Tt]he\s+)?[Cc]hicago\s+[Ss]tock\s+[Ee]xchange(,?\s+[Ii]nc[.]?)?)|(([Tt]he\s+)?[Ii]nvestors\s+[Ee]xchange(,?\s+[Ll][Ll][Cc])?)|(([Tt]he\s+)?[Mm]iami\s+[Ii]nternational\s+[Ss]ecurities\s+[Ee]xchange(,?\s+[Ll][Ll][Cc])?)|(([Tt]he\s+)?[Mm]IAX\s+[Pp]EARL(,?\s+[Ll][Ll][Cc])?)|(([Tt]he\s+)?[Nn][Aa][Ss][Dd][Aa][Qq]\s+[Bb][Xx](,?\s+[Ii]nc[.]?)?)|(([Tt]he\s+)?[Nn][Aa][Ss][Dd][Aa][Qq]\s+[Gg][Ee][Mm][Xx](,?\s+[Ll][Ll][Cc])?)|(([Tt]he\s+)?[Nn][Aa][Ss][Dd][Aa][Qq]\s+[Ii][Ss][Ee](,?\s+[Ll][Ll][Cc])?)|(([Tt]he\s+)?[Nn][Aa][Ss][Dd][Aa][Qq]\s+[Mm][Rr][Xx](,?\s+[Ll][Ll][Cc])?)|([Nn][Aa][Ss][Dd][Aa][Qq]\s+[Pp][Hh][Ll][Xx](,?\s+[Ll][Ll][Cc])?)|(([Tt]he\s+)?[Nn][Yy][Ss][Ee]|([Tt]he\s+)?[Nn]ew\s+[Yy]ork\s+[Ss]tock\s+[Ee]xchange(,?\s+[Ll][Ll][Cc])?)|(([Tt]he\s+)?[Nn][Yy][Ss][Ee]\s+[Aa]merican(,?\s+[Ll][Ll][Cc])?)|(([Tt]he\s+)?[Nn][Yy][Ss][Ee]\s+[Aa]rca(,?\s+[Ii]nc[.]?)?)|(([Tt]he\s+)?[Nn][Yy][Ss][Ee]\s+[Nn]ational(,?\s+[Ii]nc[.]?)?)|(([Tt]he\s+)?[Nn][Aa][Ss][Dd][Aa][Qq](\s+([Ss]tock|[Gg]lobal(\s+[Ss]elect)?)\s+[Mm]arket(,?\s+[Ll][Ll][Cc])?)?))[ \t\n\r]*$")
250
+
251
+ exchCodes = ("BOX", "CboeBYX", "CboeBZX", "C2", "CboeEDGA", "CboeEDGX", "CBOE", "CHX", "IEX", "MIAX", "PEARL", "BX", "GEMX", "ISE", "MRX", "Phlx", "NYSE", "NYSEAMER", "NYSEArca", "NYSENAT", "NASDAQ")
252
+
253
+ def exchnameen(arg):
254
+ exchMatch = exchNamePattern.match(arg)
255
+ if not exchMatch or len(arg.strip()) == 0:
256
+ raise FunctionArgType(1, "exchnameen lexical error")
257
+ try:
258
+ return exchCodes[codeIndex(exchMatch)]
259
+ except (IndexException, TypeError) as ex:
260
+ raise FunctionArgType(0, str(ex))
261
+
262
+ entityFilerNamePattern = re_compile(r"^[ \t\n\r]*(([Ll]arge\s+[Aa]ccelerated\s+[Ff]iler)|([Aa]ccelerated\s+[Ff]iler)|([Nn]on[^\w]+[Aa]ccelerated\s+[Ff]iler))[ \t\n\r]*$")
263
+
264
+ entityFilerCodes = ("Large Accelerated Filer", "Accelerated Filer", "Non-accelerated Filer")
265
+
266
+
267
+ def entityfilercategoryen(arg):
268
+ entityFilerMatch = entityFilerNamePattern.match(arg)
269
+ if not entityFilerMatch or len(arg.strip()) == 0:
270
+ raise FunctionArgType(1, "entityfilercategoryen lexical error")
271
+ try:
272
+ return entityFilerCodes[codeIndex(entityFilerMatch)]
273
+ except (IndexException, TypeError) as ex:
274
+ raise FunctionArgType(0, str(ex))
275
+
276
+ def loadSECtransforms(customTransforms, *args, **kwargs):
277
+ ixtSEC = "http://www.sec.gov/inlineXBRL/transformation/2015-08-31"
278
+ customTransforms.update({
279
+ qname(ixtSEC, "ixt-sec:duryear"): duryear,
280
+ qname(ixtSEC, "ixt-sec:durmonth"): durmonth,
281
+ qname(ixtSEC, "ixt-sec:durweek"): durweek,
282
+ qname(ixtSEC, "ixt-sec:durday"): durday,
283
+ qname(ixtSEC, "ixt-sec:durhour"): durhour,
284
+ qname(ixtSEC, "ixt-sec:datequarterend"): datequarterend,
285
+ qname(ixtSEC, "ixt-sec:numinf"): numinf,
286
+ qname(ixtSEC, "ixt-sec:numneginf"): numneginf,
287
+ qname(ixtSEC, "ixt-sec:numnan"): numnan,
288
+ qname(ixtSEC, "ixt-sec:numwordsen"): numwordsen,
289
+ qname(ixtSEC, "ixt-sec:durwordsen"): durwordsen,
290
+ qname(ixtSEC, "ixt-sec:boolballotbox"): boolballotbox,
291
+ qname(ixtSEC, "ixt-sec:yesnoballotbox"): yesnoballotbox,
292
+ qname(ixtSEC, "ixt-sec:countrynameen"): countrynameen,
293
+ qname(ixtSEC, "ixt-sec:stateprovnameen"): stateprovnameen,
294
+ qname(ixtSEC, "ixt-sec:edgarprovcountryen"): edgarprovcountryen,
295
+ qname(ixtSEC, "ixt-sec:exchnameen"): exchnameen,
296
+ qname(ixtSEC, "ixt-sec:entityfilercategoryen"): entityfilercategoryen
297
+ })
298
+
299
+ __pluginInfo__ = {
300
+ 'name': 'SEC Inline Transforms',
301
+ 'version': '19.2', # SEC version
302
+ 'description': "This plug-in adds custom transforms SEC inline filing with durations. ",
303
+ 'license': 'Apache-2',
304
+ 'author': f'SEC employees (integrated by {authorLabel})',
305
+ 'copyright': f'{copyrightLabel} \nUtilizes text2num.py (c) 2008 Greg Hewgill',
306
+ # classes of mount points (required)
307
+ 'ModelManager.LoadCustomTransforms': loadSECtransforms,
308
+ }
@@ -0,0 +1,39 @@
1
+ # SEC ixt-sec Transformation Test Cases
2
+
3
+ ## Introduction
4
+
5
+ This is a XBRL International style test suite to test SEC transformations and ensure they produce expected results or raise an error code.
6
+
7
+ The test cases are in the standard XBRL International transformation test case format and conforms to the tests.xsd schema provided by XBRL International with its transformation registry tests.
8
+
9
+ For display purposes, a simple XSLT 1.0 stylesheet is also included:
10
+ tests.xsl
11
+
12
+ * Two stylesheets, with accompanying bash wrapper scripts are provided:
13
+
14
+ * extract.sh (extractVariations.xsl) creates an XML file containing all valid
15
+ or all invalid test inputs with an xsi:type attribute indicating the input type.
16
+
17
+ * extractTestcase.sh (extractTestcase.xsl) extracts all test inputs and
18
+ expected outputs into an XBRL conformance suite test case.
19
+
20
+ * run
21
+
22
+ ## Testcase file format
23
+
24
+ The testcase file is a declarative representation that organizes the tests in a way that a test harness can run the tests.
25
+
26
+ The testcase element is the root element for a set of individual variations.
27
+
28
+ The testcase contains these elements:
29
+
30
+ * transform: A collection of tests for the transform @name with expected output type @outputType.
31
+ * variation: A single test for the transform provided by parent element @name.
32
+ * @input: Attribute with the string to be transformed.
33
+ * @output: Attribute with the xml value of the transformation result, if valid, else empty string.
34
+ * @result: Attribute with "valid" or "invalid", regarding validity of input to transformation.
35
+ * @description: An optional attribute for this test variation
36
+
37
+ ### Operation with Arelle
38
+
39
+
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ java -jar saxon9.jar tests.xml extractTestcase.xsl > testcase.xml
@@ -0,0 +1,109 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <xsl:stylesheet
3
+ version="1.0"
4
+ xmlns:case="http://xbrl.org/2011/conformance-rendering/transforms"
5
+ xmlns:ixt="http://www.xbrl.org/inlineXBRL/transformation/WGWD/YYYY-MM-DD"
6
+ xmlns:reg="http://xbrl.org/2008/registry"
7
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
8
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
10
+ xmlns:func="http://xbrl.org/2008/function"
11
+
12
+ >
13
+ <xsl:output indent="yes"/>
14
+ <xsl:param name="result"/>
15
+ <xsl:template match="/">
16
+ <testcase xmlns="http://xbrl.org/2008/conformance"
17
+ xmlns:reg="http://xbrl.org/2008/registry"
18
+ xmlns:cfcn="http://xbrl.org/2008/conformance/function"
19
+ xmlns:ixt-sec="http://www.sec.gov/inlineXBRL/transformation/2015-08-31"
20
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
21
+ xmlns:xhtml="http://www.w3.org/1999/xhtml"
22
+ xmlns:xlink="http://www.w3.org/1999/xlink"
23
+ xmlns:xqt-err="http://www.w3.org/2005/xqt-errors"
24
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
25
+ >
26
+
27
+ <owners>
28
+ <reg:owner id="herm">
29
+ <reg:name>Herm Fischer</reg:name>
30
+ <reg:affiliation>Mark V Systems Limited</reg:affiliation>
31
+ <reg:email>fischer@markv.com</reg:email>
32
+ <reg:assumedOwnership moment="2014-09-18T12:00:00" />
33
+ </reg:owner>
34
+ </owners>
35
+
36
+ <number>1</number>
37
+
38
+ <name>Function tests for Transformation Registry 3</name>
39
+
40
+ <documentation>
41
+ <xhtml:p>XII formula-formatted test case for ixt transforms in version 3 registry</xhtml:p>
42
+ </documentation>
43
+
44
+ <xsl:for-each select="case:testcase/case:transform">
45
+ <xsl:variable name="transformName" select="@name"/>
46
+ <xsl:variable name="transformType" select="@type"/>
47
+ <xsl:variable name="transformNum" select="position()"/>
48
+
49
+ <xsl:for-each select="case:variation">
50
+ <xsl:variable name="input" select="@input"/>
51
+ <xsl:variable name="output" select="@output"/>
52
+ <xsl:variable name="result" select="@result"/>
53
+ <xsl:variable name="description" select="@description"/>
54
+ <xsl:variable name="variationNum" select="position()"/>
55
+
56
+ <variation id="V-01">
57
+ <xsl:attribute name="id">
58
+ <xsl:value-of select="concat( 'V-', $transformNum, '-', $variationNum )"/>
59
+ </xsl:attribute>
60
+ <name>
61
+ <xsl:choose>
62
+ <xsl:when test="boolean($description)">
63
+ <xsl:value-of select="$description"/>
64
+ </xsl:when>
65
+ <xsl:otherwise>
66
+ <xsl:value-of select="
67
+ concat( $transformName, '(&quot;', $input, '&quot;)' )
68
+ "/>
69
+ </xsl:otherwise>
70
+ </xsl:choose>
71
+ </name>
72
+ <inputs>
73
+ <cfcn:call>
74
+ <xsl:value-of select="
75
+ concat( $transformName, '(&quot;', $input, '&quot;)' )
76
+ "/>
77
+ </cfcn:call>
78
+ </inputs>
79
+ <outputs>
80
+ <xsl:choose>
81
+ <xsl:when test="$result = 'valid'">
82
+ <cfcn:test>
83
+ <xsl:value-of select="
84
+ concat( '$result eq &quot;', $output, '&quot;' )
85
+ "/>
86
+ </cfcn:test>
87
+ </xsl:when>
88
+ <xsl:otherwise>
89
+ <error>xqt-err:XPTY0004</error>
90
+ </xsl:otherwise>
91
+ </xsl:choose>
92
+ </outputs>
93
+ </variation>
94
+ </xsl:for-each>
95
+ </xsl:for-each>
96
+ <revisions>
97
+ <revision by="Makefile">
98
+ <xsl:attribute name="on">
99
+ <xsl:value-of select="current-dateTime()"/>
100
+ </xsl:attribute>
101
+ <xhtml:p>
102
+ Created the test case by xslt extraction from tests.xml.
103
+ </xhtml:p>
104
+ </revision>
105
+ </revisions>
106
+ </testcase>
107
+ </xsl:template>
108
+
109
+ </xsl:stylesheet>
@@ -0,0 +1,16 @@
1
+ #!/bin/bash
2
+
3
+ # re-generate arelle's formula-assertion-style testcase file from test.xml authoritative testcase file
4
+ java -jar saxon9.jar tests.xml extractTestcase.xsl > testcase.xml
5
+
6
+ # to run from source
7
+ ARELLE="python3.9 ../../../../../arelleCmdLine.py"
8
+
9
+ # to run from cx-frozen build (prod)
10
+ #ARELLE=/xbrldata/deployment-arelle/release/arelleCmdLine
11
+
12
+ # remove old log files
13
+ rm -f ~/temp/ixt-sec*
14
+
15
+ # run test cases
16
+ $ARELLE --plugins transforms/SEC -f testcase.xml -v --logFile ~/temp/ixt-sec.log --csvTestReport ~/temp/ixt-sec.xlsx