(&mut self, s: &[u8], flags: BytesLiteralFlags)
| 183 | } |
| 184 | |
| 185 | fn p_bytes_repr(&mut self, s: &[u8], flags: BytesLiteralFlags) { |
| 186 | // raw bytes are interpreted without escapes and should all be ascii (it's a python syntax |
| 187 | // error otherwise), but if this assumption is violated, a `Utf8Error` will be returned from |
| 188 | // `p_raw_bytes`, and we should fall back on the normal escaping behavior instead of |
| 189 | // panicking |
| 190 | if flags.prefix().is_raw() { |
| 191 | if let Ok(s) = std::str::from_utf8(s) { |
| 192 | write!(self.buffer, "{}", flags.display_contents(s)) |
| 193 | .expect("Writing to a String buffer should never fail"); |
| 194 | return; |
| 195 | } |
| 196 | } |
| 197 | let quote_style = self.mode.quote_style(flags); |
| 198 | let escape = AsciiEscape::with_preferred_quote(s, quote_style); |
| 199 | if let Some(len) = escape.layout().len { |
| 200 | self.buffer.reserve(len); |
| 201 | } |
| 202 | escape |
| 203 | .bytes_repr(flags.triple_quotes()) |
| 204 | .write(&mut self.buffer) |
| 205 | .expect("Writing to a String buffer should never fail"); |
| 206 | } |
| 207 | |
| 208 | fn p_str_repr(&mut self, s: &str, flags: impl Into<AnyStringFlags>) { |
| 209 | let flags = flags.into(); |
no test coverage detected