avrotize 2.21.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. avrotize/__init__.py +66 -0
  2. avrotize/__main__.py +6 -0
  3. avrotize/_version.py +34 -0
  4. avrotize/asn1toavro.py +160 -0
  5. avrotize/avrotize.py +152 -0
  6. avrotize/avrotocpp/CMakeLists.txt.jinja +77 -0
  7. avrotize/avrotocpp/build.bat.jinja +7 -0
  8. avrotize/avrotocpp/build.sh.jinja +7 -0
  9. avrotize/avrotocpp/dataclass_body.jinja +108 -0
  10. avrotize/avrotocpp/vcpkg.json.jinja +21 -0
  11. avrotize/avrotocpp.py +483 -0
  12. avrotize/avrotocsharp/README.md.jinja +166 -0
  13. avrotize/avrotocsharp/class_test.cs.jinja +266 -0
  14. avrotize/avrotocsharp/dataclass_core.jinja +293 -0
  15. avrotize/avrotocsharp/enum_test.cs.jinja +20 -0
  16. avrotize/avrotocsharp/project.csproj.jinja +30 -0
  17. avrotize/avrotocsharp/project.sln.jinja +34 -0
  18. avrotize/avrotocsharp/run_coverage.ps1.jinja +98 -0
  19. avrotize/avrotocsharp/run_coverage.sh.jinja +149 -0
  20. avrotize/avrotocsharp/testproject.csproj.jinja +19 -0
  21. avrotize/avrotocsharp.py +1180 -0
  22. avrotize/avrotocsv.py +121 -0
  23. avrotize/avrotodatapackage.py +173 -0
  24. avrotize/avrotodb.py +1383 -0
  25. avrotize/avrotogo/go_enum.jinja +12 -0
  26. avrotize/avrotogo/go_helpers.jinja +31 -0
  27. avrotize/avrotogo/go_struct.jinja +151 -0
  28. avrotize/avrotogo/go_test.jinja +47 -0
  29. avrotize/avrotogo/go_union.jinja +38 -0
  30. avrotize/avrotogo.py +476 -0
  31. avrotize/avrotographql.py +197 -0
  32. avrotize/avrotoiceberg.py +210 -0
  33. avrotize/avrotojava/class_test.java.jinja +212 -0
  34. avrotize/avrotojava/enum_test.java.jinja +21 -0
  35. avrotize/avrotojava/testproject.pom.jinja +54 -0
  36. avrotize/avrotojava.py +2156 -0
  37. avrotize/avrotojs.py +250 -0
  38. avrotize/avrotojsons.py +481 -0
  39. avrotize/avrotojstruct.py +345 -0
  40. avrotize/avrotokusto.py +364 -0
  41. avrotize/avrotomd/README.md.jinja +49 -0
  42. avrotize/avrotomd.py +137 -0
  43. avrotize/avrotools.py +168 -0
  44. avrotize/avrotoparquet.py +208 -0
  45. avrotize/avrotoproto.py +359 -0
  46. avrotize/avrotopython/dataclass_core.jinja +241 -0
  47. avrotize/avrotopython/enum_core.jinja +87 -0
  48. avrotize/avrotopython/pyproject_toml.jinja +18 -0
  49. avrotize/avrotopython/test_class.jinja +97 -0
  50. avrotize/avrotopython/test_enum.jinja +23 -0
  51. avrotize/avrotopython.py +626 -0
  52. avrotize/avrotorust/dataclass_enum.rs.jinja +74 -0
  53. avrotize/avrotorust/dataclass_struct.rs.jinja +204 -0
  54. avrotize/avrotorust/dataclass_union.rs.jinja +105 -0
  55. avrotize/avrotorust.py +435 -0
  56. avrotize/avrotots/class_core.ts.jinja +140 -0
  57. avrotize/avrotots/class_test.ts.jinja +77 -0
  58. avrotize/avrotots/enum_core.ts.jinja +46 -0
  59. avrotize/avrotots/gitignore.jinja +34 -0
  60. avrotize/avrotots/index.ts.jinja +0 -0
  61. avrotize/avrotots/package.json.jinja +23 -0
  62. avrotize/avrotots/tsconfig.json.jinja +21 -0
  63. avrotize/avrotots.py +687 -0
  64. avrotize/avrotoxsd.py +344 -0
  65. avrotize/cddltostructure.py +1841 -0
  66. avrotize/commands.json +3496 -0
  67. avrotize/common.py +834 -0
  68. avrotize/constants.py +87 -0
  69. avrotize/csvtoavro.py +132 -0
  70. avrotize/datapackagetoavro.py +76 -0
  71. avrotize/dependencies/cpp/vcpkg/vcpkg.json +19 -0
  72. avrotize/dependencies/cs/net90/dependencies.csproj +29 -0
  73. avrotize/dependencies/go/go121/go.mod +6 -0
  74. avrotize/dependencies/java/jdk21/pom.xml +91 -0
  75. avrotize/dependencies/python/py312/requirements.txt +13 -0
  76. avrotize/dependencies/rust/stable/Cargo.toml +17 -0
  77. avrotize/dependencies/typescript/node22/package.json +16 -0
  78. avrotize/dependency_resolver.py +348 -0
  79. avrotize/dependency_version.py +432 -0
  80. avrotize/generic/generic.avsc +57 -0
  81. avrotize/jsonstoavro.py +2167 -0
  82. avrotize/jsonstostructure.py +2864 -0
  83. avrotize/jstructtoavro.py +878 -0
  84. avrotize/kstructtoavro.py +93 -0
  85. avrotize/kustotoavro.py +455 -0
  86. avrotize/openapitostructure.py +717 -0
  87. avrotize/parquettoavro.py +157 -0
  88. avrotize/proto2parser.py +498 -0
  89. avrotize/proto3parser.py +403 -0
  90. avrotize/prototoavro.py +382 -0
  91. avrotize/prototypes/any.avsc +19 -0
  92. avrotize/prototypes/api.avsc +106 -0
  93. avrotize/prototypes/duration.avsc +20 -0
  94. avrotize/prototypes/field_mask.avsc +18 -0
  95. avrotize/prototypes/struct.avsc +60 -0
  96. avrotize/prototypes/timestamp.avsc +20 -0
  97. avrotize/prototypes/type.avsc +253 -0
  98. avrotize/prototypes/wrappers.avsc +117 -0
  99. avrotize/structuretocddl.py +597 -0
  100. avrotize/structuretocpp/CMakeLists.txt.jinja +76 -0
  101. avrotize/structuretocpp/build.bat.jinja +3 -0
  102. avrotize/structuretocpp/build.sh.jinja +3 -0
  103. avrotize/structuretocpp/dataclass_body.jinja +50 -0
  104. avrotize/structuretocpp/vcpkg.json.jinja +11 -0
  105. avrotize/structuretocpp.py +697 -0
  106. avrotize/structuretocsharp/class_test.cs.jinja +180 -0
  107. avrotize/structuretocsharp/dataclass_core.jinja +156 -0
  108. avrotize/structuretocsharp/enum_test.cs.jinja +36 -0
  109. avrotize/structuretocsharp/json_structure_converters.cs.jinja +399 -0
  110. avrotize/structuretocsharp/program.cs.jinja +49 -0
  111. avrotize/structuretocsharp/project.csproj.jinja +17 -0
  112. avrotize/structuretocsharp/project.sln.jinja +34 -0
  113. avrotize/structuretocsharp/testproject.csproj.jinja +18 -0
  114. avrotize/structuretocsharp/tuple_converter.cs.jinja +121 -0
  115. avrotize/structuretocsharp.py +2295 -0
  116. avrotize/structuretocsv.py +365 -0
  117. avrotize/structuretodatapackage.py +659 -0
  118. avrotize/structuretodb.py +1125 -0
  119. avrotize/structuretogo/go_enum.jinja +12 -0
  120. avrotize/structuretogo/go_helpers.jinja +26 -0
  121. avrotize/structuretogo/go_interface.jinja +18 -0
  122. avrotize/structuretogo/go_struct.jinja +187 -0
  123. avrotize/structuretogo/go_test.jinja +70 -0
  124. avrotize/structuretogo.py +729 -0
  125. avrotize/structuretographql.py +502 -0
  126. avrotize/structuretoiceberg.py +355 -0
  127. avrotize/structuretojava/choice_core.jinja +34 -0
  128. avrotize/structuretojava/class_core.jinja +23 -0
  129. avrotize/structuretojava/enum_core.jinja +18 -0
  130. avrotize/structuretojava/equals_hashcode.jinja +30 -0
  131. avrotize/structuretojava/pom.xml.jinja +26 -0
  132. avrotize/structuretojava/tuple_core.jinja +49 -0
  133. avrotize/structuretojava.py +938 -0
  134. avrotize/structuretojs/class_core.js.jinja +33 -0
  135. avrotize/structuretojs/enum_core.js.jinja +10 -0
  136. avrotize/structuretojs/package.json.jinja +12 -0
  137. avrotize/structuretojs/test_class.js.jinja +84 -0
  138. avrotize/structuretojs/test_enum.js.jinja +58 -0
  139. avrotize/structuretojs/test_runner.js.jinja +45 -0
  140. avrotize/structuretojs.py +657 -0
  141. avrotize/structuretojsons.py +498 -0
  142. avrotize/structuretokusto.py +639 -0
  143. avrotize/structuretomd/README.md.jinja +204 -0
  144. avrotize/structuretomd.py +322 -0
  145. avrotize/structuretoproto.py +764 -0
  146. avrotize/structuretopython/dataclass_core.jinja +363 -0
  147. avrotize/structuretopython/enum_core.jinja +45 -0
  148. avrotize/structuretopython/map_alias.jinja +21 -0
  149. avrotize/structuretopython/pyproject_toml.jinja +23 -0
  150. avrotize/structuretopython/test_class.jinja +103 -0
  151. avrotize/structuretopython/test_enum.jinja +34 -0
  152. avrotize/structuretopython.py +799 -0
  153. avrotize/structuretorust/dataclass_enum.rs.jinja +63 -0
  154. avrotize/structuretorust/dataclass_struct.rs.jinja +121 -0
  155. avrotize/structuretorust/dataclass_union.rs.jinja +81 -0
  156. avrotize/structuretorust.py +714 -0
  157. avrotize/structuretots/class_core.ts.jinja +78 -0
  158. avrotize/structuretots/enum_core.ts.jinja +6 -0
  159. avrotize/structuretots/gitignore.jinja +8 -0
  160. avrotize/structuretots/index.ts.jinja +1 -0
  161. avrotize/structuretots/package.json.jinja +39 -0
  162. avrotize/structuretots/test_class.ts.jinja +35 -0
  163. avrotize/structuretots/tsconfig.json.jinja +21 -0
  164. avrotize/structuretots.py +740 -0
  165. avrotize/structuretoxsd.py +679 -0
  166. avrotize/xsdtoavro.py +413 -0
  167. avrotize-2.21.1.dist-info/METADATA +1319 -0
  168. avrotize-2.21.1.dist-info/RECORD +171 -0
  169. avrotize-2.21.1.dist-info/WHEEL +4 -0
  170. avrotize-2.21.1.dist-info/entry_points.txt +3 -0
  171. avrotize-2.21.1.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,12 @@
