Comments (4)
There are actually two cases, one where the default is for a defined type, and one for an inline enum.
Mysequence-with-enum ::= SEQUENCE
{
foo Myenum DEFAULT two,
bar ENUMERATED { a, b, c} DEFAULT c
}
I can fix the latter, but not the former.
--- a/asn1ate/pyasn1gen.py
+++ b/asn1ate/pyasn1gen.py
@@ -419,6 +419,8 @@ class Pyasn1Backend(object):
if t.optional:
return "namedtype.OptionalNamedType('%s', %s)" % (t.identifier, self.generate_expr(t.type_decl))
elif t.default_value is not None:
+ if _translate_type(t.type_decl.type_name) == 'univ.Enumerated':
+ t.default_value = '\'%s\'' % t.default_value
type_expr = self.generate_expr(t.type_decl)
type_expr += '.subtype(value=%s)' % _translate_value(t.default_value)
How to resolve a defined type to a single basic type?
from asn1ate.
I think you may be looking for sema.Module.resolve_type_decl
. That unravels a chain of declarations back to the built-in type.
from asn1ate.
I had some trouble making resolve_type_decl work. It turns out it doesn't unwrap objects that are tagged. I was able to work around this by manually unwrapping the tag (with .type_decl.type_decl), but it's not clear to me what the right way to do this is.
--- a/asn1ate/pyasn1gen.py
+++ b/asn1ate/pyasn1gen.py
@@ -419,6 +419,9 @@ class Pyasn1Backend(object):
if t.optional:
return "namedtype.OptionalNamedType('%s', %s)" % (t.identifier, self.generate_expr(t.type_decl))
elif t.default_value is not None:
+ xx = self.sema_module.resolve_type_decl(t.type_decl.type_decl, self.referenced_modules)
+ if _translate_type(xx.type_name) == 'univ.Enumerated':
+ t.default_value = '\'%s\'' % t.default_value
type_expr = self.generate_expr(t.type_decl)
type_expr += '.subtype(value=%s)' % _translate_value(t.default_value)
from asn1ate.
Hmm. It's not clear to me why you end up in inline_component_type
rather than inline_tagged_type
. Or is this code called from inline_tagged_type
? It's been too long since I thought about this code to be sure what's going on.
But your patch as-is will definitely break things for non-tagged types, I don't think any other sema-types have two levels of type_decl
members.
from asn1ate.
Related Issues (20)
- Fail to parse Kerberos ASN.1 HOT 17
- output missing size constaint HOT 6
- multi-module asn files don't work HOT 8
- Support for CLASS ... WITH SYNTAX ... HOT 6
- to support Brace value notation assignment HOT 4
- Emits invalid python for `BOOLEAN true` HOT 1
- Failure parsing minimal example with VisibleString HOT 3
- restricted_integer_type range constraint HOT 2
- Parsing Error: pyparsing.ParseException: Expected "DEFINITIONS" HOT 5
- resolve imported type declarations HOT 1
- KeyError: if the type is in another module. HOT 2
- single value and range constraint with both '..' and '|' HOT 3
- KeyError EXTERNAL HOT 6
- asn1ate generates incorrect code for DefaultedNamedType
- Feauture Request for 0.6.1: Parsing DEFAULT with structure HOT 1
- interdependent asn1 files to py files HOT 2
- asn1ate needs wheels HOT 9
- PyParsing issue (and work-around) HOT 4
- ParseException: Expected Keyword 'DEFINITIONS', found 'AUTOMATIC' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asn1ate.