コード例 #1
0
ファイル: Bytes.cs プロジェクト: zgpglee/ironpython3
 public Bytes(CodeContext context, object?source)
 {
     if (PythonTypeOps.TryInvokeUnaryOperator(context, source, "__bytes__", out object?res))
     {
         if (res is Bytes bytes)
         {
             _bytes = bytes._bytes;
         }
         else
         {
             throw PythonOps.TypeError("__bytes__ returned non-bytes (got '{0}' from type '{1}')", PythonOps.GetPythonTypeName(res), PythonOps.GetPythonTypeName(source));
         }
     }
     else if (Converter.TryConvertToIndex(source, throwOverflowError: true, out int size))
     {
         if (size < 0)
         {
             throw PythonOps.ValueError("negative count");
         }
         _bytes = new byte[size];
     }
     else
     {
         _bytes = ByteArray.GetBytes(source, useHint: true).ToArray();
     }
 }
コード例 #2
0
ファイル: Bytes.cs プロジェクト: tig/ironpython3
 public Bytes(object?source)
 {
     if (Converter.TryConvertToIndex(source, throwOverflowError: true, out int size))
     {
         if (size < 0)
         {
             throw PythonOps.ValueError("negative count");
         }
         _bytes = new byte[size];
     }
     else
     {
         _bytes = ByteArray.GetBytes(source, useHint: true).ToArray();
     }
 }
コード例 #3
0
 public Bytes(object?source) : this(ByteArray.GetBytes(source))
 {
 }