1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-12-28 05:29:48 +00:00

Add py-ttp 0.5.0

TTP is a Python library for semi-structured text parsing using templates.

In essence, TTP can help to:
- Prepare, sort and load text data for parsing
- Parse text using regexes dynamically derived out of templates
- Process matches on the fly using broad set of built-in or custom functions
- Combine match results in a structure with arbitrary hierarchy
- Transform results in desired format to ease consumption by humans or machines
- Return results to various destinations for storage or further processing

WWW: https://github.com/dmulyalin/ttp
This commit is contained in:
Sunpoet Po-Chuan Hsieh 2020-10-15 19:59:36 +00:00
parent ea16882911
commit c3a639e21e
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=552444
7 changed files with 167 additions and 0 deletions

View File

@ -1414,6 +1414,7 @@
SUBDIR += py-transifex-client
SUBDIR += py-translationstring
SUBDIR += py-transpopy
SUBDIR += py-ttp
SUBDIR += py-ucl
SUBDIR += py-ufal.udpipe
SUBDIR += py-whoosh

27
textproc/py-ttp/Makefile Normal file
View File

@ -0,0 +1,27 @@
# Created by: Po-Chuan Hsieh <sunpoet@FreeBSD.org>
# $FreeBSD$
PORTNAME= ttp
PORTVERSION= 0.5.0
CATEGORIES= textproc python
MASTER_SITES= CHEESESHOP
PKGNAMEPREFIX= ${PYTHON_PKGNAMEPREFIX}
MAINTAINER= sunpoet@FreeBSD.org
COMMENT= Template Text Parser
LICENSE= MIT
USES= dos2unix python
USE_PYTHON= autoplist concurrent distutils
NO_ARCH= yes
.include <bsd.port.pre.mk>
.if ${PYTHON_REL} > 3000
post-patch:
@${RM} ${WRKSRC}/ttp/utils/load_python_exec_py2.py
.endif
.include <bsd.port.post.mk>

3
textproc/py-ttp/distinfo Normal file
View File

@ -0,0 +1,3 @@
TIMESTAMP = 1602780720
SHA256 (ttp-0.5.0.tar.gz) = bc5fc277f052b1c5f18faf10f4a944a55e12b4730556d916ac43578476d2ae11
SIZE (ttp-0.5.0.tar.gz) = 59510

View File

@ -0,0 +1,56 @@
--- ttp/match/ip.py.orig 2020-08-16 22:06:01 UTC
+++ ttp/match/ip.py
@@ -5,9 +5,9 @@ log = logging.getLogger(__name__)
def to_ip(data, *args):
# for py2 support need to convert data to unicode:
- if _ttp_["python_major_version"] is 2:
+ if _ttp_["python_major_version"] == 2:
ipaddr_data = unicode(data)
- elif _ttp_["python_major_version"] is 3:
+ elif _ttp_["python_major_version"] == 3:
ipaddr_data = data
if "ipv4" in args:
if "/" in ipaddr_data or " " in ipaddr_data:
@@ -33,9 +33,9 @@ def is_ip(data, *args):
def to_net(data, *args):
# for py2 support need to convert data to unicode:
- if _ttp_["python_major_version"] is 2:
+ if _ttp_["python_major_version"] == 2:
ipaddr_data = unicode(data)
- elif _ttp_["python_major_version"] is 3:
+ elif _ttp_["python_major_version"] == 3:
ipaddr_data = data
if "ipv4" in args:
return ipaddress.IPv4Network(ipaddr_data), None
@@ -124,21 +124,21 @@ def cidr_match(data, prefix):
check = ip_obj.network.overlaps(ip_net)
elif isinstance(ip_obj, ipaddress.IPv4Address) or isinstance(ip_obj, ipaddress.IPv6Address):
# if object is ipaddress, need to convert it into ipinterface with /32 mask:
- if ip_obj.version is 4:
+ if ip_obj.version == 4:
# for py2 support need to convert data to unicode:
- if _ttp_["python_major_version"] is 2:
+ if _ttp_["python_major_version"] == 2:
ipaddr_data = unicode("{}/32".format(str(ip_obj)))
- elif _ttp_["python_major_version"] is 3:
+ elif _ttp_["python_major_version"] == 3:
ipaddr_data = "{}/32".format(str(ip_obj))
ip_obj = ipaddress.IPv4Interface(ipaddr_data)
- elif ip_obj.version is 6:
+ elif ip_obj.version == 6:
# for py2 support need to convert data to unicode:
- if _ttp_["python_major_version"] is 2:
+ if _ttp_["python_major_version"] == 2:
ipaddr_data = unicode("{}/128".format(str(ip_obj)))
- elif _ttp_["python_major_version"] is 3:
+ elif _ttp_["python_major_version"] == 3:
ipaddr_data = "{}/128".format(str(ip_obj))
ip_obj = ipaddress.IPv6Interface(ipaddr_data)
check = ip_obj.network.overlaps(ip_net)
else:
check = None
- return data, check
\ No newline at end of file
+ return data, check

