Nyx Node
Toggle main menu visibility
Loading...
Searching...
No Matches
xml.py
1
# -*- coding: utf-8 -*-
2
########################################################################################################################
3
# NyxNode
4
# Author: Jérôme ODIER <jerome.odier@lpsc.in2p3.fr>
5
# SPDX-License-Identifier: GPL-3.0+
6
########################################################################################################################
7
8
from
__future__
import
annotations
9
10
########################################################################################################################
11
12
import
typing
13
import
weakref
14
15
########################################################################################################################
16
17
from
.
import
bind
18
19
if
typing.TYPE_CHECKING:
20
21
from
.obj
import
NyxObject
22
23
########################################################################################################################
24
25
class
NyxXMLDoc
:
26
"""!
27
@brief XML document.
28
"""
29
30
####################################################################################################################
31
32
def
__init__
(self, ptr: int):
33
"""!
34
@brief Wraps a C XML document pointer.
35
36
@param ptr XML document pointer.
37
"""
38
39
self.
_ptr
= bind.check_ptr(ptr,
'nyx_xmldoc_t'
)
40
41
self.
_finalizer
= weakref.finalize(self, NyxXMLDoc._finalize, self.
_ptr
)
42
43
####################################################################################################################
44
45
@staticmethod
46
def
_finalize(ptr: int) ->
None
:
47
48
bind.lib.nyx_xmldoc_free(ptr)
49
50
####################################################################################################################
51
52
@property
53
def
ptr(self) -> int:
54
"""!
55
@private
56
@brief C pointer to the XML document object.
57
"""
58
59
if
not
self.
_ptr
:
60
61
raise
ValueError(
'Nyx XMLDoc has been finalized'
)
62
63
return
self.
_ptr
64
65
####################################################################################################################
66
67
@staticmethod
68
def
from_string
(string: str) -> NyxXMLDoc:
69
"""!
70
@brief Parses an XML document from a string.
71
72
@param string XML string.
73
@return The new XML document.
74
"""
75
76
from
.obj
import
NyxObject
77
78
return
NyxXMLDoc
(bind.lib.nyx_xmldoc_parse(bind.as_bytes(string, allow_none =
False
)))
79
80
####################################################################################################################
81
82
def
to_string
(self) -> str:
83
"""!
84
@brief Returns a string representing this XML document.
85
86
@return A string that represents this XML document.
87
"""
88
89
return
bind.take_string(bind.lib.nyx_xmldoc_to_string(self.
ptr
))
90
91
####################################################################################################################
92
93
def
to_json
(self) -> NyxObject:
94
"""!
95
@brief Converts this XML Nyx / INDI command to the JSON one.
96
97
@return The corresponding JSON Nyx / INDI command.
98
"""
99
100
return
NyxObject
(bind.lib.nyx_xmldoc_to_object(self.
ptr
))
101
102
####################################################################################################################
103
104
def
__eq__(self, other) -> bool:
105
106
if
not
isinstance(other, NyxXMLDoc):
107
108
return
NotImplemented
109
110
return
self.
to_string
() == other.to_string()
111
112
####################################################################################################################
113
114
def
__str__(self) -> str:
115
116
return
self.
to_string
()
117
118
def
__repr__(self) -> str:
119
120
return
self.
to_string
()
121
122
########################################################################################################################
123
124
__all__ = [name
for
name
in
globals()
if
name.lower().startswith(
'nyx'
)]
125
126
########################################################################################################################
nyx.obj.NyxObject
Base class for JSON Nyx objects.
Definition
obj.py:44
nyx.xml.NyxXMLDoc
XML document.
Definition
xml.py:25
nyx.xml.NyxXMLDoc._ptr
_ptr
Definition
xml.py:39
nyx.xml.NyxXMLDoc.to_json
NyxObject to_json(self)
Converts this XML Nyx / INDI command to the JSON one.
Definition
xml.py:93
nyx.xml.NyxXMLDoc._finalizer
_finalizer
Definition
xml.py:41
nyx.xml.NyxXMLDoc.from_string
NyxXMLDoc from_string(str string)
Parses an XML document from a string.
Definition
xml.py:68
nyx.xml.NyxXMLDoc.__init__
__init__(self, int ptr)
Wraps a C XML document pointer.
Definition
xml.py:32
nyx.xml.NyxXMLDoc.to_string
str to_string(self)
Returns a string representing this XML document.
Definition
xml.py:82
nyx.xml.NyxXMLDoc.ptr
ptr
Definition
xml.py:89
Author:
Jérôme ODIER
License:
LGPL-3.0-or-later
Copyright:
LPSC / CNRS