@@ -135,43 +135,55 @@ fn bytearray_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
135
135
fn bytearray_isalnum ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
136
136
arg_check ! ( vm, args, required = [ ( zelf, Some ( vm. ctx. bytearray_type( ) ) ) ] ) ;
137
137
let bytes = get_value ( zelf) ;
138
- Ok ( vm. new_bool ( bytes. iter ( ) . all ( |x| char:: from ( * x) . is_alphanumeric ( ) ) ) )
138
+ Ok ( vm. new_bool ( !bytes . is_empty ( ) && bytes. iter ( ) . all ( |x| char:: from ( * x) . is_alphanumeric ( ) ) ) )
139
139
}
140
140
141
141
fn bytearray_isalpha ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
142
142
arg_check ! ( vm, args, required = [ ( zelf, Some ( vm. ctx. bytearray_type( ) ) ) ] ) ;
143
143
let bytes = get_value ( zelf) ;
144
- Ok ( vm. new_bool ( bytes. iter ( ) . all ( |x| char:: from ( * x) . is_alphabetic ( ) ) ) )
144
+ Ok ( vm. new_bool ( !bytes . is_empty ( ) && bytes. iter ( ) . all ( |x| char:: from ( * x) . is_alphabetic ( ) ) ) )
145
145
}
146
146
147
147
fn bytearray_isascii ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
148
148
arg_check ! ( vm, args, required = [ ( zelf, Some ( vm. ctx. bytearray_type( ) ) ) ] ) ;
149
149
let bytes = get_value ( zelf) ;
150
- Ok ( vm. new_bool ( bytes. iter ( ) . all ( |x| char:: from ( * x) . is_ascii ( ) ) ) )
150
+ Ok ( vm. new_bool ( !bytes . is_empty ( ) && bytes. iter ( ) . all ( |x| char:: from ( * x) . is_ascii ( ) ) ) )
151
151
}
152
152
153
153
fn bytearray_isdigit ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
154
154
arg_check ! ( vm, args, required = [ ( zelf, Some ( vm. ctx. bytearray_type( ) ) ) ] ) ;
155
155
let bytes = get_value ( zelf) ;
156
- Ok ( vm. new_bool ( bytes. iter ( ) . all ( |x| char:: from ( * x) . is_digit ( 10 ) ) ) )
156
+ Ok ( vm. new_bool ( !bytes . is_empty ( ) && bytes. iter ( ) . all ( |x| char:: from ( * x) . is_digit ( 10 ) ) ) )
157
157
}
158
158
159
159
fn bytearray_islower ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
160
160
arg_check ! ( vm, args, required = [ ( zelf, Some ( vm. ctx. bytearray_type( ) ) ) ] ) ;
161
161
let bytes = get_value ( zelf) ;
162
- Ok ( vm. new_bool ( bytes. iter ( ) . all ( |x| char:: from ( * x) . is_lowercase ( ) ) ) )
162
+ Ok ( vm. new_bool (
163
+ !bytes. is_empty ( )
164
+ && bytes
165
+ . iter ( )
166
+ . filter ( |x| char:: from ( * * x) . is_whitespace ( ) )
167
+ . all ( |x| char:: from ( * x) . is_lowercase ( ) ) ,
168
+ ) )
163
169
}
164
170
165
171
fn bytearray_isspace ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
166
172
arg_check ! ( vm, args, required = [ ( zelf, Some ( vm. ctx. bytearray_type( ) ) ) ] ) ;
167
173
let bytes = get_value ( zelf) ;
168
- Ok ( vm. new_bool ( bytes. iter ( ) . all ( |x| char:: from ( * x) . is_whitespace ( ) ) ) )
174
+ Ok ( vm. new_bool ( !bytes . is_empty ( ) && bytes. iter ( ) . all ( |x| char:: from ( * x) . is_whitespace ( ) ) ) )
169
175
}
170
176
171
177
fn bytearray_isupper ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
172
178
arg_check ! ( vm, args, required = [ ( zelf, Some ( vm. ctx. bytearray_type( ) ) ) ] ) ;
173
179
let bytes = get_value ( zelf) ;
174
- Ok ( vm. new_bool ( bytes. iter ( ) . all ( |x| char:: from ( * x) . is_uppercase ( ) ) ) )
180
+ Ok ( vm. new_bool (
181
+ !bytes. is_empty ( )
182
+ && bytes
183
+ . iter ( )
184
+ . filter ( |x| !char:: from ( * * x) . is_whitespace ( ) )
185
+ . all ( |x| char:: from ( * x) . is_uppercase ( ) ) ,
186
+ ) )
175
187
}
176
188
177
189
fn bytearray_istitle ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
0 commit comments