<commit_before>"""xmlWriter.py -- Simple XML authoring class"""

from __future__ import print_function, division, absolute_import
from fontTools.misc.py23 import *
import sys
import string

INDENT = "  "


class XMLWriter(object):
	
	def __init__(self, fileOrPath, indentwhite=INDENT, idlefunc=None, encoding=None):
		if encoding is None:
			encoding = 'utf-8'
		if encoding.lower().replace('-','') != 'utf8':
			raise Exception('Only UTF-8 encoding is supported.')
		if fileOrPath == '-':
			fileOrPath = sys.stdout
		if not hasattr(fileOrPath, "write"):
			self.file = open(fileOrPath, "wb")
		else:
			# assume writable file object
			self.file = fileOrPath

		# Figure out if writer expects bytes or unicodes
		try:
			# The bytes check should be first.  See:
			# https://github.com/behdad/fonttools/pull/233
			self.file.write(b'')
			self.totype = tobytes
		except TypeError:
			# This better not fail.
			self.file.write(tounicode(''))
			self.totype = tounicode
		self.indentwhite = self.totype(indentwhite)
		self.newlinestr = self.totype('\n')
		self.indentlevel = 0
		self.stack = []
		self.needindent = 1
		self.idlefunc = idlefunc
		self.idlecounter = 0
		self._writeraw(b'<?xml version="1.0" encoding="utf-8"?>')
		self.newline()
	
	def close(self):
		self.file.close()
	
	def write(self, string, indent=True):
		"""Writes text."""
		self._writeraw(escape(string), indent=indent)

	def writecdata(self, string):
		"""Writes text in a CDATA section."""
		self._writeraw("<![CDATA[" + string + "]]>")

	def write8bit(self, data, strip=False):
		"""Writes a bytes() sequence into the XML, escaping
		non-ASCII bytes.  When this is read in xmlReader,
		the original bytes can be recovered by encoding to
		'latin-1'."""
		self._writeraw(escape8bit(data), strip=strip)

	def write_noindent(self, string):
		"""Writes text without indentation."""
		self._writeraw(escape(string), indent=False)<commit_msg>Use os.linesep for line separator in xmlWriter<commit_after>"""xmlWriter.py -- Simple XML authoring class"""

from __future__ import print_function, division, absolute_import
from fontTools.misc.py23 import *
import sys
import os
import string

INDENT = "  "


class XMLWriter(object):
	
	def __init__(self, fileOrPath, indentwhite=INDENT, idlefunc=None, encoding=None):
		if encoding is None:
			encoding = 'utf-8'
		if encoding.lower().replace('-','') != 'utf8':
			raise Exception('Only UTF-8 encoding is supported.')
		if fileOrPath == '-':
			fileOrPath = sys.stdout
		if not hasattr(fileOrPath, "write"):
			self.file = open(fileOrPath, "wb")
		else:
			# assume writable file object
			self.file = fileOrPath

		# Figure out if writer expects bytes or unicodes
		try:
			# The bytes check should be first.  See:
			# https://github.com/behdad/fonttools/pull/233
			self.file.write(b'')
			self.totype = tobytes
		except TypeError:
			# This better not fail.
			self.file.write(tounicode(''))
			self.totype = tounicode
		self.indentwhite = self.totype(indentwhite)
		self.newlinestr = self.totype(os.linesep)
		self.indentlevel = 0
		self.stack = []
		self.needindent = 1
		self.idlefunc = idlefunc
		self.idlecounter = 0
		self._writeraw(b'<?xml version="1.0" encoding="utf-8"?>')
		self.newline()
	
	def close(self):
		self.file.close()
	
	def write(self, string, indent=True):
		"""Writes text."""
		self._writeraw(escape(string), indent=indent)

	def writecdata(self, string):
		"""Writes text in a CDATA section."""
		self._writeraw("<![CDATA[" + string + "]]>")

	def write8bit(self, data, strip=False):
		"""Writes a bytes() sequence into the XML, escaping
		non-ASCII bytes.  When this is read in xmlReader,
		the original bytes can be recovered by encoding to
		'latin-1'."""
		self._writeraw(escape8bit(data), strip=strip)

	def write_noindent(self, string):
		"""Writes text without indentation."""
		self._writeraw(escape(string), indent=False)
{'fraction_non_alphanumeric': 0.1374774310033531, 'fraction_numerical': 0.008769667268506576, 'mean_word_length': 4.102631578947369, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 2, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 7}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '338961', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1276, 'n_words': 345}