@@ -20,6 +20,7 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyRef<PyModule> {
20
20
21
21
#[ pymodule]
22
22
mod _sqlite {
23
+ use crossbeam_utils:: atomic:: AtomicCell ;
23
24
use libsqlite3_sys:: {
24
25
SQLITE_BLOB , SQLITE_DETERMINISTIC , SQLITE_FLOAT , SQLITE_INTEGER , SQLITE_NULL ,
25
26
SQLITE_OPEN_CREATE , SQLITE_OPEN_READWRITE , SQLITE_OPEN_URI , SQLITE_TEXT , SQLITE_TRACE_STMT ,
@@ -67,11 +68,14 @@ mod _sqlite {
67
68
PySetterValue ,
68
69
} ,
69
70
object:: { Traverse , TraverseFn } ,
70
- protocol:: { PyBuffer , PyIterReturn , PyMappingMethods , PySequence , PySequenceMethods } ,
71
+ protocol:: {
72
+ PyBuffer , PyIterReturn , PyMappingMethods , PyNumberMethods , PySequence ,
73
+ PySequenceMethods ,
74
+ } ,
71
75
sliceable:: { SaturatedSliceIter , SliceableSequenceOp } ,
72
76
types:: {
73
- AsMapping , AsSequence , Callable , Comparable , Constructor , Hashable , IterNext , Iterable ,
74
- PyComparisonOp , SelfIter , Unconstructible ,
77
+ AsMapping , AsNumber , AsSequence , Callable , Comparable , Constructor , Hashable , IterNext ,
78
+ Iterable , PyComparisonOp , SelfIter , Unconstructible ,
75
79
} ,
76
80
utils:: ToCString ,
77
81
} ;
@@ -2058,7 +2062,7 @@ mod _sqlite {
2058
2062
}
2059
2063
}
2060
2064
2061
- #[ pyclass( with( AsMapping , Unconstructible ) ) ]
2065
+ #[ pyclass( with( AsMapping , Unconstructible , AsNumber , AsSequence ) ) ]
2062
2066
impl Blob {
2063
2067
#[ pymethod]
2064
2068
fn close ( & self ) {
@@ -2349,6 +2353,50 @@ mod _sqlite {
2349
2353
}
2350
2354
}
2351
2355
2356
+ impl AsNumber for Blob {
2357
+ fn as_number ( ) -> & ' static PyNumberMethods {
2358
+ static AS_NUMBER : PyNumberMethods = PyNumberMethods {
2359
+ add : Some ( |a, b, vm| {
2360
+ Err ( vm. new_type_error ( format ! (
2361
+ "unsupported operand type(s) for +: '{}' and '{}'" ,
2362
+ a. class( ) . name( ) ,
2363
+ b. class( ) . name( )
2364
+ ) ) )
2365
+ } ) ,
2366
+ multiply : Some ( |a, b, vm| {
2367
+ Err ( vm. new_type_error ( format ! (
2368
+ "unsupported operand type(s) for *: '{}' and '{}'" ,
2369
+ a. class( ) . name( ) ,
2370
+ b. class( ) . name( )
2371
+ ) ) )
2372
+ } ) ,
2373
+ ..PyNumberMethods :: NOT_IMPLEMENTED
2374
+ } ;
2375
+ & AS_NUMBER
2376
+ }
2377
+ }
2378
+
2379
+ impl AsSequence for Blob {
2380
+ fn as_sequence ( ) -> & ' static PySequenceMethods {
2381
+ static AS_SEQUENCE : PySequenceMethods = PySequenceMethods {
2382
+ length : AtomicCell :: new ( None ) ,
2383
+ concat : AtomicCell :: new ( None ) ,
2384
+ repeat : AtomicCell :: new ( None ) ,
2385
+ item : AtomicCell :: new ( None ) ,
2386
+ ass_item : AtomicCell :: new ( None ) ,
2387
+ contains : atomic_func ! ( |seq, _needle, vm| {
2388
+ Err ( vm. new_type_error( format!(
2389
+ "argument of type '{}' is not iterable" ,
2390
+ seq. obj. class( ) . name( ) ,
2391
+ ) ) )
2392
+ } ) ,
2393
+ inplace_concat : AtomicCell :: new ( None ) ,
2394
+ inplace_repeat : AtomicCell :: new ( None ) ,
2395
+ } ;
2396
+ & AS_SEQUENCE
2397
+ }
2398
+ }
2399
+
2352
2400
#[ pyattr]
2353
2401
#[ pyclass( name) ]
2354
2402
#[ derive( Debug , PyPayload ) ]
0 commit comments