27
27
from typing import Union
28
28
import warnings
29
29
30
+ from ansys .dyna .core .lib .encrypted_keyword import EncryptedKeyword
30
31
from ansys .dyna .core .lib .format_type import format_type
31
32
from ansys .dyna .core .lib .import_handler import ImportContext , ImportHandler
32
33
from ansys .dyna .core .lib .io_utils import write_or_return
@@ -89,15 +90,15 @@ def append(self, keyword: Union[KeywordBase, str], check=False) -> None:
89
90
90
91
Parameters
91
92
----------
92
- keyword : Union[KeywordBase, str]
93
- Keyword. The keyword can be either an implementation of the ``KeywordBase``
94
- instance or a string.
93
+ keyword : Union[KeywordBase, EncryptedKeyword, str]
94
+ Keyword. The keyword can be ``KeywordBase``, ``EncryptedKeyword``,
95
+ or a string.
95
96
check : bool, optional
96
97
The default is ``False``.
97
98
"""
98
- assert isinstance ( keyword , KeywordBase ) or isinstance (
99
- keyword , str
100
- ), "Keywords or strings can only be appended to the deck."
99
+ assert (
100
+ isinstance ( keyword , KeywordBase ) or isinstance ( keyword , str ) or isinstance ( keyword , EncryptedKeyword )
101
+ ), "Only keywords, encrypted keywords, or strings can be included in a deck."
101
102
if isinstance (keyword , str ):
102
103
self ._keywords .append (self ._formatstring (keyword , check ))
103
104
else :
@@ -143,7 +144,7 @@ def _formatstring(self, string, check=False):
143
144
return string
144
145
145
146
@property
146
- def all_keywords (self ) -> typing .List [typing .Union [str , KeywordBase ]]:
147
+ def all_keywords (self ) -> typing .List [typing .Union [str , KeywordBase , EncryptedKeyword ]]:
147
148
"""List of all keywords."""
148
149
return self ._keywords
149
150
@@ -152,6 +153,11 @@ def string_keywords(self) -> typing.List[str]:
152
153
"""List of keywords as a raw string."""
153
154
return [kw for kw in self ._keywords if isinstance (kw , str )]
154
155
156
+ @property
157
+ def encrypted_keywords (self ) -> typing .List [str ]:
158
+ """List of keywords as a raw string."""
159
+ return [kw for kw in self ._keywords if isinstance (kw , EncryptedKeyword )]
160
+
155
161
@property
156
162
def keywords (self ):
157
163
"""List of processed keywords."""
@@ -172,7 +178,8 @@ def _expand_helper(self, search_paths: typing.List[str], recurse: bool) -> typin
172
178
"""Recursively outputs a list of keywords within Includes."""
173
179
keywords = []
174
180
for keyword in self .all_keywords :
175
- if isinstance (keyword , str ):
181
+ if not isinstance (keyword , KeywordBase ):
182
+ print (keyword )
176
183
keywords .append (keyword )
177
184
continue
178
185
if keyword .keyword != "INCLUDE" :
@@ -269,12 +276,18 @@ def dumps(self) -> str:
269
276
warnings .warn ("The 'dumps()' method is deprecated. Use the 'write()' method instead." )
270
277
return self .write ()
271
278
272
- def _write_keyword (self , buf : typing .TextIO , kwd : typing .Union [str , KeywordBase ], format : format_type ) -> None :
279
+ def _write_keyword (
280
+ self , buf : typing .TextIO , kwd : typing .Union [str , KeywordBase , EncryptedKeyword ], format : format_type
281
+ ) -> None :
273
282
"""Write a keyword to the buffer."""
274
283
if isinstance (kwd , KeywordBase ):
275
284
kwd .write (buf , None , format )
276
285
elif isinstance (kwd , str ):
277
286
buf .write (kwd )
287
+ elif isinstance (kwd , EncryptedKeyword ):
288
+ buf .write ("-----BEGIN PGP MESSAGE-----\n " )
289
+ buf .write (kwd .data )
290
+ buf .write ("\n -----END PGP MESSAGE-----\n " )
278
291
279
292
def _remove_trailing_newline (self , buf : typing .TextIO ) -> None :
280
293
"""If the last character is a newline, seek back so that it can be overwritten.
@@ -429,8 +442,10 @@ def get(self, **kwargs) -> typing.List[KeywordBase]:
429
442
return kwds
430
443
431
444
def _import_file (self , path : str , encoding : str , context : ImportContext ):
445
+ from ansys .dyna .core .lib .deck_loader import load_deck_from_buffer
446
+
432
447
with open (path , encoding = encoding ) as f :
433
- return self . loads ( f . read () , context )
448
+ return load_deck_from_buffer ( self , f , context , self . _import_handlers )
434
449
435
450
def import_file (
436
451
self , path : str , encoding : str = "utf-8"
@@ -494,6 +509,8 @@ def __repr__(self) -> str:
494
509
content_lines .append (f"kwd: { kw .get_title ()} " )
495
510
elif isinstance (kw , str ):
496
511
content_lines .append ("str: " + kw .split ("\n " )[0 ] + "..." )
512
+ elif isinstance (kw , EncryptedKeyword ):
513
+ content_lines .append ("encrypted keyword..." )
497
514
498
515
output = "\n " .join (content_lines )
499
516
return output
0 commit comments