Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
asn1-value-editor
Commits
009190c5
Commit
009190c5
authored
Aug 04, 2016
by
Maxime Perrotin
Browse files
Keep dash in VN parsed strings
parent
268ab8ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
asn1_value_editor/vn.py
View file @
009190c5
...
...
@@ -137,19 +137,19 @@ VALUE_LIST.setParseAction(lambda s, l, t: [t.asList()])
def
parseChoiceValue
(
s
,
l
,
t
):
''' Parsing CHOICE '''
choice
=
t
[
0
]
.
replace
(
'-'
,
'_'
)
choice
=
t
[
0
]
return
{
'Choice'
:
choice
,
choice
:
t
[
2
]}
choiceValue
.
setParseAction
(
parseChoiceValue
)
def
parseValueReference
(
s
,
l
,
t
):
''' Parsing ENUMERATED Id '''
value
=
t
[
0
]
#.replace('-', '_')
value
=
t
[
0
]
return
{
'Enum'
:
value
}
valuereference
.
setParseAction
(
parseValueReference
)
namedValue
.
setParseAction
(
lambda
s
,
l
,
t
:
{
t
[
0
]
.
replace
(
'-'
,
'_'
)
:
t
[
1
]})
namedValue
.
setParseAction
(
lambda
s
,
l
,
t
:
{
t
[
0
]:
t
[
1
]})
FloatingPointLiteral
.
setParseAction
(
lambda
s
,
l
,
t
:
float
(
t
[
0
]))
INT
.
setParseAction
(
lambda
s
,
l
,
t
:
int
(
t
[
0
]))
TRUE
.
setParseAction
(
lambda
s
,
l
,
t
:
True
)
...
...
@@ -181,17 +181,17 @@ def toASN1ValueNotation(val):
result
=
''
if
isinstance
(
val
,
dict
):
if
'Choice'
in
val
:
result
+=
val
[
'Choice'
].
replace
(
'_'
,
'-'
).
strip
()
+
':'
result
+=
val
[
'Choice'
].
strip
()
+
':'
result
+=
toASN1ValueNotation
(
val
[
val
[
'Choice'
]])
elif
'Enum'
in
val
:
result
+=
unicode
(
val
[
'Enum'
]).
replace
(
'_'
,
'-'
).
strip
()
result
+=
unicode
(
val
[
'Enum'
]).
strip
()
else
:
# SEQUENCE and SET
result
+=
' { '
needsComa
=
False
for
seqElem
in
val
:
if
needsComa
:
result
+=
', '
result
+=
seqElem
.
replace
(
'_'
,
'-'
).
strip
()
+
' '
result
+=
seqElem
.
strip
()
+
' '
result
+=
toASN1ValueNotation
(
val
[
seqElem
])
needsComa
=
True
result
+=
' }'
...
...
test/pytest/test_valuegenerator.py
View file @
009190c5
...
...
@@ -78,7 +78,7 @@ def test_random_simpleseq(qtbot):
def
test_random_simplechoice
(
qtbot
):
''' Test CHOICE. '''
typeName
=
"Type-SingleChoice"
for
i
in
range
(
100
0
):
for
i
in
range
(
100
):
result
=
compute_random_value
(
pool
[
typeName
],
pool
)
if
'choice-B'
in
result
:
assert
'TRUE'
in
result
or
'FALSE'
in
result
...
...
@@ -93,7 +93,7 @@ def test_random_simplechoice(qtbot):
def
test_random_simpleseqof
(
qtbot
):
''' Test SEQOF '''
typeName
=
"Type-SingleSeqOf"
for
i
in
range
(
100
0
):
for
i
in
range
(
100
):
result
=
compute_random_value
(
pool
[
typeName
],
pool
)
value
=
parse_gser
(
'result'
,
result
)[
'result'
]
assert
0
<=
len
(
value
)
<=
5
...
...
@@ -104,7 +104,7 @@ def test_random_simpleseqof(qtbot):
def
test_random_mydata
(
qtbot
):
''' Test more complex sequence '''
typeName
=
"MyData"
for
i
in
range
(
10
00
):
for
i
in
range
(
10
):
result
=
compute_random_value
(
pool
[
typeName
],
pool
)
value
=
parse_gser
(
'result'
,
result
)[
'result'
]
assert
type
(
value
)
is
list
and
1
<=
len
(
value
)
<=
10
...
...
@@ -118,7 +118,7 @@ def test_random_mydata(qtbot):
def
test_random_seq2
(
qtbot
):
''' Test more complex sequence '''
typeName
=
"Type-Seq"
for
i
in
range
(
10
00
):
for
i
in
range
(
10
):
result
=
compute_random_value
(
pool
[
typeName
],
pool
)
value
=
parse_gser
(
'result'
,
result
)[
'result'
]
assert
'item-a'
in
value
and
'item-b'
in
value
and
'item-C'
in
value
\
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment