@@ -6,7 +6,7 @@ use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pymethods};
66use rquest:: Utf8Bytes ;
77
88use crate :: {
9- buffer:: { Buffer , BytesBuffer , PyBufferProtocol } ,
9+ buffer:: { BytesBuffer , PyBufferProtocol } ,
1010 error:: wrap_rquest_error,
1111 typing:: Json ,
1212} ;
@@ -37,13 +37,13 @@ impl Message {
3737 #[ getter]
3838 pub fn data < ' py > ( & self , py : Python < ' py > ) -> Option < Bound < ' py , PyAny > > {
3939 let bytes = match & self . 0 {
40- rquest:: Message :: Text ( text) => text. as_bytes ( ) ,
40+ rquest:: Message :: Text ( text) => text. clone ( ) . into ( ) ,
4141 rquest:: Message :: Binary ( bytes)
4242 | rquest:: Message :: Ping ( bytes)
43- | rquest:: Message :: Pong ( bytes) => bytes,
43+ | rquest:: Message :: Pong ( bytes) => bytes. clone ( ) ,
4444 _ => return None ,
4545 } ;
46- Buffer :: new ( bytes. to_vec ( ) ) . into_bytes_ref ( py) . ok ( )
46+ BytesBuffer :: new ( bytes) . into_bytes_ref ( py) . ok ( )
4747 }
4848
4949 /// Returns the text content of the message if it is a text message.
@@ -171,7 +171,7 @@ impl Message {
171171 #[ pyo3( signature = ( text) ) ]
172172 #[ inline( always) ]
173173 pub fn from_text ( text : PyBackedStr ) -> Self {
174- let msg = rquest:: Message :: Text ( rquest :: Utf8Bytes :: from ( text. as_ref ( ) as & str ) ) ;
174+ let msg = rquest:: Message :: text ( text. as_ref ( ) as & str ) ;
175175 Message ( msg)
176176 }
177177
0 commit comments