@@ -187,21 +187,41 @@ class ByteArray(Builtin):
187187 <dd> Constructs a byte array where bytes comes from decode a b64 encoded String
188188 </dl>
189189
190- >> A=ByteArray[{1,25,3}]
190+ >> A=ByteArray[{1, 25, 3}]
191191 = ByteArray["ARkD"]
192192 >> A[[2]]
193193 = 25
194+ >> System`Normal[A]
195+ = {1, 25, 3}
196+ >> ToString[A]
197+ = ByteArray["ARkD"]
198+ >> ByteArray["ARkD"]
199+ = ByteArray["ARkD"]
194200 >> B=ByteArray["asy"]
195- = ByteArray["WVhONQ=="]
201+ : The first argument in Bytearray[asy] should be a B64 enconded string or a vector of integers.
202+ = $Failed
196203 """
197204
198205 messages = {'aotd' : 'Elements in `1` are inconsistent with type Byte' ,
199206 'lend' : 'The first argument in Bytearray[`1`] should ' + \
200- 'be a B64 enconded string or a vector of integers' ,}
207+ 'be a B64 enconded string or a vector of integers. ' ,}
201208
202209 def apply_str (self , string , evaluation ):
203210 'ByteArray[string_String]'
204- return Expression ("ByteArray" , ByteArrayAtom (string .value ))
211+ try :
212+ atom = ByteArrayAtom (string .value )
213+ except Exception as e :
214+ evaluation .message ("ByteArray" , 'lend' , string )
215+ return SymbolFailed
216+ return Expression ("ByteArray" , atom )
217+
218+ def apply_to_str (self , baa , evaluation ):
219+ 'ToString[ByteArray[baa_ByteArrayAtom]]'
220+ return String ('ByteArray["' + baa .__str__ () + '"]' )
221+
222+ def apply_normal (self , baa , evaluation ):
223+ 'System`Normal[ByteArray[baa_ByteArrayAtom]]'
224+ return Expression ("List" , * [Integer (x ) for x in baa .value ])
205225
206226 def apply_list (self , values , evaluation ):
207227 'ByteArray[values_List]'
@@ -1067,6 +1087,7 @@ def apply(self, list, i, evaluation):
10671087 indices = i .get_sequence ()
10681088 # How to deal with ByteArrays
10691089 if list .get_head_name () == "System`ByteArray" :
1090+ list = list .evaluate (evaluation )
10701091 if len (indices ) > 1 :
10711092 print ("Part::partd1: Depth of object ByteArray[<3>] " +
10721093 "is not sufficient for the given part specification." )
0 commit comments