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

Method repr_wtf8

crates/vm/src/stdlib/_sre.rs:555–596  ·  view source on GitHub ↗
(zelf: &Py<Self>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

553 impl Representable for Pattern {
554 #[inline]
555 fn repr_wtf8(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<Wtf8Buf> {
556 let flag_names = [
557 ("re.IGNORECASE", SreFlag::IGNORECASE),
558 ("re.LOCALE", SreFlag::LOCALE),
559 ("re.MULTILINE", SreFlag::MULTILINE),
560 ("re.DOTALL", SreFlag::DOTALL),
561 ("re.UNICODE", SreFlag::UNICODE),
562 ("re.VERBOSE", SreFlag::VERBOSE),
563 ("re.DEBUG", SreFlag::DEBUG),
564 ("re.ASCII", SreFlag::ASCII),
565 ];
566
567 /* Omit re.UNICODE for valid string patterns. */
568 let mut flags = zelf.flags;
569 if !zelf.isbytes
570 && (flags & (SreFlag::LOCALE | SreFlag::UNICODE | SreFlag::ASCII))
571 == SreFlag::UNICODE
572 {
573 flags &= !SreFlag::UNICODE;
574 }
575
576 let flags = flag_names
577 .iter()
578 .filter(|(_, flag)| flags.contains(*flag))
579 .map(|(name, _)| name)
580 .join("|");
581
582 let pattern = zelf.pattern.repr(vm)?;
583 let mut result = Wtf8Buf::from("re.compile(");
584 let pat = if pattern.char_len() > 200 {
585 pattern.as_wtf8().code_points().take(200).collect()
586 } else {
587 pattern.as_wtf8().to_owned()
588 };
589 result.push_wtf8(&pat);
590 if !flags.is_empty() {
591 result.push_str(", ");
592 result.push_str(&flags);
593 }
594 result.push_char(')');
595 Ok(result)
596 }
597 }
598
599 #[pyattr]

Callers

nothing calls this directly

Calls 15

collectMethod · 0.80
code_pointsMethod · 0.80
push_wtf8Method · 0.80
joinMethod · 0.45
mapMethod · 0.45
filterMethod · 0.45
iterMethod · 0.45
containsMethod · 0.45
reprMethod · 0.45
char_lenMethod · 0.45
takeMethod · 0.45
as_wtf8Method · 0.45

Tested by

no test coverage detected