<commit_before>"""
The code in this file was ported from javascript from the transperth website.

As I progress, I will attempt to whittle it down to purely what is absolutely
required.
"""

from collections import defaultdict
from pprint import pprint

# from .. import BASE
BASE = 'https://www.transperth.wa.gov.au/'

_async_post_back_control_client_IDs = set()
_post_back_control_client_IDs = set()
_update_panel_client_IDs = [
    "dnn_ctr2061_SmartRiderTransactions_pnlModuleMessagePanel",
    "dnn_ctr2061_SmartRiderTransactions_pnlSmartRiderBalancePanel",
    "dnn_ctr2061_SmartRiderTransactions_rgTransactionsPanel",
    "dnn_ctr2061_SmartRiderTransactions_rdFromDatePanel",
    "dnn_ctr2061_SmartRiderTransactions_rdToDatePanel",
    "RadAjaxManager1SU"
]
_update_panel_has_children_as_triggers = [True, True, True, True, True, True]
_update_panel_IDs = [
    "dnn$ctr2061$SmartRiderTransactions$pnlModuleMessagePanel",
    "dnn$ctr2061$SmartRiderTransactions$pnlSmartRiderBalancePanel",
    "dnn$ctr2061$SmartRiderTransactions$rgTransactionsPanel",
    "dnn$ctr2061$SmartRiderTransactions$rdFromDatePanel",
    "dnn$ctr2061$SmartRiderTransactions$rdToDatePanel",
    "RadAjaxManager1SU"
]
_create_post_back_settings = lambda c, b, a: {
    'async': c,
    'panelID': b,
    'sourceElement': a
}


_unique_ID_to_client_ID = lambda a: '_'.join(a.split('$'))


def _matches_parent_ID_in_list(c, b):
    for a in b:
        if (c.starts_with(a + "_")):
            return True
    return False


def _find_nearest_element(document, a):
    while a:
        d = _unique_ID_to_client_ID(a)
        c = document.get_element_by_id(d, None)

        if c is not None:
            return c

        if '$' not in a:
            return None

        a = '$'.join(
            a.split('$')[:-1]
        )

    return None


def _get_post_back_settings(document, a, c):
    d = a
    b = None
    while a is not None:
        if a.attrib['id']:
            if not b and a.attrib['id'] in _async_post_back_control_client_IDs:<commit_msg>Meaningful variables name for _find_nearest_element<commit_after>"""
The code in this file was ported from javascript from the transperth website.

As I progress, I will attempt to whittle it down to purely what is absolutely
required.
"""

from collections import defaultdict
from pprint import pprint

# from .. import BASE
BASE = 'https://www.transperth.wa.gov.au/'

_async_post_back_control_client_IDs = set()
_post_back_control_client_IDs = set()
_update_panel_client_IDs = [
    "dnn_ctr2061_SmartRiderTransactions_pnlModuleMessagePanel",
    "dnn_ctr2061_SmartRiderTransactions_pnlSmartRiderBalancePanel",
    "dnn_ctr2061_SmartRiderTransactions_rgTransactionsPanel",
    "dnn_ctr2061_SmartRiderTransactions_rdFromDatePanel",
    "dnn_ctr2061_SmartRiderTransactions_rdToDatePanel",
    "RadAjaxManager1SU"
]
_update_panel_has_children_as_triggers = [True, True, True, True, True, True]
_update_panel_IDs = [
    "dnn$ctr2061$SmartRiderTransactions$pnlModuleMessagePanel",
    "dnn$ctr2061$SmartRiderTransactions$pnlSmartRiderBalancePanel",
    "dnn$ctr2061$SmartRiderTransactions$rgTransactionsPanel",
    "dnn$ctr2061$SmartRiderTransactions$rdFromDatePanel",
    "dnn$ctr2061$SmartRiderTransactions$rdToDatePanel",
    "RadAjaxManager1SU"
]
_create_post_back_settings = lambda c, b, a: {
    'async': c,
    'panelID': b,
    'sourceElement': a
}


_unique_ID_to_client_ID = lambda a: '_'.join(a.split('$'))


def _matches_parent_ID_in_list(c, b):
    for a in b:
        if (c.starts_with(a + "_")):
            return True
    return False


def _find_nearest_element(document, target_id):
    while target_id:
        el_id = _unique_ID_to_client_ID(target_id)
        el = document.get_element_by_id(el_id, None)

        if el is not None:
            return el

        if '$' not in target_id:
            return None

        target_id = '$'.join(
            target_id.split('$')[:-1]
        )

    return None


def _get_post_back_settings(document, a, c):
    d = a
    b = None
    while a is not None:
        if a.attrib['id']:
            if not b and a.attrib['id'] in _async_post_back_control_client_IDs:
{'fraction_non_alphanumeric': 0.09320201777564256, 'fraction_numerical': 0.02065817919769397, 'mean_word_length': 3.9395017793594307, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2253307', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1472, 'n_words': 295}