View File

@ -0,0 +1,20 @@
--- ttp/returners/terminal_returner.py.orig 2020-09-03 21:58:49 UTC
+++ ttp/returners/terminal_returner.py
@@ -31,13 +31,13 @@ def terminal_returner(data, **kwargs):
for yeallow_word in yeallow_words:
data = data.replace(yeallow_word, fttr.format(Y, yeallow_word, N))
# print output
- if _ttp_["python_major_version"] is 2:
+ if _ttp_["python_major_version"] == 2:
if isinstance(data, str) or isinstance(data, unicode):
print(data)
else:
print(str(data).replace('\\n', '\n'))
- elif _ttp_["python_major_version"] is 3:
+ elif _ttp_["python_major_version"] == 3:
if isinstance(data, str):
print(data)
else:
- print(str(data).replace('\\n', '\n'))
\ No newline at end of file
+ print(str(data).replace('\\n', '\n'))

View File

@ -0,0 +1,49 @@
--- ttp/utils/loaders.py.orig 2020-09-14 21:20:38 UTC
+++ ttp/utils/loaders.py
@@ -33,7 +33,7 @@ def load_files(path, extensions=[], filters=[], read=F
if os.path.isfile(path[:5000]):
if read:
try:
- if _ttp_["python_major_version"] is 2:
+ if _ttp_["python_major_version"] == 2:
with open(path, 'r') as file_obj:
return [('text_data', file_obj.read(),)]
with open(path, 'r', encoding='utf-8') as file_obj:
@@ -53,10 +53,10 @@ def load_files(path, extensions=[], filters=[], read=F
if read:
ret = []
for f in files:
- if _ttp_["python_major_version"] is 2:
+ if _ttp_["python_major_version"] == 2:
with open((path + f), 'r') as file_obj:
ret.append(('text_data', file_obj.read(),))
- elif _ttp_["python_major_version"] is 3:
+ elif _ttp_["python_major_version"] == 3:
with open((path + f), 'r', encoding='utf-8') as file_obj:
ret.append(('text_data', file_obj.read(),))
return ret
@@ -111,7 +111,7 @@ def _get_include_data(text_data, include):
return text_data
def load_ini(text_data, include=None, **kwargs):
- if _ttp_["python_major_version"] is 3:
+ if _ttp_["python_major_version"] == 3:
import configparser
cfgparser = configparser.ConfigParser()
# to make cfgparser keep the case, e.g. VlaN222 will not become vlan222:
@@ -132,7 +132,7 @@ def load_ini(text_data, include=None, **kwargs):
log.error("ttp_utils.load_struct: Python3, Unable to load ini formatted data\n'{}'".format(text_data))
# convert configparser object into dictionary
result = {k: dict(cfgparser.items(k)) for k in list(cfgparser.keys())}
- elif _ttp_["python_major_version"] is 2:
+ elif _ttp_["python_major_version"] == 2:
import ConfigParser
import StringIO
cfgparser = ConfigParser.ConfigParser()
@@ -217,4 +217,4 @@ def load_csv(text_data, include=None, **kwargs):
continue
temp = {headers[index]: i for index, i in enumerate(row)}
data[temp.pop(key)] = temp
- return data
\ No newline at end of file
+ return data

11
textproc/py-ttp/pkg-descr Normal file
View File

@ -0,0 +1,11 @@
TTP is a Python library for semi-structured text parsing using templates.
In essence, TTP can help to:
- Prepare, sort and load text data for parsing
- Parse text using regexes dynamically derived out of templates
- Process matches on the fly using broad set of built-in or custom functions
- Combine match results in a structure with arbitrary hierarchy
- Transform results in desired format to ease consumption by humans or machines
- Return results to various destinations for storage or further processing
WWW: https://github.com/dmulyalin/ttp