@@ -178,6 +178,15 @@ def find_matching_indices_with_levelspec(expr, pattern, evaluation, levelspec=1,
178178 return found
179179
180180
181+ class Normal (Builtin ):
182+ """
183+ <dl>
184+ <dt>'Normal[expr_]'
185+ <dd> Brings especial expressions to a normal expression from
186+ different especial forms.
187+ </dl>
188+ """
189+
181190class ByteArray (Builtin ):
182191 """
183192 <dl>
@@ -187,21 +196,41 @@ class ByteArray(Builtin):
187196 <dd> Constructs a byte array where bytes comes from decode a b64 encoded String
188197 </dl>
189198
190- >> A=ByteArray[{1,25,3}]
199+ >> A=ByteArray[{1, 25, 3}]
191200 = ByteArray["ARkD"]
192201 >> A[[2]]
193202 = 25
203+ >> Normal[A]
204+ = {1, 25, 3}
205+ >> ToString[A]
206+ = ByteArray["ARkD"]
207+ >> ByteArray["ARkD"]
208+ = ByteArray["ARkD"]
194209 >> B=ByteArray["asy"]
195- = ByteArray["WVhONQ=="]
210+ : The first argument in Bytearray[asy] should be a B64 enconded string or a vector of integers.
211+ = $Failed
196212 """
197213
198214 messages = {'aotd' : 'Elements in `1` are inconsistent with type Byte' ,
199215 'lend' : 'The first argument in Bytearray[`1`] should ' + \
200- 'be a B64 enconded string or a vector of integers' ,}
216+ 'be a B64 enconded string or a vector of integers. ' ,}
201217
202218 def apply_str (self , string , evaluation ):
203219 'ByteArray[string_String]'
204- return Expression ("ByteArray" , ByteArrayAtom (string .value ))
220+ try :
221+ atom = ByteArrayAtom (string .value )
222+ except Exception as e :
223+ evaluation .message ("ByteArray" , 'lend' , string )
224+ return SymbolFailed
225+ return Expression ("ByteArray" , atom )
226+
227+ def apply_to_str (self , baa , evaluation ):
228+ 'ToString[ByteArray[baa_ByteArrayAtom]]'
229+ return String ('ByteArray["' + baa .__str__ () + '"]' )
230+
231+ def apply_normal (self , baa , evaluation ):
232+ 'System`Normal[ByteArray[baa_ByteArrayAtom]]'
233+ return Expression ("List" , * [Integer (x ) for x in baa .value ])
205234
206235 def apply_list (self , values , evaluation ):
207236 'ByteArray[values_List]'
@@ -1067,6 +1096,7 @@ def apply(self, list, i, evaluation):
10671096 indices = i .get_sequence ()
10681097 # How to deal with ByteArrays
10691098 if list .get_head_name () == "System`ByteArray" :
1099+ list = list .evaluate (evaluation )
10701100 if len (indices ) > 1 :
10711101 print ("Part::partd1: Depth of object ByteArray[<3>] " +
10721102 "is not sufficient for the given part specification." )
0 commit comments