Skip to content

Commit dde774c

Browse files
committed
hxlquickmeta (#9): HXLMetaType class created
1 parent 7fd1ba1 commit dde774c

File tree

1 file changed

+70
-11
lines changed

1 file changed

+70
-11
lines changed

bin/hxlquickmeta

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ class HXLQuickMeta:
8686

8787
parser.add_argument(
8888
'--hxlquickmeta-hashtag',
89-
help='Output debug information for just one hashtag (without use files)',
89+
help='Output debug information for just one hashtag (inline)',
9090
# metavar='quickhashtag',
9191
default=None,
9292
nargs='?'
9393
)
9494

9595
parser.add_argument(
9696
'--hxlquickmeta-value',
97-
help='Output debug information for just one value (without use files)',
97+
help='Output debug information for just one value (inline)',
9898
# metavar='quickhashtag',
9999
default=None,
100100
nargs='?'
@@ -220,21 +220,22 @@ class HXLMeta:
220220
221221
222222
See also:
223-
- https://github.com/HXLStandard/libhxl-python/blob/master/hxl/datatypes.py
224-
- https://github.com/HXLStandard/libhxl-python/blob/master/hxl/model.py
225-
- https://github.com/HXLStandard/libhxl-python/blob/master/hxl/validation.py
223+
- github.com/HXLStandard/libhxl-python/blob/master/hxl/datatypes.py
224+
- github.com/HXLStandard/libhxl-python/blob/master/hxl/model.py
225+
- github.com/HXLStandard/libhxl-python/blob/master/hxl/validation.py
226226
"""
227227

228-
# From hxl.datatypes.TOKEN_PATTERN) # TODO: remove if not used
228+
# From libhxl v4.22, hxl.datatypes.TOKEN_PATTERN) # TODO: remove if unused
229229
TOKEN_PATTERN = r'[A-Za-z][_0-9A-Za-z]*'
230230
"""A regular expression matching a single string token.
231231
"""
232232

233-
# From hxl.datatypes._WHITESPACE_PATTERN
233+
# From libhxl v4.22, hxl.datatypes._WHITESPACE_PATTERN
234234
_WHITESPACE_PATTERN = re.compile(r'\s+', re.MULTILINE)
235235

236-
# From hxl.TagPattern.PATTERN # TODO: remove if not used
237-
PATTERN = r'^\s*#?({token}|\*)((?:\s*[+-]{token})*)\s*(!)?\s*$'.format(token=hxl.datatypes.TOKEN_PATTERN)
236+
# From libhxl v4.22, hxl.TagPattern.PATTERN # TODO: remove if not used
237+
PATTERN = r'^\s*#?({token}|\*)((?:\s*[+-]{token})*)\s*(!)?\s*$'.format(
238+
token=hxl.datatypes.TOKEN_PATTERN)
238239
"""Constant: regular expression to match a HXL tag pattern.
239240
"""
240241

@@ -790,7 +791,8 @@ class HXLMeta:
790791
self.data_columns = None
791792

792793
def _parse_heading(self, heading):
793-
# @see https://stackoverflow.com/questions/8270092/remove-all-whitespace-in-a-string
794+
# @see https://stackoverflow.com/questions/8270092/
795+
# remove-all-whitespace-in-a-string
794796
# pattern = re.compile(r'\s+')
795797
heading1 = re.sub(self._WHITESPACE_PATTERN, '', heading)
796798
return heading1
@@ -824,12 +826,69 @@ class HXLMeta:
824826
# header_original = next(csv_reader)
825827
# print('header_original', header_original)
826828

827-
# hxlquickmeta --hxlquickmeta-hashtag="#adm2+code" --hxlquickmeta-value="BR3106200"
829+
# hxlquickmeta --hxlquickmeta-hashtag="#adm2+code"
830+
# --hxlquickmeta-value="BR3106200"
828831
def get_hashtag_info(self, hashtag, value):
829832
print('hashtag', hashtag)
830833
print('hashtag._parse_heading', self._parse_heading(hashtag))
834+
print('hashtag.is_hashtag_base_valid',
835+
self.is_hashtag_base_valid(hashtag))
831836
print('value', value)
832837

838+
def is_hashtag_base_valid(self, term, strict=True):
839+
if strict:
840+
return hxl.datatypes.is_token(term)
841+
# @see docs.python.org/3/library/exceptions.html#exception-hierarchy
842+
raise NotImplementedError('Less strict validation not implemented')
843+
844+
845+
class HXLMetaType:
846+
"""
847+
HXLMetaType is a wrapper both to libhxl-python datatype-like functions and
848+
the new experimental ones used on HXLMeta
849+
850+
Author: Multiple Authors
851+
License: Public Domain
852+
Version: v0.6.6
853+
854+
See also:
855+
- github.com/HXLStandard/libhxl-python/blob/master/hxl/datatypes.py
856+
- github.com/HXLStandard/libhxl-python/blob/master/hxl/model.py
857+
- github.com/HXLStandard/libhxl-python/blob/master/hxl/validation.py
858+
"""
859+
860+
@staticmethod
861+
def libhxl_is_empty(value):
862+
return hxl.datatypes.is_empty(value)
863+
864+
@staticmethod
865+
def libhxl_is_date(value):
866+
return hxl.datatypes.is_date(value)
867+
868+
# @staticmethod
869+
# def libhxl_is_dict(value):
870+
# return hxl.datatypes.is_dict(value)
871+
872+
@staticmethod
873+
def libhxl_is_number(value):
874+
return hxl.datatypes.is_number(value)
875+
876+
@staticmethod
877+
def libhxl_is_string(value):
878+
return hxl.datatypes.is_string(value)
879+
880+
@staticmethod
881+
def libhxl_is_token(value):
882+
return hxl.datatypes.is_token(value)
883+
884+
@staticmethod
885+
def libhxl_is_truthy(value):
886+
return hxl.datatypes.is_truthy(value)
887+
888+
@staticmethod
889+
def libhxl_typeof(value):
890+
return hxl.datatypes.typeof(value)
891+
833892

834893
class HXLUtils:
835894
"""

0 commit comments

Comments
 (0)