1
+ package {{ base_package }}
2
+
3
+ {%- if doc %}
4
+ // {{ doc }}
5
+ {%- endif %}
6
+ type {{ struct_name }} int
7
+
8
+ const (
9
+ {%- for symbol in symbols %}
10
+ {{ struct_name }}_{{ symbol }} {{ struct_name }} = {{ loop.index0 }}
11
+ {%- endfor %}
12
+ )
@@ -0,0 +1,31 @@
1
+ package {{ base_package }}
2
+
3
+ import (
4
+ "math/rand"
5
+ "time"
6
+ )
7
+
8
+ func init() {
9
+ rand.Seed(time.Now().UnixNano())
10
+ }
11
+
12
+ func Opt[T any](s T) *T {
13
+ return &s
14
+ }
15
+
16
+ {%- for struct in structs %}
17
+ func random{{ struct.name }}() {{ struct.name }} {
18
+ return {{ struct.name }} {
19
+ {%- for field in struct.fields %}
20
+ {{ field.name }}: {{ field.value }},
21
+ {%- endfor %}
22
+ }
23
+ }
24
+ {%- endfor %}
25
+
26
+ {%- for enum in enums %}
27
+ func random{{ enum.name }}() {{ enum.name }} {
28
+ return 0
29
+ }
30
+ {%- endfor %}
31
+
@@ -0,0 +1,151 @@
1
+ package {{ base_package }}
2
+
3
+ import (
4
+ {%- if "time.Time" in imports %}
5
+ "time"
6
+ {%- endif %}
7
+ {%- if json_annotation %}
8
+ "encoding/json"
9
+ {%- endif %}
10
+ {%- if json_annotation or avro_annotation %}
11
+ "compress/gzip"
12
+ "bytes"
13
+ "fmt"
14
+ "io"
15
+ "strings"
16
+ {%- endif %}
17
+ {%- if avro_annotation %}
18
+ "github.com/hamba/avro/v2"
19
+ {%- endif %}
20
+ {%- for ref_pkg in referenced_packages %}
21
+ "{{ ref_pkg }}"
22
+ {%- endfor %}
23
+ )
24
+
25
+ {%- if doc %}
26
+ // {{ doc }}
27
+ {%- endif %}
28
+ type {{ struct_name }} struct {
29
+ {%- for field in fields %}
30
+ {{ field.name }} {{ field.type }}{% if json_annotation or avro_annotation %} `{%- if json_annotation -%}json:"{{ field.original_name }}"{%- endif %}{%- if avro_annotation -%} avro:"{{ field.original_name }}"{%- endif -%}`{% endif %}
31
+ {%- endfor %}
32
+ }
33
+
34
+ {%- if avro_annotation %}
35
+ var {{ struct_name }}Schema, _ = avro.Parse(`{{ avro_schema }}`)
36
+ {% endif %}
37
+
38
+ {%- if json_annotation or avro_annotation %}
39
+ func (s *{{ struct_name }}) ToByteArray(contentType string) ([]byte, error) {
40
+ var result []byte
41
+ var err error
42
+ mediaType := strings.Split(contentType, ";")[0]
43
+ switch mediaType {
44
+ {%- if json_annotation %}
45
+ case "application/json":
46
+ result, err = json.Marshal(s)
47
+ if err != nil {
48
+ return nil, err
49
+ }
50
+ {%- endif %}
51
+ {%- if avro_annotation %}
52
+ case "avro/binary", "application/vnd.apache.avro+avro":
53
+ result, err = avro.Marshal({{ struct_name }}Schema, s)
54
+ if err != nil {
55
+ return nil, err
56
+ }
57
+ {%- endif %}
58
+ default:
59
+ return nil, fmt.Errorf("unsupported media type: %s", mediaType)
60
+ }
61
+ if strings.HasSuffix(mediaType, "+gzip") {
62
+ var buf bytes.Buffer
63
+ gzipWriter := gzip.NewWriter(&buf)
64
+ _, err = gzipWriter.Write(result)
65
+ if err != nil {
66
+ return nil, err
67
+ }
68
+ err = gzipWriter.Close()
69
+ if err != nil {
70
+ return nil, err
71
+ }
72
+ result = buf.Bytes()
73
+ }
74
+ return result, nil
75
+ }
76
+
77
+ func {{ struct_name }}FromData(data interface{}, contentType string) (*{{ struct_name }}, error) {
78
+ var err error
79
+ var s {{ struct_name }}
80
+ mediaType := strings.Split(contentType, ";")[0]
81
+ if strings.HasSuffix(mediaType, "+gzip") {
82
+ var reader io.Reader
83
+ switch v := data.(type) {
84
+ case []byte:
85
+ reader = bytes.NewReader(v)
86
+ case io.Reader:
87
+ reader = v
88
+ default:
89
+ return nil, fmt.Errorf("unsupported data type for gzip: %T", data)
90
+ }
91
+ gzipReader, err := gzip.NewReader(reader)
92
+ if err != nil {
93
+ return nil, err
94
+ }
95
+ defer gzipReader.Close()
96
+ data, err = io.ReadAll(gzipReader)
97
+ if err != nil {
98
+ return nil, err
99
+ }
100
+ }
101
+ switch mediaType {
102
+ {%- if json_annotation %}
103
+ case "application/json":
104
+ switch v := data.(type) {
105
+ case []byte:
106
+ err = json.Unmarshal(v, &s)
107
+ case string:
108
+ err = json.Unmarshal([]byte(v), &s)
109
+ case io.Reader:
110
+ err = json.NewDecoder(v).Decode(&s)
111
+ default:
112
+ return nil, fmt.Errorf("unsupported data type for JSON: %T", data)
113
+ }
114
+ {%- endif %}
115
+ {%- if avro_annotation %}
116
+ case "avro/binary", "application/vnd.apache.avro+avro":
117
+ switch v := data.(type) {
118
+ case []byte:
119
+ err = avro.Unmarshal({{ struct_name }}Schema, v, &s)
120
+ case io.Reader:
121
+ rawData, err := io.ReadAll(v)
122
+ if err != nil {
123
+ return nil, err
124
+ }
125
+ err = avro.Unmarshal({{ struct_name }}Schema, rawData, &s)
126
+ default:
127
+ return nil, fmt.Errorf("unsupported data type for Avro: %T", data)
128
+ }
129
+ {%- endif %}
130
+ default:
131
+ return nil, fmt.Errorf("unsupported media type: %s", mediaType)
132
+ }
133
+ if err != nil {
134
+ return nil, err
135
+ }
136
+ return &s, nil
137
+ }
138
+ {%- endif %}
139
+
140
+ {%- if json_annotation %}
141
+ func (s *{{ struct_name }}) IsJsonMatch(node map[string]interface{}) bool {
142
+ {%- for clause in json_match_predicates %}
143
+ {{ clause }}
144
+ {%- endfor %}
145
+ return true
146
+ }
147
+ {%- endif %}
148
+
149
+ func (s *{{ struct_name }}) ToObject() interface{} {
150
+ return s
151
+ }
@@ -0,0 +1,47 @@
1
+ package {{ base_package }}
2
+
3
+ import (
4
+ "testing"
5
+ )
6
+
7
+ func Test{{ struct_name }}_Instantiate(t *testing.T) {
8
+ random{{ struct_name }}()
9
+ }
10
+
11
+ {%- if kind == "struct" and (json_annotation or avro_annotation) %}
12
+
13
+ func Test{{ struct_name }}_ToByteArray(t *testing.T) {
14
+ s := random{{ struct_name }}()
15
+ {%- if json_annotation %}
16
+ _, err := s.ToByteArray("application/json")
17
+ if err != nil {
18
+ t.Errorf("ToByteArray failed: %v", err)
19
+ }
20
+ {%- endif %}
21
+ {%- if avro_annotation %}
22
+ _, err := s.ToByteArray("avro/binary")
23
+ if err != nil {
24
+ t.Errorf("ToByteArray failed: %v", err)
25
+ }
26
+ {%- endif %}
27
+ }
28
+
29
+ func Test{{ struct_name }}_FromData(t *testing.T) {
30
+ input := random{{struct_name}}()
31
+ {%- if json_annotation %}
32
+ dataj, _ := input.ToByteArray("application/json")
33
+ _, err := {{struct_name}}FromData(dataj, "application/json")
34
+ if err != nil {
35
+ t.Errorf("FromData failed: %v", err)
36
+ }
37
+ {%- endif %}
38
+ {%- if avro_annotation %}
39
+ dataa, _ := input.ToByteArray("avro/binary")
40
+ _, err := {{struct_name}}FromData(dataa, "avro/binary")
41
+ if err != nil {
42
+ t.Errorf("FromData failed: %v", err)
43
+ }
44
+ {%- endif %}
45
+ }
46
+
47
+ {%- endif %}
@@ -0,0 +1,38 @@
1
+ package {{ base_package }}
2
+
3
+
4
+ type {{ union_class_name }} struct {
5
+ {%- for union_type in union_types %}
6
+ {{ union_type | pascal }} *{{ union_type }}
7
+ {%- endfor %}
8
+ }
9
+
10
+ func (u *{{ union_class_name }}) ToObject() interface{} {
11
+ if u == nil {
12
+ return nil
13
+ }
14
+ {%- for union_type in union_types %}
15
+ if u.{{ union_type | pascal }} != nil {
16
+ return u.{{ union_type | pascal }}
17
+ }
18
+ {%- endfor %}
19
+ return nil
20
+ }
21
+
22
+ {%- if json_annotation or avro_annotation %}
23
+ {%- endif %}
24
+
25
+ {%- if json_annotation %}
26
+ func (u *{{ union_class_name }}) IsJsonMatch(node map[string]interface{}) bool {
27
+ if u == nil {
28
+ return false
29
+ }
30
+ {%- for union_type in union_types %}
31
+ if u.{{ union_type | pascal }} != nil {
32
+ {{ get_is_json_match_clause(union_type | pascal, union_type) }}
33
+ return true
34
+ }
35
+ {%- endfor %}
36
+ return false
37
+ }
38
+ {%- endif %}