Skip to content

Commit

Permalink
Windows fix for xml-format command
Browse files Browse the repository at this point in the history
  • Loading branch information
lowell80 committed Jun 5, 2019
1 parent e84144f commit b71f345
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ksconf/commands/xmlformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import re
import os
import sys
from io import BytesIO, StringIO
from collections import Counter

Expand All @@ -24,6 +25,8 @@
# Lazy loaded by _handle_imports()
etree = None

windows = sys.platform == "nt"



class FileReadlinesCache(object):
Expand Down Expand Up @@ -143,7 +146,10 @@ def guess_indent(elem, default=2):
def pretty_print_xml(cls, path, default_indent=2):
# Copied from https://stackoverflow.com/a/5649263/315892
parser = etree.XMLParser(resolve_entities=False, strip_cdata=False)
document = etree.parse(path, parser)
# Could just parse the file directly, but that fails on windows for some reason.
# While slower, no significant enough to justify platform-specific code paths
with open(path, "rb") as stream:
document = etree.parse(stream, parser)
root = document.getroot()
i = cls.guess_indent(root, default_indent)
cls.indent_tree(root, indent=i)
Expand Down

0 comments on commit b71f345

Please sign in to comment.