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

Function parse_escapechar_from_obj

crates/stdlib/src/csv.rs:180–201  ·  view source on GitHub ↗
(vm: &VirtualMachine, obj: &PyObject)

Source from the content-addressed store, hash-verified

178 })
179 }
180 fn parse_escapechar_from_obj(vm: &VirtualMachine, obj: &PyObject) -> PyResult<Option<u8>> {
181 match_class!(match obj.get_attr("escapechar", vm)? {
182 s @ PyStr => {
183 Ok(Some(s.as_bytes().iter().copied().exactly_one().map_err(|_| {
184 new_csv_error(
185 vm,
186 format!(r#""escapechar" must be a unicode character or None, not a string of length {}"#, s.len()),
187 )
188 })?))
189 }
190 _n @ PyNone => {
191 Ok(None)
192 }
193 attr => {
194 let msg = format!(
195 r#""escapechar" must be a unicode character or None, not {}"#,
196 attr.class()
197 );
198 Err(vm.new_type_error(msg.to_owned()))
199 }
200 })
201 }
202 fn prase_lineterminator_from_obj(vm: &VirtualMachine, obj: &PyObject) -> PyResult<Terminator> {
203 match_class!(match obj.get_attr("lineterminator", vm)? {
204 s @ PyStr => {

Callers 1

try_from_objectMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected