<commit_before>"""
Support for basic EPP frame construction and parsing.
"""

from neuemux import xmlutils


ROOT = 'urn:ietf:params:xml:ns:epp-1.0'

HELLO = (
    '<?xml version="1.0" encoding="UTF-8"?>'
    '<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"><hello/></epp>'
)

LOGOUT = (
    '<?xml version="1.0" encoding="UTF-8"?>'
    '<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">'
    '<command><logout/><clTRID>neuemux-logout</clTRID></command>'
    '</epp>'
)


def login(uname, pwd, objs=(), exts=(), lang='en'):
    """
    Construct a login frame.
    """
    xml = xmlutils.XMLBuilder()
    with xml.within('epp', xmlns=ROOT):
        with xml.within('command'):
            with xml.within('login'):
                xml.tag('clID', uname)
                xml.tag('pw', pwd)
                with xml.within('options'):
                    xml.tag('version', '1.0')
                    xml.tag('lang', lang)
                with xml.within('svcs'):
                    for obj in objs:
                        xml.tag('objURI', obj)
                    with xml.within('svcExtension'):
                        for ext in exts:
                            xml.tag('extURI', ext)
            xml.tag('clTRID', 'neuemux-login')
    return xml.as_string()<commit_msg>Need both login and logout frames to have unique TRIDs.<commit_after>"""
Support for basic EPP frame construction and parsing.
"""

import uuid

from neuemux import xmlutils


ROOT = 'urn:ietf:params:xml:ns:epp-1.0'

HELLO = (
    '<?xml version="1.0" encoding="UTF-8"?>'
    '<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"><hello/></epp>'
)


def login(uname, pwd, objs=(), exts=(), lang='en', trid=None):
    """
    Construct a login frame.
    """
    if trid is None:
        trid = uuid.uuid1()

    xml = xmlutils.XMLBuilder()
    with xml.within('epp', xmlns=ROOT):
        with xml.within('command'):
            with xml.within('login'):
                xml.tag('clID', uname)
                xml.tag('pw', pwd)
                with xml.within('options'):
                    xml.tag('version', '1.0')
                    xml.tag('lang', lang)
                with xml.within('svcs'):
                    for obj in objs:
                        xml.tag('objURI', obj)
                    with xml.within('svcExtension'):
                        for ext in exts:
                            xml.tag('extURI', ext)
            xml.tag('clTRID', trid)
    return xml.as_string()


def logout(trid=None):
    """
    Construct a logout frame.
    """
    if trid is None:
        trid = uuid.uuid1()

    xml = xmlutils.XMLBuilder()
    with xml.within('epp', xmlns=ROOT):
        with xml.within('command'):
            xml.tag('logout')
            xml.tag('clTRID', trid)
    return xml.as_string()
{'fraction_non_alphanumeric': 0.16414141414141414, 'fraction_numerical': 0.009018759018759018, 'mean_word_length': 1.8676318510858325, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 3, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 55}, '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': '6492994', 'n_tokens_mistral': 939, 'n_tokens_neox': 897, 'n_words': 189}