| 397 | |
| 398 | #[pyfunction(name = "ParserCreate")] |
| 399 | fn parser_create( |
| 400 | args: ParserCreateArgs, |
| 401 | vm: &VirtualMachine, |
| 402 | ) -> PyResult<PyExpatLikeXmlParserRef> { |
| 403 | // Validate namespace_separator: must be at most one character |
| 404 | let ns_sep = match args.namespace_separator { |
| 405 | Some(ref s) => { |
| 406 | if s.as_str().chars().count() > 1 { |
| 407 | return Err(vm.new_value_error( |
| 408 | "namespace_separator must be at most one character, omitted, or None", |
| 409 | )); |
| 410 | } |
| 411 | Some(s.as_str().to_owned()) |
| 412 | } |
| 413 | None => None, |
| 414 | }; |
| 415 | |
| 416 | // encoding parameter is currently not used (xml-rs handles encoding from XML declaration) |
| 417 | let _ = args.encoding; |
| 418 | |
| 419 | PyExpatLikeXmlParser::new(ns_sep, args.intern, vm) |
| 420 | } |
| 421 | |
| 422 | // TODO: Tie this exception to the module's state. |
| 423 | #[pyattr] |