Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3..../site-pac.../yaml
File: serializer.py
[0] Fix | Delete
__all__ = ['Serializer', 'SerializerError']
[1] Fix | Delete
[2] Fix | Delete
from .error import YAMLError
[3] Fix | Delete
from .events import *
[4] Fix | Delete
from .nodes import *
[5] Fix | Delete
[6] Fix | Delete
class SerializerError(YAMLError):
[7] Fix | Delete
pass
[8] Fix | Delete
[9] Fix | Delete
class Serializer:
[10] Fix | Delete
[11] Fix | Delete
ANCHOR_TEMPLATE = 'id%03d'
[12] Fix | Delete
[13] Fix | Delete
def __init__(self, encoding=None,
[14] Fix | Delete
explicit_start=None, explicit_end=None, version=None, tags=None):
[15] Fix | Delete
self.use_encoding = encoding
[16] Fix | Delete
self.use_explicit_start = explicit_start
[17] Fix | Delete
self.use_explicit_end = explicit_end
[18] Fix | Delete
self.use_version = version
[19] Fix | Delete
self.use_tags = tags
[20] Fix | Delete
self.serialized_nodes = {}
[21] Fix | Delete
self.anchors = {}
[22] Fix | Delete
self.last_anchor_id = 0
[23] Fix | Delete
self.closed = None
[24] Fix | Delete
[25] Fix | Delete
def open(self):
[26] Fix | Delete
if self.closed is None:
[27] Fix | Delete
self.emit(StreamStartEvent(encoding=self.use_encoding))
[28] Fix | Delete
self.closed = False
[29] Fix | Delete
elif self.closed:
[30] Fix | Delete
raise SerializerError("serializer is closed")
[31] Fix | Delete
else:
[32] Fix | Delete
raise SerializerError("serializer is already opened")
[33] Fix | Delete
[34] Fix | Delete
def close(self):
[35] Fix | Delete
if self.closed is None:
[36] Fix | Delete
raise SerializerError("serializer is not opened")
[37] Fix | Delete
elif not self.closed:
[38] Fix | Delete
self.emit(StreamEndEvent())
[39] Fix | Delete
self.closed = True
[40] Fix | Delete
[41] Fix | Delete
#def __del__(self):
[42] Fix | Delete
# self.close()
[43] Fix | Delete
[44] Fix | Delete
def serialize(self, node):
[45] Fix | Delete
if self.closed is None:
[46] Fix | Delete
raise SerializerError("serializer is not opened")
[47] Fix | Delete
elif self.closed:
[48] Fix | Delete
raise SerializerError("serializer is closed")
[49] Fix | Delete
self.emit(DocumentStartEvent(explicit=self.use_explicit_start,
[50] Fix | Delete
version=self.use_version, tags=self.use_tags))
[51] Fix | Delete
self.anchor_node(node)
[52] Fix | Delete
self.serialize_node(node, None, None)
[53] Fix | Delete
self.emit(DocumentEndEvent(explicit=self.use_explicit_end))
[54] Fix | Delete
self.serialized_nodes = {}
[55] Fix | Delete
self.anchors = {}
[56] Fix | Delete
self.last_anchor_id = 0
[57] Fix | Delete
[58] Fix | Delete
def anchor_node(self, node):
[59] Fix | Delete
if node in self.anchors:
[60] Fix | Delete
if self.anchors[node] is None:
[61] Fix | Delete
self.anchors[node] = self.generate_anchor(node)
[62] Fix | Delete
else:
[63] Fix | Delete
self.anchors[node] = None
[64] Fix | Delete
if isinstance(node, SequenceNode):
[65] Fix | Delete
for item in node.value:
[66] Fix | Delete
self.anchor_node(item)
[67] Fix | Delete
elif isinstance(node, MappingNode):
[68] Fix | Delete
for key, value in node.value:
[69] Fix | Delete
self.anchor_node(key)
[70] Fix | Delete
self.anchor_node(value)
[71] Fix | Delete
[72] Fix | Delete
def generate_anchor(self, node):
[73] Fix | Delete
self.last_anchor_id += 1
[74] Fix | Delete
return self.ANCHOR_TEMPLATE % self.last_anchor_id
[75] Fix | Delete
[76] Fix | Delete
def serialize_node(self, node, parent, index):
[77] Fix | Delete
alias = self.anchors[node]
[78] Fix | Delete
if node in self.serialized_nodes:
[79] Fix | Delete
self.emit(AliasEvent(alias))
[80] Fix | Delete
else:
[81] Fix | Delete
self.serialized_nodes[node] = True
[82] Fix | Delete
self.descend_resolver(parent, index)
[83] Fix | Delete
if isinstance(node, ScalarNode):
[84] Fix | Delete
detected_tag = self.resolve(ScalarNode, node.value, (True, False))
[85] Fix | Delete
default_tag = self.resolve(ScalarNode, node.value, (False, True))
[86] Fix | Delete
implicit = (node.tag == detected_tag), (node.tag == default_tag)
[87] Fix | Delete
self.emit(ScalarEvent(alias, node.tag, implicit, node.value,
[88] Fix | Delete
style=node.style))
[89] Fix | Delete
elif isinstance(node, SequenceNode):
[90] Fix | Delete
implicit = (node.tag
[91] Fix | Delete
== self.resolve(SequenceNode, node.value, True))
[92] Fix | Delete
self.emit(SequenceStartEvent(alias, node.tag, implicit,
[93] Fix | Delete
flow_style=node.flow_style))
[94] Fix | Delete
index = 0
[95] Fix | Delete
for item in node.value:
[96] Fix | Delete
self.serialize_node(item, node, index)
[97] Fix | Delete
index += 1
[98] Fix | Delete
self.emit(SequenceEndEvent())
[99] Fix | Delete
elif isinstance(node, MappingNode):
[100] Fix | Delete
implicit = (node.tag
[101] Fix | Delete
== self.resolve(MappingNode, node.value, True))
[102] Fix | Delete
self.emit(MappingStartEvent(alias, node.tag, implicit,
[103] Fix | Delete
flow_style=node.flow_style))
[104] Fix | Delete
for key, value in node.value:
[105] Fix | Delete
self.serialize_node(key, node, None)
[106] Fix | Delete
self.serialize_node(value, node, key)
[107] Fix | Delete
self.emit(MappingEndEvent())
[108] Fix | Delete
self.ascend_resolver()
[109] Fix | Delete
[110] Fix | Delete
[111] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function