diff options
author | Jacek Antonelli | 2008-08-15 23:45:50 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:50 -0500 |
commit | 2a4dea528f670b9bb1f77ef27a8a1dd16603d114 (patch) | |
tree | 95c68e362703c9099d571ecbdc6142b1cda1e005 /linden/indra/lib | |
parent | Second Life viewer sources 1.20.6 (diff) | |
download | meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.zip meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.tar.gz meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.tar.bz2 meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.tar.xz |
Second Life viewer sources 1.20.7
Diffstat (limited to 'linden/indra/lib')
-rw-r--r-- | linden/indra/lib/python/indra/base/llsd.py | 85 | ||||
-rw-r--r-- | linden/indra/lib/python/indra/ipc/llsdhttp.py | 2 | ||||
-rw-r--r-- | linden/indra/lib/python/indra/util/named_query.py | 6 |
3 files changed, 92 insertions, 1 deletions
diff --git a/linden/indra/lib/python/indra/base/llsd.py b/linden/indra/lib/python/indra/base/llsd.py index 26ac3a2..cd23551 100644 --- a/linden/indra/lib/python/indra/base/llsd.py +++ b/linden/indra/lib/python/indra/base/llsd.py | |||
@@ -218,6 +218,78 @@ class LLSDXMLFormatter(object): | |||
218 | def format_xml(something): | 218 | def format_xml(something): |
219 | return LLSDXMLFormatter().format(something) | 219 | return LLSDXMLFormatter().format(something) |
220 | 220 | ||
221 | class LLSDXMLPrettyFormatter(LLSDXMLFormatter): | ||
222 | def __init__(self, indent_atom = None): | ||
223 | # Call the super class constructor so that we have the type map | ||
224 | super(LLSDXMLPrettyFormatter, self).__init__() | ||
225 | |||
226 | # Override the type map to use our specialized formatters to | ||
227 | # emit the pretty output. | ||
228 | self.type_map[list] = self.PRETTY_ARRAY | ||
229 | self.type_map[tuple] = self.PRETTY_ARRAY | ||
230 | self.type_map[types.GeneratorType] = self.PRETTY_ARRAY, | ||
231 | self.type_map[dict] = self.PRETTY_MAP | ||
232 | |||
233 | # Private data used for indentation. | ||
234 | self._indent_level = 1 | ||
235 | if indent_atom is None: | ||
236 | self._indent_atom = ' ' | ||
237 | else: | ||
238 | self._indent_atom = indent_atom | ||
239 | |||
240 | def _indent(self): | ||
241 | "Return an indentation based on the atom and indentation level." | ||
242 | return self._indent_atom * self._indent_level | ||
243 | |||
244 | def PRETTY_ARRAY(self, v): | ||
245 | rv = [] | ||
246 | rv.append('<array>\n') | ||
247 | self._indent_level = self._indent_level + 1 | ||
248 | rv.extend(["%s%s\n" % | ||
249 | (self._indent(), | ||
250 | self.generate(item)) | ||
251 | for item in v]) | ||
252 | self._indent_level = self._indent_level - 1 | ||
253 | rv.append(self._indent()) | ||
254 | rv.append('</array>') | ||
255 | return ''.join(rv) | ||
256 | |||
257 | def PRETTY_MAP(self, v): | ||
258 | rv = [] | ||
259 | rv.append('<map>\n') | ||
260 | self._indent_level = self._indent_level + 1 | ||
261 | keys = v.keys() | ||
262 | keys.sort() | ||
263 | rv.extend(["%s%s\n%s%s\n" % | ||
264 | (self._indent(), | ||
265 | self.elt('key', key), | ||
266 | self._indent(), | ||
267 | self.generate(v[key])) | ||
268 | for key in keys]) | ||
269 | self._indent_level = self._indent_level - 1 | ||
270 | rv.append(self._indent()) | ||
271 | rv.append('</map>') | ||
272 | return ''.join(rv) | ||
273 | |||
274 | def format(self, something): | ||
275 | data = [] | ||
276 | data.append('<?xml version="1.0" ?>\n<llsd>') | ||
277 | data.append(self.generate(something)) | ||
278 | data.append('</llsd>\n') | ||
279 | return '\n'.join(data) | ||
280 | |||
281 | def format_pretty_xml(something): | ||
282 | """@brief Serialize a python object as 'pretty' llsd xml. | ||
283 | |||
284 | The output conforms to the LLSD DTD, unlike the output from the | ||
285 | standard python xml.dom DOM::toprettyxml() method which does not | ||
286 | preserve significant whitespace. | ||
287 | This function is not necessarily suited for serializing very large | ||
288 | objects. It is not optimized by the cllsd module, and sorts on | ||
289 | dict (llsd map) keys alphabetically to ease human reading. | ||
290 | """ | ||
291 | return LLSDXMLPrettyFormatter().format(something) | ||
292 | |||
221 | class LLSDNotationFormatter(object): | 293 | class LLSDNotationFormatter(object): |
222 | def __init__(self): | 294 | def __init__(self): |
223 | self.type_map = { | 295 | self.type_map = { |
@@ -829,6 +901,7 @@ class LLSD(object): | |||
829 | 901 | ||
830 | parse = staticmethod(parse) | 902 | parse = staticmethod(parse) |
831 | toXML = staticmethod(format_xml) | 903 | toXML = staticmethod(format_xml) |
904 | toPrettyXML = staticmethod(format_pretty_xml) | ||
832 | toBinary = staticmethod(format_binary) | 905 | toBinary = staticmethod(format_binary) |
833 | toNotation = staticmethod(format_notation) | 906 | toNotation = staticmethod(format_notation) |
834 | 907 | ||
@@ -842,6 +915,16 @@ try: | |||
842 | except: | 915 | except: |
843 | print "Couldn't import mulib.stacked, not registering LLSD converters" | 916 | print "Couldn't import mulib.stacked, not registering LLSD converters" |
844 | else: | 917 | else: |
918 | def llsd_convert_json(llsd_stuff, request): | ||
919 | callback = request.get_header('callback') | ||
920 | if callback is not None: | ||
921 | ## See Yahoo's ajax documentation for information about using this | ||
922 | ## callback style of programming | ||
923 | ## http://developer.yahoo.com/common/json.html#callbackparam | ||
924 | req.write("%s(%s)" % (callback, simplejson.dumps(llsd_stuff))) | ||
925 | else: | ||
926 | req.write(simplejson.dumps(llsd_stuff)) | ||
927 | |||
845 | def llsd_convert_xml(llsd_stuff, request): | 928 | def llsd_convert_xml(llsd_stuff, request): |
846 | request.write(format_xml(llsd_stuff)) | 929 | request.write(format_xml(llsd_stuff)) |
847 | 930 | ||
@@ -849,6 +932,8 @@ else: | |||
849 | request.write(format_binary(llsd_stuff)) | 932 | request.write(format_binary(llsd_stuff)) |
850 | 933 | ||
851 | for typ in [LLSD, dict, list, tuple, str, int, float, bool, unicode, type(None)]: | 934 | for typ in [LLSD, dict, list, tuple, str, int, float, bool, unicode, type(None)]: |
935 | stacked.add_producer(typ, llsd_convert_json, 'application/json') | ||
936 | |||
852 | stacked.add_producer(typ, llsd_convert_xml, 'application/llsd+xml') | 937 | stacked.add_producer(typ, llsd_convert_xml, 'application/llsd+xml') |
853 | stacked.add_producer(typ, llsd_convert_xml, 'application/xml') | 938 | stacked.add_producer(typ, llsd_convert_xml, 'application/xml') |
854 | stacked.add_producer(typ, llsd_convert_xml, 'text/xml') | 939 | stacked.add_producer(typ, llsd_convert_xml, 'text/xml') |
diff --git a/linden/indra/lib/python/indra/ipc/llsdhttp.py b/linden/indra/lib/python/indra/ipc/llsdhttp.py index 378c1c2..24cad61 100644 --- a/linden/indra/lib/python/indra/ipc/llsdhttp.py +++ b/linden/indra/lib/python/indra/ipc/llsdhttp.py | |||
@@ -34,7 +34,7 @@ from indra.base import llsd | |||
34 | 34 | ||
35 | from eventlet import httpc | 35 | from eventlet import httpc |
36 | 36 | ||
37 | suite = httpc.HttpSuite(llsd.format_xml, llsd.parse, 'application/xml+llsd') | 37 | suite = httpc.HttpSuite(llsd.format_xml, llsd.parse, 'application/llsd+xml') |
38 | delete = suite.delete | 38 | delete = suite.delete |
39 | delete_ = suite.delete_ | 39 | delete_ = suite.delete_ |
40 | get = suite.get | 40 | get = suite.get |
diff --git a/linden/indra/lib/python/indra/util/named_query.py b/linden/indra/lib/python/indra/util/named_query.py index c52bfde..680d1f9 100644 --- a/linden/indra/lib/python/indra/util/named_query.py +++ b/linden/indra/lib/python/indra/util/named_query.py | |||
@@ -47,6 +47,9 @@ except NameError: | |||
47 | from indra.base import llsd | 47 | from indra.base import llsd |
48 | from indra.base import config | 48 | from indra.base import config |
49 | 49 | ||
50 | NQ_FILE_SUFFIX = config.get('named-query-file-suffix', '') | ||
51 | NQ_FILE_SUFFIX_LEN = len(NQ_FILE_SUFFIX) | ||
52 | |||
50 | _g_named_manager = None | 53 | _g_named_manager = None |
51 | 54 | ||
52 | def _init_g_named_manager(sql_dir = None): | 55 | def _init_g_named_manager(sql_dir = None): |
@@ -98,6 +101,9 @@ class NamedQuery(object): | |||
98 | a path to a file containing an llsd named query document.""" | 101 | a path to a file containing an llsd named query document.""" |
99 | self._stat_interval_seconds = 5 # 5 seconds | 102 | self._stat_interval_seconds = 5 # 5 seconds |
100 | self._name = name | 103 | self._name = name |
104 | if (filename is not None) \ | ||
105 | and (NQ_FILE_SUFFIX != filename[-NQ_FILE_SUFFIX_LEN:]): | ||
106 | filename = filename + NQ_FILE_SUFFIX | ||
101 | self._location = filename | 107 | self._location = filename |
102 | self._alternative = dict() | 108 | self._alternative = dict() |
103 | self._last_mod_time = 0 | 109 | self._last_mod_time = 0 |