comparison rust/hg-cpython/src/filepatterns.rs @ 43737:dc4e74d0ef96

py3: send bytes from Rust-created warning patterns Python code expects bytes in both Python 2 and Python 3, so we should send bytes. Differential Revision: https://phab.mercurial-scm.org/D7454
author Rapha?l Gom?s <rgomes@octobus.net>
date Mon, 18 Nov 2019 17:37:59 +0100
parents 7a01778bc7b7
children 4f1cddd1939e
comparison
equal deleted inserted replaced
43736:794426e96970 43737:dc4e74d0ef96
11 //! and can be used as replacement for the the pure `filepatterns` Python 11 //! and can be used as replacement for the the pure `filepatterns` Python
12 //! module. 12 //! module.
13 //! 13 //!
14 use crate::exceptions::{PatternError, PatternFileError}; 14 use crate::exceptions::{PatternError, PatternFileError};
15 use cpython::{ 15 use cpython::{
16 PyBytes, PyDict, PyModule, PyObject, PyResult, PyString, PyTuple, Python, 16 PyBytes, PyDict, PyModule, PyObject, PyResult, PyTuple, Python, ToPyObject,
17 ToPyObject,
18 }; 17 };
19 use hg::{ 18 use hg::{
20 build_single_regex, read_pattern_file, utils::files::get_path_from_bytes, 19 build_single_regex, read_pattern_file, utils::files::get_path_from_bytes,
21 LineNumber, PatternTuple, 20 LineNumber, PatternTuple,
22 }; 21 };
64 } 63 }
65 64
66 fn warnings_to_py_bytes( 65 fn warnings_to_py_bytes(
67 py: Python, 66 py: Python,
68 warnings: &[(PathBuf, Vec<u8>)], 67 warnings: &[(PathBuf, Vec<u8>)],
69 ) -> Vec<(PyString, PyBytes)> { 68 ) -> Vec<(PyBytes, PyBytes)> {
70 warnings 69 warnings
71 .iter() 70 .iter()
72 .map(|(path, syn)| { 71 .map(|(path, syn)| {
73 ( 72 (
74 PyString::new(py, &path.to_string_lossy()), 73 PyBytes::new(py, &path.to_string_lossy().as_bytes()),
75 PyBytes::new(py, syn), 74 PyBytes::new(py, syn),
76 ) 75 )
77 }) 76 })
78 .collect() 77 .collect()
79 } 78 }