| 459 | } |
| 460 | |
| 461 | pub fn _mul(&self, a: &PyObject, b: &PyObject) -> PyResult { |
| 462 | let result = self.binary_op1(a, b, PyNumberBinaryOp::Multiply)?; |
| 463 | if !result.is(&self.ctx.not_implemented) { |
| 464 | return Ok(result); |
| 465 | } |
| 466 | if let Ok(seq_a) = a.try_sequence(self) { |
| 467 | let n = b |
| 468 | .try_index(self)? |
| 469 | .as_bigint() |
| 470 | .to_isize() |
| 471 | .ok_or_else(|| self.new_overflow_error("repeated bytes are too long"))?; |
| 472 | return seq_a.repeat(n, self); |
| 473 | } else if let Ok(seq_b) = b.try_sequence(self) { |
| 474 | let n = a |
| 475 | .try_index(self)? |
| 476 | .as_bigint() |
| 477 | .to_isize() |
| 478 | .ok_or_else(|| self.new_overflow_error("repeated bytes are too long"))?; |
| 479 | return seq_b.repeat(n, self); |
| 480 | } |
| 481 | Err(self.new_unsupported_bin_op_error(a, b, "*")) |
| 482 | } |
| 483 | |
| 484 | pub fn _imul(&self, a: &PyObject, b: &PyObject) -> PyResult { |
| 485 | let result = self.binary_iop1( |