Skip to content

Commit 9ea74ce

Browse files
authored
any as bytes (#1390)
1 parent 0d6481e commit 9ea74ce

File tree

692 files changed

+2526
-185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

692 files changed

+2526
-185
lines changed

doc/source/_static/dpf_operators.html

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

src/ansys/dpf/core/any.py

Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
import ansys.dpf.core.server_types
1111
from ansys.dpf.core import server as server_module
1212
from ansys.dpf.core import errors
13+
from ansys.dpf.core.check_version import server_meet_version
1314
from ansys.dpf.core.common import type_to_internal_object_keyword
14-
from ansys.dpf.gate import any_abstract_api
15+
from ansys.dpf.gate import any_abstract_api, integral_types
1516

1617

1718
class Any:
@@ -48,8 +49,42 @@ def __init__(self, any_dpf=None, server=None):
4849
self._internal_type = None
4950
self._get_as_method = None
5051

52+
def _new_from_string(self, str):
53+
return self._new_from_string_as_bytes(str.encode('utf-8'))
54+
55+
@staticmethod
56+
def _get_as_string(self):
57+
out = Any._get_as_string_as_bytes(self)
58+
if out is not None and not isinstance(out, str):
59+
return out.decode('utf-8')
60+
return out
61+
5162
@staticmethod
52-
def _type_to_new_from_get_as_method(any_dpf):
63+
def _get_as_string_as_bytes(self):
64+
if server_meet_version("8.0", self._server):
65+
size = integral_types.MutableUInt64(0)
66+
return self._api.any_get_as_string_with_size(self, size)
67+
else:
68+
return self._api.any_get_as_string(self)
69+
70+
def _new_from_string_on_client(self, client, str):
71+
return self._new_from_string_as_bytes_on_client(client, str.encode('utf-8'))
72+
73+
def _new_from_string_as_bytes(self, str):
74+
if server_meet_version("8.0", self._server):
75+
size = integral_types.MutableUInt64(len(str))
76+
return self._api.any_new_from_string_with_size(str, size)
77+
else:
78+
return self._api.any_new_from_string(str)
79+
80+
def _new_from_string_as_bytes_on_client(self, client, str):
81+
if server_meet_version("8.0", self._server):
82+
size = integral_types.MutableUInt64(len(str))
83+
return self._api.any_new_from_string_with_size_on_client(client, str, size)
84+
else:
85+
return self._api.any_new_from_string_on_client(client, str)
86+
87+
def _type_to_new_from_get_as_method(self):
5388
from ansys.dpf.core import (
5489
field,
5590
property_field,
@@ -62,47 +97,53 @@ def _type_to_new_from_get_as_method(any_dpf):
6297
return [
6398
(
6499
int,
65-
any_dpf._api.any_new_from_int,
66-
any_dpf._api.any_get_as_int,
67-
any_dpf._api.any_new_from_int_on_client,
100+
self._api.any_new_from_int,
101+
self._api.any_get_as_int,
102+
self._api.any_new_from_int_on_client,
68103
),
69104
(
70105
str,
71-
any_dpf._api.any_new_from_string,
72-
any_dpf._api.any_get_as_string,
73-
any_dpf._api.any_new_from_string_on_client,
106+
self._new_from_string,
107+
self._get_as_string,
108+
self._new_from_string_on_client,
74109
),
75110
(
76111
float,
77-
any_dpf._api.any_new_from_double,
78-
any_dpf._api.any_get_as_double,
79-
any_dpf._api.any_new_from_double_on_client,
112+
self._api.any_new_from_double,
113+
self._api.any_get_as_double,
114+
self._api.any_new_from_double_on_client,
80115
),
81-
(field.Field, any_dpf._api.any_new_from_field, any_dpf._api.any_get_as_field),
116+
(
117+
bytes,
118+
self._new_from_string_as_bytes,
119+
self._get_as_string_as_bytes,
120+
self._new_from_string_as_bytes_on_client,
121+
),
122+
(field.Field, self._api.any_new_from_field, self._api.any_get_as_field),
82123
(
83124
property_field.PropertyField,
84-
any_dpf._api.any_new_from_property_field,
85-
any_dpf._api.any_get_as_property_field,
125+
self._api.any_new_from_property_field,
126+
self._api.any_get_as_property_field,
86127
),
87128
(
88129
string_field.StringField,
89-
any_dpf._api.any_new_from_string_field,
90-
any_dpf._api.any_get_as_string_field,
130+
self._api.any_new_from_string_field,
131+
self._api.any_get_as_string_field,
91132
),
92133
(
93134
generic_data_container.GenericDataContainer,
94-
any_dpf._api.any_new_from_generic_data_container,
95-
any_dpf._api.any_get_as_generic_data_container,
135+
self._api.any_new_from_generic_data_container,
136+
self._api.any_get_as_generic_data_container,
96137
),
97138
(
98139
scoping.Scoping,
99-
any_dpf._api.any_new_from_scoping,
100-
any_dpf._api.any_get_as_scoping,
140+
self._api.any_new_from_scoping,
141+
self._api.any_get_as_scoping,
101142
),
102143
(
103144
data_tree.DataTree,
104-
any_dpf._api.any_new_from_data_tree,
105-
any_dpf._api.any_get_as_data_tree,
145+
self._api.any_new_from_data_tree,
146+
self._api.any_get_as_data_tree,
106147
),
107148
]
108149

@@ -120,22 +161,22 @@ def new_from(obj, server=None):
120161
Wrapped any type.
121162
"""
122163

123-
innerServer = server if server is not None else obj._server
164+
inner_server = server if server is not None else obj._server
124165

125-
if not innerServer.meet_version("7.0"):
166+
if not inner_server.meet_version("7.0"):
126167
raise errors.DpfVersionNotSupported("7.0")
127168

128-
any_dpf = Any(server=innerServer)
169+
any_dpf = Any(server=inner_server)
129170

130-
for type_tuple in Any._type_to_new_from_get_as_method(any_dpf):
171+
for type_tuple in any_dpf._type_to_new_from_get_as_method():
131172
if isinstance(obj, type_tuple[0]):
132173
# call respective new_from function
133174
if isinstance(server, ansys.dpf.core.server_types.InProcessServer) or not (
134-
isinstance(obj, int) or isinstance(obj, str) or isinstance(obj, float)
175+
isinstance(obj, int) or isinstance(obj, str) or isinstance(obj, float) or isinstance(obj, bytes)
135176
):
136177
any_dpf._internal_obj = type_tuple[1](obj)
137178
else:
138-
any_dpf._internal_obj = type_tuple[3](innerServer.client, obj)
179+
any_dpf._internal_obj = type_tuple[3](inner_server.client, obj)
139180
# store get_as & type for casting back to original type
140181
any_dpf._internal_type = type_tuple[0]
141182
any_dpf._get_as_method = type_tuple[2]
@@ -190,9 +231,11 @@ def cast(self, output_type=None):
190231
# call the get_as function for the appropriate type
191232
internal_obj = type_tuple[2](self)
192233
if (
193-
self._internal_type is int
194-
or self._internal_type is str
195-
or self._internal_type is float
234+
self._internal_type is int
235+
or self._internal_type is str
236+
or self._internal_type is float
237+
or self._internal_type is bytes
238+
196239
):
197240
obj = internal_obj
198241
else:

src/ansys/dpf/core/operators/averaging/elemental_difference.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
====================
44
Autogenerated DPF operator classes.
55
"""
6+
67
from warnings import warn
78
from ansys.dpf.core.dpf_operator import Operator
89
from ansys.dpf.core.inputs import Input, _Inputs

src/ansys/dpf/core/operators/averaging/elemental_difference_fc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
=======================
44
Autogenerated DPF operator classes.
55
"""
6+
67
from warnings import warn
78
from ansys.dpf.core.dpf_operator import Operator
89
from ansys.dpf.core.inputs import Input, _Inputs

src/ansys/dpf/core/operators/averaging/elemental_fraction_fc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
=====================
44
Autogenerated DPF operator classes.
55
"""
6+
67
from warnings import warn
78
from ansys.dpf.core.dpf_operator import Operator
89
from ansys.dpf.core.inputs import Input, _Inputs

src/ansys/dpf/core/operators/averaging/elemental_mean.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
==============
44
Autogenerated DPF operator classes.
55
"""
6+
67
from warnings import warn
78
from ansys.dpf.core.dpf_operator import Operator
89
from ansys.dpf.core.inputs import Input, _Inputs

src/ansys/dpf/core/operators/averaging/elemental_mean_fc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
=================
44
Autogenerated DPF operator classes.
55
"""
6+
67
from warnings import warn
78
from ansys.dpf.core.dpf_operator import Operator
89
from ansys.dpf.core.inputs import Input, _Inputs

src/ansys/dpf/core/operators/averaging/elemental_nodal_to_nodal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
========================
44
Autogenerated DPF operator classes.
55
"""
6+
67
from warnings import warn
78
from ansys.dpf.core.dpf_operator import Operator
89
from ansys.dpf.core.inputs import Input, _Inputs

src/ansys/dpf/core/operators/averaging/elemental_nodal_to_nodal_elemental.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
==================================
44
Autogenerated DPF operator classes.
55
"""
6+
67
from warnings import warn
78
from ansys.dpf.core.dpf_operator import Operator
89
from ansys.dpf.core.inputs import Input, _Inputs

src/ansys/dpf/core/operators/averaging/elemental_nodal_to_nodal_elemental_fc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
=====================================
44
Autogenerated DPF operator classes.
55
"""
6+
67
from warnings import warn
78
from ansys.dpf.core.dpf_operator import Operator
89
from ansys.dpf.core.inputs import Input, _Inputs

0 commit comments

Comments
 (0)