Source code for q2_sdk.hq.db.regex

"""Interacts with the Q2_Regex table"""

from argparse import _SubParsersAction
from functools import partial
from typing import List
from lxml.objectify import BoolElement, IntElement, StringElement
from .db_object import DbObject
from .representation_row_base import RepresentationRowBase


[docs] class RegexRow(RepresentationRowBase): RegexID: IntElement = "RegexID" FindStatement: StringElement = "FindStatement" ReplacementText: StringElement = "ReplacementText" IgnoreCase: BoolElement = "IgnoreCase" Description: StringElement = "Description" ShortName: StringElement = "ShortName"
[docs] class Regex(DbObject): GET_BY_NAME_KEY = "ShortName" NAME = "Regex" REPRESENTATION_ROW_CLASS = RegexRow
[docs] def add_arguments(self, parser: _SubParsersAction): subparser = parser.add_parser("get_regex") subparser.set_defaults(parser="get") subparser.set_defaults(func=partial(self.get, serialize_for_cli=True)) subparser.add_argument( "--no-trunc", action="store_true", help="Do not truncate FindStatement" )
[docs] async def get(self, no_trunc=False, serialize_for_cli=False) -> List[RegexRow]: response = await self.call_hq("sdk_GetRegex") truncate = not no_trunc if serialize_for_cli: fields_to_truncate = [] if truncate: fields_to_truncate = ["FindStatement"] columns = ["FindStatement", "ReplacementText", "IgnoreCase", "ShortName"] response = self.serialize_for_cli( response, columns, fields_to_truncate=fields_to_truncate ) return response