(
pattern: PyObjectRef,
flags: u16,
code: PyObjectRef,
groups: usize,
groupindex: PyDictRef,
indexgroup: PyObjectRef,
vm: &VirtualMachine,
)
| 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")] |
no test coverage detected