Skip to content

Commit

Permalink
Allow non-ascii chars in 'short' and 'description'
Browse files Browse the repository at this point in the history
of zones, services and icmp-types.
  • Loading branch information
jpopelka committed Jul 18, 2013
1 parent 9c136d6 commit 6d57254
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/firewall/core/io/icmptype.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def icmptype_writer(icmptype, path=None):

# short
if icmptype.short and icmptype.short != "":
if isinstance(zone.short, bytes):
zone.short = zone.short.decode('utf-8')
handler.ignorableWhitespace(" ")
handler.startElement("short", { })
handler.characters(icmptype.short)
Expand All @@ -134,6 +136,8 @@ def icmptype_writer(icmptype, path=None):

# description
if icmptype.description and icmptype.description != "":
if isinstance(zone.description, bytes):
zone.description = zone.description.decode('utf-8')
handler.ignorableWhitespace(" ")
handler.startElement("description", { })
handler.characters(icmptype.description)
Expand Down
8 changes: 7 additions & 1 deletion src/firewall/core/io/io_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,21 @@ def endElement(self, name):

def characters(self, content):
if self._element != None:
self._element += str(content.replace('\n', ' '))
self._element += content.replace('\n', ' ')

class IO_Object_XMLGenerator(saxutils.XMLGenerator):
def __init__(self, out):
saxutils.XMLGenerator.__init__(self, out, "utf-8")

def simpleElement(self, name, attrs):
if isinstance(name, bytes):
name = name.decode('utf-8')
self._write(u'<' + name)
for (name, value) in attrs.items():
if isinstance(name, bytes):
name = name.decode('utf-8')
if isinstance(value, bytes):
value = value.decode('utf-8')
self._write(u' %s=%s' % (name, saxutils.quoteattr(value)))
self._write(u'/>')

Expand Down
4 changes: 4 additions & 0 deletions src/firewall/core/io/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ def service_writer(service, path=None):

# short
if service.short and service.short != "":
if isinstance(zone.short, bytes):
zone.short = zone.short.decode('utf-8')
handler.ignorableWhitespace(" ")
handler.startElement("short", { })
handler.characters(service.short)
Expand All @@ -162,6 +164,8 @@ def service_writer(service, path=None):

# description
if service.description and service.description != "":
if isinstance(zone.description, bytes):
zone.description = zone.description.decode('utf-8')
handler.ignorableWhitespace(" ")
handler.startElement("description", { })
handler.characters(service.description)
Expand Down
4 changes: 4 additions & 0 deletions src/firewall/core/io/zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ def zone_writer(zone, path=None):

# short
if zone.short and zone.short != "":
if isinstance(zone.short, bytes):
zone.short = zone.short.decode('utf-8')
handler.ignorableWhitespace(" ")
handler.startElement("short", { })
handler.characters(zone.short)
Expand All @@ -484,6 +486,8 @@ def zone_writer(zone, path=None):

# description
if zone.description and zone.description != "":
if isinstance(zone.description, bytes):
zone.description = zone.description.decode('utf-8')
handler.ignorableWhitespace(" ")
handler.startElement("description", { })
handler.characters(zone.description)
Expand Down

0 comments on commit 6d57254

Please sign in to comment.