MCPcopy Index your code
hub / github.com/RustPython/RustPython / groupdict

Method groupdict

crates/vm/src/stdlib/_sre.rs:773–793  ·  view source on GitHub ↗
(
            &self,
            default: OptionalArg<PyObjectRef>,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

771
772 #[pymethod]
773 fn groupdict(
774 &self,
775 default: OptionalArg<PyObjectRef>,
776 vm: &VirtualMachine,
777 ) -> PyResult<PyDictRef> {
778 let default = default.unwrap_or_else(|| vm.ctx.none());
779
780 with_sre_str!(self.pattern, &self.string, vm, |str_drive| {
781 let dict = vm.ctx.new_dict();
782
783 for (key, index) in self.pattern.groupindex.clone() {
784 let value = self
785 .get_index(index, vm)
786 .and_then(|x| self.get_slice(x, str_drive, vm))
787 .map(|x| x.to_pyobject(vm))
788 .unwrap_or_else(|| default.clone());
789 dict.set_item(&*key, value, vm)?;
790 }
791 Ok(dict)
792 })
793 }
794
795 fn get_index(&self, group: PyObjectRef, vm: &VirtualMachine) -> Option<usize> {
796 let i = if let Ok(i) = group.try_index(vm) {

Callers 11

_strptimeFunction · 0.80
resolve_nameFunction · 0.80
_date_from_stringFunction · 0.80
_parse_format_specifierFunction · 0.80
convertMethod · 0.80
validateMethod · 0.80
test_groupdictMethod · 0.80
test_bug_34294Method · 0.80
framework_infoFunction · 0.80
dylib_infoFunction · 0.80
stdlib_re.pyFile · 0.80

Calls 1

noneMethod · 0.80

Tested by 2

test_groupdictMethod · 0.64
test_bug_34294Method · 0.64