From d46ea842c25d8500d338c23fa81dba705f24bc0d Mon Sep 17 00:00:00 2001 From: Anthony MOI Date: Fri, 10 Jan 2020 00:32:30 -0500 Subject: [PATCH] Python - IndexableString accepts tuples directly --- bindings/python/src/encoding.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bindings/python/src/encoding.rs b/bindings/python/src/encoding.rs index bcced93e..a93d29e7 100644 --- a/bindings/python/src/encoding.rs +++ b/bindings/python/src/encoding.rs @@ -56,8 +56,18 @@ impl PyMappingProtocol for IndexableString { } } else if let Ok(slice) = item.cast_as::(py) { Ok(slice) + } else if let Ok(offset) = item.cast_as::(py) { + if offset.len() == 2 { + let start = offset.get_item(0).extract::()?; + let end = offset.get_item(1).extract::()?; + Ok(PySlice::new(py, start, end, 1)) + } else { + Err(exceptions::TypeError::py_err("Expected Tuple[int, int]")) + } } else { - Err(exceptions::TypeError::py_err("Expected number or slice")) + Err(exceptions::TypeError::py_err( + "Expected number or slice or Tuple[int, int]", + )) }?; // Find out range from the slice