Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
futzu authored Nov 17, 2024
1 parent b02ae6d commit 0086882
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions threefive/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
from new_reader import reader


def rm_xmlattr(exemel,attr):
def rm_xmlattr(exemel, attr):
"""
rm_xmlattr remove an attr from
an xml string, byte string or Node instance.
"""
if isinstance(exemel,bytes):
exemel=exemel.decode()
if isinstance(exemel,Node):
exemel=exemel.mk()
reggie= re.compile(f'{attr}=".+?"')
if isinstance(exemel, bytes):
exemel = exemel.decode()
if isinstance(exemel, Node):
exemel = exemel.mk()
reggie = re.compile(f'{attr}=".+?"')
return "".join(reggie.split(exemel))


Expand Down Expand Up @@ -136,17 +136,17 @@ def __init__(self, name, value=None, attrs={}, ns=None):
def __repr__(self):
return self.mk()

def rm_attr(self,attr):
def rm_attr(self, attr):
"""
rm_attr remove an attribute
"""
self.attrs.pop(attr)

def add_attr(self,attr,value):
def add_attr(self, attr, value):
"""
add_attr add an attribute
"""
self.attrs[attr]=value
self.attrs[attr] = value

def set_depth(self):
"""
Expand All @@ -163,7 +163,7 @@ def get_indent(self):
tab = " "
return tab * self.depth

def _rendrd_children(self,obj,rendrd,ndent):
def _rendrd_children(self, obj, rendrd, ndent):
for child in obj.children:
rendrd += obj.mk(child)
return f"{rendrd}{ndent}</{obj.name}>\n"
Expand All @@ -186,18 +186,18 @@ def mk(self, obj=None):
return f"{rendrd}{obj.value}</{obj.name}>\n"
rendrd = f"{rendrd}\n"
if obj.children:
return self._rendrd_children(obj,rendrd,ndent)
return self._rendrd_children(obj, rendrd, ndent)
return rendrd.replace(">", "/>")

def add_child(self, child, slot=None):
"""
add_child adds a child node
set slot to insert at index slot.
"""
if slot ==None:
if slot == None:
self.children.append(child)
else:
self.children=self.children[:slot]+[child]+self.children[slot:]
self.children = self.children[:slot] + [child] + self.children[slot:]

def rm_child(self, child):
"""
Expand All @@ -208,11 +208,11 @@ def rm_child(self, child):
"""
self.children.remove(child)

def add_comment(self, comment,slot=None):
def add_comment(self, comment, slot=None):
"""
add_comment add a Comment node
"""
self.add_child(Comment(comment),slot)
self.add_child(Comment(comment), slot)


class Comment(Node):
Expand Down Expand Up @@ -290,19 +290,19 @@ def mk_active(self, node):
name = node[1:].split(" ", 1)[0].split(">", 1)[0].split(":")[-1]
self.active = name.replace("/", "").replace(">", "")

def _split_attrs(self,node):
def _split_attrs(self, node):
node = node.replace("='", '="').replace("' ", '" ')
attrs = [x for x in node.split(" ") if "=" in x]
return attrs

def mk_attrs(self, node):
"""
mk_attrs parses the current node for attributes
and stores them in self.stuff[self.active]
"""
if "!--" in node:
return False
attrs =self._split_attrs(node)
attrs = self._split_attrs(node)
parsed = {
x.split('="')[0]: unescape(x.split('="')[1].split('"')[0]) for x in attrs
}
Expand Down

0 comments on commit 0086882

Please sign in to comment.