@@ -51,7 +51,7 @@ impl JID {
5151 fn server ( & self ) -> String {
5252 self . inner . server . clone ( )
5353 }
54- fn __repr__ ( & self ) -> String {
54+ pub fn __repr__ ( & self ) -> String {
5555 format ! ( "JID(user='{}', server='{}')" , self . inner. user, self . inner. server)
5656 }
5757}
@@ -318,144 +318,3 @@ pub struct UploadResponse {
318318 #[ pyo3( get) ]
319319 pub file_length : u64 ,
320320}
321- pub enum NodeValueEnum {
322- String ( String ) ,
323- Jid ( pyo3:: Py < JID > ) ,
324- }
325-
326- /// PyClass wrapper untuk NodeValue
327- #[ pyclass]
328- pub struct NodeValue {
329- inner : NodeValueEnum ,
330- }
331-
332- #[ pymethods]
333- impl NodeValue {
334- #[ new]
335- pub fn new_string ( value : String ) -> Self {
336- Self { inner : NodeValueEnum :: String ( value) }
337- }
338-
339- #[ staticmethod]
340- pub fn jid ( value : pyo3:: Py < JID > ) -> Self {
341- Self { inner : NodeValueEnum :: Jid ( value) }
342- }
343-
344- pub fn set_string ( & mut self , value : String ) {
345- self . inner = NodeValueEnum :: String ( value) ;
346- }
347-
348- pub fn set_jid ( & mut self , value : pyo3:: Py < JID > ) {
349- self . inner = NodeValueEnum :: Jid ( value) ;
350- }
351-
352- pub fn __repr__ ( & self , py : Python < ' _ > ) -> String {
353- match & self . inner {
354- NodeValueEnum :: String ( s) => format ! ( "NodeValue::String({})" , s) ,
355- NodeValueEnum :: Jid ( jid) => {
356- let jid_ref = jid. bind ( py) . borrow ( ) ;
357- format ! ( "NodeValue::Jid({})" , jid_ref. __repr__( ) )
358- }
359- }
360- }
361- }
362-
363- /// NodeContent enum internal
364- pub enum NodeContentEnum {
365- Bytes ( Vec < u8 > ) ,
366- String ( String ) ,
367- Nodes ( Vec < pyo3:: Py < Node > > ) ,
368- }
369-
370- /// PyClass wrapper untuk NodeContent
371- #[ pyclass]
372- pub struct NodeContent {
373- inner : NodeContentEnum ,
374- }
375-
376- #[ pymethods]
377- impl NodeContent {
378- #[ staticmethod]
379- pub fn bytes ( data : Vec < u8 > ) -> Self {
380- Self { inner : NodeContentEnum :: Bytes ( data) }
381- }
382-
383- #[ staticmethod]
384- pub fn string ( data : String ) -> Self {
385- Self { inner : NodeContentEnum :: String ( data) }
386- }
387-
388- #[ staticmethod]
389- pub fn nodes ( data : Vec < pyo3:: Py < Node > > ) -> Self {
390- Self { inner : NodeContentEnum :: Nodes ( data) }
391- }
392-
393- pub fn is_bytes ( & self ) -> bool {
394- matches ! ( self . inner, NodeContentEnum :: Bytes ( _) )
395- }
396-
397- pub fn is_string ( & self ) -> bool {
398- matches ! ( self . inner, NodeContentEnum :: String ( _) )
399- }
400-
401- pub fn is_nodes ( & self ) -> bool {
402- matches ! ( self . inner, NodeContentEnum :: Nodes ( _) )
403- }
404-
405- pub fn as_bytes < ' py > ( & self , py : Python < ' py > ) -> Option < pyo3:: Py < PyBytes > > {
406- match & self . inner {
407- NodeContentEnum :: Bytes ( b) => Some ( PyBytes :: new ( py, b) . unbind ( ) ) ,
408- _ => None ,
409- }
410- }
411-
412- pub fn as_string ( & self ) -> Option < & str > {
413- match & self . inner {
414- NodeContentEnum :: String ( s) => Some ( s) ,
415- _ => None ,
416- }
417- }
418-
419- pub fn as_nodes ( & self ) -> Option < & Vec < pyo3:: Py < Node > > > {
420- match & self . inner {
421- NodeContentEnum :: Nodes ( n) => Some ( n) ,
422- _ => None ,
423- }
424- }
425-
426- pub fn __repr__ ( & self ) -> String {
427- match & self . inner {
428- NodeContentEnum :: Bytes ( _) => "NodeContent::Bytes(...)" . to_string ( ) ,
429- NodeContentEnum :: String ( s) => format ! ( "NodeContent::String({})" , s) ,
430- NodeContentEnum :: Nodes ( n) => format ! ( "NodeContent::Nodes(len={})" , n. len( ) ) ,
431- }
432- }
433- }
434-
435- /// PyClass Node
436- #[ pyclass]
437- pub struct Node {
438- #[ pyo3( get, set) ]
439- pub tag : String ,
440-
441- #[ pyo3( get, set) ]
442- pub content : Option < pyo3:: Py < NodeContent > > ,
443- }
444-
445- #[ pymethods]
446- impl Node {
447- #[ new]
448- pub fn new ( tag : String , content : Option < pyo3:: Py < NodeContent > > ) -> Self {
449- Self { tag, content }
450- }
451-
452- pub fn __repr__ ( & self , py : Python < ' _ > ) -> String {
453- match & self . content {
454- Some ( c) => {
455- let content_ref = c. bind ( py) . borrow ( ) ;
456- format ! ( "Node(tag={}, content={})" , self . tag, content_ref. __repr__( ) )
457- }
458- None => format ! ( "Node(tag={}, content=None)" , self . tag) ,
459- }
460- }
461- }
0 commit comments