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

Function compile

crates/vm/src/stdlib/_sre.rs:88–113  ·  view source on GitHub ↗
(
        pattern: PyObjectRef,
        flags: u16,
        code: PyObjectRef,
        groups: usize,
        groupindex: PyDictRef,
        indexgroup: PyObjectRef,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

86
87 #[pyfunction]
88 fn compile(
89 pattern: PyObjectRef,
90 flags: u16,
91 code: PyObjectRef,
92 groups: usize,
93 groupindex: PyDictRef,
94 indexgroup: PyObjectRef,
95 vm: &VirtualMachine,
96 ) -> PyResult<Pattern> {
97 // FIXME:
98 // pattern could only be None if called by re.Scanner
99 // re.Scanner has no official API and in CPython's implement
100 // isbytes will be hanging (-1)
101 // here is just a hack to let re.Scanner works only with str not bytes
102 let isbytes = !vm.is_none(&pattern) && !pattern.downcastable::<PyStr>();
103 let code = code.try_to_value(vm)?;
104 Ok(Pattern {
105 pattern,
106 flags: SreFlag::from_bits_truncate(flags),
107 code,
108 groups,
109 groupindex,
110 indexgroup: indexgroup.try_to_value(vm)?,
111 isbytes,
112 })
113 }
114
115 #[pyattr]
116 #[pyclass(name = "SRE_Template")]

Callers 1

sub_implMethod · 0.70

Calls 2

try_to_valueMethod · 0.80
is_noneMethod · 0.45

Tested by

no test coverage detected