Exemple #1
0
 public static object __new__(CodeContext context, [NotNull] PythonType cls, [NotNull] IBufferProtocol source)
 {
     if (cls == TypeCache.Bytes)
     {
         if (source.GetType() == typeof(Bytes))
         {
             return(source);
         }
         else if (TryInvokeBytesOperator(context, source, out Bytes? res))
         {
             return(res);
         }
         else if (Converter.TryConvertToIndex(source, throwOverflowError: true, out int size))
         {
             if (size < 0)
             {
                 throw PythonOps.ValueError("negative count");
             }
             return(new Bytes(new byte[size]));
         }
         else
         {
             return(new Bytes(source));
         }
     }
     else
     {
         return(cls.CreateInstance(context, __new__(context, TypeCache.Bytes, source)));
     }
 }