Ejemplo n.º 1
0
 internal static Bytes FromObject(CodeContext context, object?o)
 {
     if (o == null)
     {
         throw PythonOps.TypeError("cannot convert 'NoneType' object to bytes");
     }
     else if (o.GetType() == typeof(Bytes))
     {
         return((Bytes)o);
     }
     else if (TryInvokeBytesOperator(context, o, out Bytes? res))
     {
         return(res);
     }
     else if (o is string || o is ExtensibleString)
     {
         throw PythonOps.TypeError("cannot convert unicode object to bytes");
     }
     else
     {
         return(new Bytes(ByteOps.GetBytes(o, useHint: true, context).ToArray()));
     }
 }
Ejemplo n.º 2
0
        public ByteArray /*!*/ join([NotNull] List /*!*/ sequence)
        {
            if (sequence.__len__() == 0)
            {
                return(new ByteArray());
            }

            lock (this) {
                if (sequence.__len__() == 1)
                {
                    return(JoinOne(sequence[0]));
                }

                List <byte> ret = new List <byte>();
                ByteOps.AppendJoin(sequence._data[0], 0, ret);
                for (int i = 1; i < sequence._size; i++)
                {
                    ret.AddRange(this);
                    ByteOps.AppendJoin(sequence._data[i], i, ret);
                }

                return(new ByteArray(ret));
            }
        }
Ejemplo n.º 3
0
 public Bytes([NotNull] List bytes)
 {
     _bytes = ByteOps.GetBytes(bytes, ByteOps.GetByteListOk).ToArray();
 }
Ejemplo n.º 4
0
 public Bytes([NotNull] PythonList bytes)
 {
     _bytes = ByteOps.GetBytes(bytes).ToArray();
 }