[Python] Why does my GeneralizedTime pyasn1 implementation report 'SyntaxError: invalid...

Discussão em 'Python' iniciado por Stack, Abril 22, 2025.

  1. Stack

    Stack Membro Participativo

    Here is my asn1 grammar representation:

    MiepPullWtdr ::= [0] SEQUENCE
    {
    timeStamp [8] GeneralizedTime
    }


    I need help in implementing the same using pyasn1.

    Here is my code snippet:

    from pyasn1.type import univ, namedtype, tag, char, namedval, useful

    class MiepPullWtdr(univ.Sequence):
    componentType = namedtype.NamedTypes(namedtype.NamedType('timeStamp', useful.GeneralizedTime().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 8)))

    )

    miepPullWtdr = MiepPullWtdr()
    miepPullWtdr.setComponentByName('timeStamp', '201103081200Z')
    print(miepPullWtdr.prettyPrint())


    I also tried:

    componentType = namedtype.NamedTypes(namedtype.NamedType('timeStamp',useful.GeneralizedTime().tagSet(tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 8)))


    Both doesn't work and gives a weird error regrading Syntax error:

    miepPullWtdr = MiepPullWtdr()
    ^
    SyntaxError: invalid syntax


    I have checked the commas and brackets. All seem to be correct.

    Continue reading...

Compartilhe esta Página