/usr/lib/python2.7/dist-packages/DisplayCAL/jsondict.py is in dispcalgui 3.1.0.0-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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | # -*- coding: utf-8 -*-
import codecs
import os
import demjson
from config import get_data_path
from debughelpers import handle_error
from util_str import safe_unicode
class JSONDict(dict):
"""
JSON dictionary with key -> value mappings.
The actual mappings are loaded from the source JSON file when they
are accessed.
"""
def __init__(self, path=None, encoding="UTF-8", errors="strict"):
dict.__init__(self)
self._isloaded = False
self.path = path
self.encoding = encoding
self.errors = errors
def __cmp__(self, other):
self.load()
return dict.__cmp__(self, other)
def __contains__(self, key):
self.load()
return dict.__contains__(self, key)
def __delitem__(self, key):
self.load()
dict.__delitem__(self, key)
def __delslice__(self, i, j):
self.load()
dict.__delslice__(self, i, j)
def __eq__(self, other):
self.load()
return dict.__eq__(self, other)
def __ge__(self, other):
self.load()
return dict.__ge__(self, other)
def __getitem__(self, name):
self.load()
return dict.__getitem__(self, name)
def __getslice__(self, i, j):
self.load()
return dict.__getslice__(self, i, j)
def __gt__(self, other):
self.load()
return dict.__gt__(self, other)
def __iter__(self):
self.load()
return dict.__iter__(self)
def __le__(self, other):
self.load()
return dict.__le__(self, other)
def __len__(self):
self.load()
return dict.__len__(self)
def __lt__(self, other):
self.load()
return dict.__lt__(self, other)
def __ne__(self, other):
self.load()
return dict.__ne__(self, other)
def __repr__(self):
self.load()
return dict.__repr__(self)
def __setitem__(self, name, value):
self.load()
dict.__setitem__(self, name, value)
def __sizeof__(self):
self.load()
return dict.__sizeof__(self)
def clear(self):
if not self._isloaded:
self._isloaded = True
dict.clear(self)
def copy(self):
self.load()
return dict.copy(self)
def get(self, name, fallback=None):
self.load()
return dict.get(self, name, fallback)
def has_key(self, name):
self.load()
return dict.has_key(self, name)
def items(self):
self.load()
return dict.items(self)
def iteritems(self):
self.load()
return dict.iteritems(self)
def iterkeys(self):
self.load()
return dict.iterkeys(self)
def itervalues(self):
self.load()
return dict.itervalues(self)
def keys(self):
self.load()
return dict.keys(self)
def load(self, path=None, encoding=None, errors=None):
if not self._isloaded and (path or self.path):
self._isloaded = True
if not path:
path = self.path
if path and not os.path.isabs(path):
path = get_data_path(path)
if path and os.path.isfile(path):
self.path = path
if encoding:
self.encoding = encoding
if errors:
self.errors = errors
else:
handle_error(UserWarning(u"Warning - JSON file '%s' not found" %
safe_unicode(path)))
return
try:
jsonfile = codecs.open(path, "rU", self.encoding, self.errors)
try:
dict.update(self, demjson.decode(jsonfile.read()))
except (UnicodeDecodeError,
demjson.JSONDecodeError), exception:
handle_error(UserWarning(
u"Warning - JSON file '%s': %s" %
tuple(safe_unicode(s) for s in
(path, safe_unicode(exception).capitalize() if
isinstance(exception,
demjson.JSONDecodeError)
else exception))))
except Exception, exception:
handle_error(UserWarning(u"Warning - JSON file '%s': %s" %
tuple(safe_unicode(s) for s in
(path, exception))))
else:
jsonfile.close()
def pop(self, key, *args):
self.load()
return dict.pop(self, key, *args)
def popitem(self, name, value):
self.load()
return dict.popitem(self, name, value)
def setdefault(self, name, value=None):
self.load()
return dict.setdefault(self, name, value)
def update(self, other):
self.load()
dict.update(self, other)
def values(self):
self.load()
return dict.values(self)
|