impl Match.expand
@@ -12,7 +12,7 @@ mod _sre {
use super::constants::SreFlag;
use super::interp::{self, lower_ascii, lower_unicode, upper_unicode, State};
use crate::builtins::tuple::PyTupleRef;
- use crate::builtins::{PyStrRef, PyTypeRef};
+ use crate::builtins::{PyDictRef, PyStrRef, PyTypeRef};
use crate::function::{Args, OptionalArg};
use crate::pyobject::{
Either, IntoPyObject, PyCallable, PyObjectRef, PyRef, PyResult, PyValue, StaticType,
@@ -84,7 +84,7 @@ mod _sre {
flags: u16,
code: PyObjectRef,
groups: usize,
- groupindex: HashMap<String, usize>,
+ groupindex: PyDictRef,
indexgroup: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<Pattern> {
@@ -126,7 +126,7 @@ mod _sre {
pub flags: SreFlag,
pub code: Vec<u32>,
pub groups: usize,
- pub groupindex: HashMap<String, usize>,
+ pub groupindex: PyDictRef,
pub indexgroup: Vec<Option<String>>,
}
@@ -207,6 +207,10 @@ mod _sre {
fn flags(&self) -> u16 {
self.flags.bits()
}
+ #[pyproperty]
+ fn groupindex(&self) -> PyDictRef {
+ self.groupindex.clone()
+ }
fn subx(&self, sub_args: SubArgs, vm: &VirtualMachine) -> PyResult<PyStrRef> {
Err(vm.new_not_implemented_error("".to_owned()))
@@ -310,6 +314,13 @@ mod _sre {
self.get_index(group.unwrap_or(0), vm).map(|x| self.regs[x])
}
+ #[pymethod]
+ fn expand(zelf: PyRef<Match>, template: PyStrRef, vm: &VirtualMachine) -> PyResult {
+ let re = vm.import("re", &[], 0)?;
+ let func = vm.get_attribute(re, "_expand")?;
+ vm.invoke(&func, (zelf.pattern.clone(), zelf, template))
+ }
+
#[pymethod]
fn group(&self, args: Args<isize>, vm: &VirtualMachine) -> PyResult {
let mut args = args.into_vec();
