@@ -263,7 +263,7 @@ public ByteArray capitalize() {
263263 public ByteArray center ( int width ) => center ( width , ( byte ) ' ' ) ;
264264
265265 public ByteArray center ( int width , [ BytesLike , NotNone ] IList < byte > fillchar )
266- => center ( width , fillchar . ToByte ( " center" , 2 ) ) ;
266+ => center ( width , fillchar . ToByte ( nameof ( center ) , 2 ) ) ;
267267
268268 private ByteArray center ( int width , byte fillchar ) {
269269 lock ( this ) {
@@ -301,7 +301,7 @@ public int count([BytesLike, NotNone] IList<byte> sub, object? start, object? en
301301 int istart = start != null ? Converter . ConvertToIndex ( start ) : 0 ;
302302 lock ( this ) {
303303 int iend = end != null ? Converter . ConvertToIndex ( end ) : _bytes . Count ;
304- return _bytes . CountOf ( sub , istart , iend ) ;
304+ return _bytes . CountOf ( sub , istart , iend ) ;
305305 }
306306 }
307307
@@ -585,13 +585,13 @@ public bool isupper() {
585585 /// in the sequence seq. The separator between elements is the
586586 /// string providing this method
587587 /// </summary>
588- public ByteArray join ( object ? sequence ) {
589- IEnumerator seq = PythonOps . GetEnumerator ( sequence ) ;
588+ public ByteArray join ( object ? iterable ) {
589+ IEnumerator seq = PythonOps . GetEnumerator ( iterable ) ;
590590 if ( ! seq . MoveNext ( ) ) {
591591 return new ByteArray ( ) ;
592592 }
593593
594- // check if we have just a sequnce of just one value - if so just
594+ // check if we have a sequence of just one value - if so just
595595 // return that value.
596596 object ? curVal = seq . Current ;
597597 if ( ! seq . MoveNext ( ) ) {
@@ -613,34 +613,32 @@ public ByteArray join(object? sequence) {
613613 return new ByteArray ( ret ) ;
614614 }
615615
616- public ByteArray join ( [ NotNone ] PythonList sequence ) {
617- if ( sequence . __len__ ( ) == 0 ) {
616+ public ByteArray join ( [ NotNone ] PythonList iterable ) {
617+ if ( iterable . __len__ ( ) == 0 ) {
618618 return new ByteArray ( ) ;
619619 }
620620
621621 lock ( this ) {
622- if ( sequence . __len__ ( ) == 1 ) {
623- return JoinOne ( sequence [ 0 ] ) ;
622+ if ( iterable . __len__ ( ) == 1 ) {
623+ return JoinOne ( iterable [ 0 ] ) ;
624624 }
625625
626626 List < byte > ret = new List < byte > ( ) ;
627- ByteOps . AppendJoin ( sequence . _data [ 0 ] , 0 , ret ) ;
628- for ( int i = 1 ; i < sequence . _size ; i ++ ) {
627+ ByteOps . AppendJoin ( iterable . _data [ 0 ] , 0 , ret ) ;
628+ for ( int i = 1 ; i < iterable . _size ; i ++ ) {
629629 ret . AddRange ( this ) ;
630- ByteOps . AppendJoin ( sequence . _data [ i ] , i , ret ) ;
630+ ByteOps . AppendJoin ( iterable . _data [ i ] , i , ret ) ;
631631 }
632632
633633 return new ByteArray ( ret ) ;
634634 }
635635 }
636636
637- public ByteArray ljust ( int width ) {
638- return ljust ( width , ( byte ) ' ' ) ;
639- }
637+ public ByteArray ljust ( int width )
638+ => ljust ( width , ( byte ) ' ' ) ;
640639
641- public ByteArray ljust ( int width , [ BytesLike , NotNone ] IList < byte > fillchar ) {
642- return ljust ( width , fillchar . ToByte ( "ljust" , 2 ) ) ;
643- }
640+ public ByteArray ljust ( int width , [ BytesLike , NotNone ] IList < byte > fillchar )
641+ => ljust ( width , fillchar . ToByte ( nameof ( ljust ) , 2 ) ) ;
644642
645643 private ByteArray ljust ( int width , byte fillchar ) {
646644 lock ( this ) {
@@ -671,7 +669,7 @@ public ByteArray lstrip() {
671669 }
672670 }
673671
674- public ByteArray lstrip ( [ BytesLike ] IList < byte > ? chars ) {
672+ public ByteArray lstrip ( [ BytesLike ] IList < byte > ? chars ) {
675673 if ( chars == null ) return lstrip ( ) ;
676674 lock ( this ) {
677675 var res = _bytes . LeftStrip ( chars ) ;
@@ -806,13 +804,11 @@ public int rindex(BigInteger @byte, object? start)
806804 public int rindex ( BigInteger @byte , object ? start , object ? end )
807805 => rindex ( Bytes . FromByte ( @byte . ToByteChecked ( ) ) , start , end ) ;
808806
809- public ByteArray rjust ( int width ) {
810- return rjust ( width , ( byte ) ' ' ) ;
811- }
807+ public ByteArray rjust ( int width )
808+ => rjust ( width , ( byte ) ' ' ) ;
812809
813- public ByteArray rjust ( int width , [ BytesLike , NotNone ] IList < byte > fillchar ) {
814- return rjust ( width , fillchar . ToByte ( "rjust" , 2 ) ) ;
815- }
810+ public ByteArray rjust ( int width , [ BytesLike , NotNone ] IList < byte > fillchar )
811+ => rjust ( width , fillchar . ToByte ( nameof ( rjust ) , 2 ) ) ;
816812
817813 private ByteArray rjust ( int width , int fillchar ) {
818814 byte fill = fillchar . ToByteChecked ( ) ;
@@ -855,7 +851,7 @@ public PythonTuple rpartition([BytesLike, NotNone] IList<byte> sep) {
855851 }
856852
857853 [ return : SequenceTypeInfo ( typeof ( ByteArray ) ) ]
858- public PythonList rsplit ( [ BytesLike ] IList < byte > ? sep = null , int maxsplit = - 1 ) {
854+ public PythonList rsplit ( [ BytesLike ] IList < byte > ? sep = null , int maxsplit = - 1 ) {
859855 lock ( this ) {
860856 return _bytes . RightSplit ( sep , maxsplit , x => new ByteArray ( new List < byte > ( x ) ) ) ;
861857 }
@@ -868,7 +864,7 @@ public ByteArray rstrip() {
868864 }
869865 }
870866
871- public ByteArray rstrip ( [ BytesLike ] IList < byte > ? chars ) {
867+ public ByteArray rstrip ( [ BytesLike ] IList < byte > ? chars ) {
872868 if ( chars == null ) return rstrip ( ) ;
873869 lock ( this ) {
874870 var res = _bytes . RightStrip ( chars ) ;
@@ -877,7 +873,7 @@ public ByteArray rstrip([BytesLike]IList<byte>? chars) {
877873 }
878874
879875 [ return : SequenceTypeInfo ( typeof ( ByteArray ) ) ]
880- public PythonList split ( [ BytesLike ] IList < byte > ? sep = null , int maxsplit = - 1 ) {
876+ public PythonList split ( [ BytesLike ] IList < byte > ? sep = null , int maxsplit = - 1 ) {
881877 lock ( this ) {
882878 return _bytes . Split ( sep , maxsplit , x => new ByteArray ( x ) ) ;
883879 }
@@ -973,7 +969,7 @@ public ByteArray strip() {
973969 }
974970 }
975971
976- public ByteArray strip ( [ BytesLike ] IList < byte > ? chars ) {
972+ public ByteArray strip ( [ BytesLike ] IList < byte > ? chars ) {
977973 if ( chars == null ) return strip ( ) ;
978974 lock ( this ) {
979975 var res = _bytes . Strip ( chars ) ;
@@ -1000,22 +996,22 @@ private void ValidateTable(IList<byte>? table) {
1000996 }
1001997 }
1002998
1003- public ByteArray translate ( [ BytesLike ] IList < byte > ? table ) {
999+ public ByteArray translate ( [ BytesLike ] IList < byte > ? table ) {
10041000 ValidateTable ( table ) ;
10051001 lock ( this ) {
10061002 return new ByteArray ( _bytes . Translate ( table , null ) ) ;
10071003 }
10081004 }
10091005
10101006
1011- public ByteArray translate ( [ BytesLike ] IList < byte > ? table , [ BytesLike , NotNone ] IList < byte > delete ) {
1007+ public ByteArray translate ( [ BytesLike ] IList < byte > ? table , [ BytesLike , NotNone ] IList < byte > delete ) {
10121008 ValidateTable ( table ) ;
10131009 lock ( this ) {
10141010 return new ByteArray ( _bytes . Translate ( table , delete ) ) ;
10151011 }
10161012 }
10171013
1018- public ByteArray translate ( [ BytesLike ] IList < byte > ? table , object ? delete ) {
1014+ public ByteArray translate ( [ BytesLike ] IList < byte > ? table , object ? delete ) {
10191015 if ( delete is IBufferProtocol bufferProtocol ) {
10201016 using var buffer = bufferProtocol . GetBuffer ( ) ;
10211017 return translate ( table , buffer . AsReadOnlySpan ( ) . ToArray ( ) ) ;
@@ -1353,11 +1349,11 @@ private static ByteArray JoinOne(object? curVal) {
13531349 return new ByteArray ( new List < byte > ( bytes ) ) ;
13541350 }
13551351 if ( curVal is IBufferProtocol bp ) {
1356- using ( IPythonBuffer buf = bp . GetBuffer ( ) ) {
1357- return new ByteArray ( new ArrayData < byte > ( buf . AsReadOnlySpan ( ) ) ) ;
1358- }
1352+ using var buf = bp . GetBufferNoThrow ( ) ;
1353+ if ( buf is null ) throw ByteOps . JoinSequenceError ( curVal , 0 ) ;
1354+ return new ByteArray ( new ArrayData < byte > ( buf . AsReadOnlySpan ( ) ) ) ;
13591355 }
1360- throw PythonOps . TypeError ( "can only join an iterable of bytes" ) ;
1356+ throw ByteOps . JoinSequenceError ( curVal , 0 ) ;
13611357 }
13621358
13631359 private ByteArray CopyThis ( ) {
0 commit comments