This file is indexed.

/usr/lib/python3/dist-packages/fontTools/varLib/designspace.py is in python3-fonttools 3.21.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"""Rudimentary support for loading MutatorMath .designspace files."""
from __future__ import print_function, division, absolute_import
from fontTools.misc.py23 import *
try:
	import xml.etree.cElementTree as ET
except ImportError:
	import xml.etree.ElementTree as ET

__all__ = ['load', 'loads']

namespaces = {'xml': '{http://www.w3.org/XML/1998/namespace}'}


def _xml_parse_location(et):
	loc = {}
	for dim in et.find('location'):
		assert dim.tag == 'dimension'
		name = dim.attrib['name']
		value = float(dim.attrib['xvalue'])
		assert name not in loc
		loc[name] = value
	return loc


def _load_item(et):
	item = dict(et.attrib)
	for element in et:
		if element.tag == 'location':
			value = _xml_parse_location(et)
		else:
			value = {}
			if 'copy' in element.attrib:
				value['copy'] = bool(int(element.attrib['copy']))
			# TODO load more?!
		item[element.tag] = value
	return item


def _xml_parse_axis_or_map(element):
	dic = {}
	for name in element.attrib:
		if name in ['name', 'tag']:
			dic[name] = element.attrib[name]
		else:
			dic[name] = float(element.attrib[name])
	return dic


def _load_axis(et):
	item = _xml_parse_axis_or_map(et)
	maps = []
	labelnames = {}
	for element in et:
		assert element.tag in ['labelname', 'map']
		if element.tag == 'labelname':
			lang = element.attrib["{0}lang".format(namespaces['xml'])]
			labelnames[lang] = element.text
		elif element.tag == 'map':
			maps.append(_xml_parse_axis_or_map(element))
	if labelnames:
		item['labelname'] = labelnames
	if maps:
		item['map'] = maps
	return item


def _load(et):
	designspace = {}
	ds = et.getroot()

	axes_element = ds.find('axes')
	if axes_element is not None:
		axes = []
		for et in axes_element:
			axes.append(_load_axis(et))
		designspace['axes'] = axes

	sources_element = ds.find('sources')
	if sources_element is not None:
		sources = []
		for et in sources_element:
			sources.append(_load_item(et))
		designspace['sources'] = sources

	instances_element = ds.find('instances')
	if instances_element is not None:
		instances = []
		for et in instances_element:
			instances.append(_load_item(et))
		designspace['instances'] = instances

	return designspace


def load(filename):
	"""Load designspace from a file name or object.
	   Returns a dictionary containing three (optional) items:
	   - list of "axes"
	   - list of "sources" (aka masters)
	   - list of "instances"
	"""
	return _load(ET.parse(filename))


def loads(string):
	"""Load designspace from a string."""
	return _load(ET.fromstring(string))

if __name__ == '__main__':
	import sys
	from pprint import pprint
	for f in sys.argv[1:]:
		pprint(load(f))