elem.append(self._xmlForFossil(subv)) else: subelem = etree.SubElement(elem, 'item') subelem.text = self._convert(subv) elif isinstance(v, dict): elem.append(self._xmlForFossil(v)) else: txt = self._convert(v) try: elem.text = txt except Exception: Logger.get('xmlSerializer').exception('Setting XML text value failed (id: %s, value %r)', id, txt) return felement def _execute(self, fossil, xml_declaration=True): if type(fossil) == list: # collection of fossils doc = etree.ElementTree(etree.Element("collection")) for elem in fossil: self._xmlForFossil(elem, doc) result = doc else: result = self._xmlForFossil(fossil) return etree.tostring(result, pretty_print=self.pretty, xml_declaration=xml_declaration, encoding='utf-8') Serializer.register('xml', XMLSerializer)
return self._file.canAccess(aw) @classmethod def _matchPath(cls, path): if not hasattr(cls, '_RE'): cls._RE = re.compile(r'/' + cls.PREFIX + '/event/' + cls.RE + r'\.(\w+)$') return cls._RE.match(path) class FileSerializer(Serializer): encapsulate = False schemaless = False def _execute(self, fdata): cfg = Config.getInstance() self._mime = cfg.getFileTypeMimeType(fdata['ftype']) if cfg.getUseXSendFile(): return "" else: return fdata['data'] def set_headers(self, req): super(FileSerializer, self).set_headers(req) set_file_headers(req, **self._obj) Serializer.register('bin', FileSerializer)
# # Indico is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Indico; if not, see <http://www.gnu.org/licenses/>. """ json-based fossil serializer """ # indico imports from indico.util import json # module imports from indico.web.http_api.metadata.serializer import Serializer class JSONSerializer(Serializer): """ Does basically direct translation from the fossi """ _mime = 'application/json' def _execute(self, fossil): return json.dumps(fossil, pretty=self.pretty) Serializer.register('json', JSONSerializer)
elif type(v) == dict: elem.append(self._xmlForFossil(v)) else: txt = self._convert(v) try: elem.text = txt except Exception, e: Logger.get('xmlSerializer').error( 'Setting XML text value failed: %s (id: %s)' % (e, id)) return felement def _execute(self, fossil, xml_declaration=True): if type(fossil) == list: # collection of fossils doc = etree.ElementTree(etree.Element("collection")) for elem in fossil: self._xmlForFossil(elem, doc) result = doc else: result = self._xmlForFossil(fossil) return etree.tostring(result, pretty_print=self.pretty, xml_declaration=xml_declaration, encoding='utf-8') Serializer.register('xml', XMLSerializer)
self._attachment = Attachment.get(int(self._pathParams['res'])) if not self._attachment: raise HTTPAPIError("File not found", 404) def export_file(self, user): if self._attachment.type != AttachmentType.file: raise HTTPAPIError("Resource is not a file", 404) return self._attachment.file.send() def _has_access(self, user): return self._attachment.can_access(user) class FileSerializer(Serializer): encapsulate = False schemaless = False def _execute(self, fdata): return fdata def get_response_content_type(self): # we already have a response with the correct headers return None Serializer.register('bin', FileSerializer)
# WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Indico; if not, see <http://www.gnu.org/licenses/>. """ json-based fossil serializer """ # indico imports from indico.util import json # module imports from indico.web.http_api.metadata.serializer import Serializer class JSONSerializer(Serializer): """ Does basically direct translation from the fossi """ _mime = 'application/json' def _execute(self, fossil): return json.dumps(fossil, pretty=self.pretty) Serializer.register('json', JSONSerializer)
## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Indico;if not, see <http://www.gnu.org/licenses/>. """ json-based fossil serializer """ # indico imports from indico.util import json # module imports from indico.web.http_api.metadata.serializer import Serializer class JSONSerializer(Serializer): """ Does basically direct translation from the fossi """ _mime = "application/json" def _execute(self, fossil): return json.dumps(fossil, pretty=self.pretty) Serializer.register("json", JSONSerializer)
else: subelem = etree.SubElement(elem, "item") subelem.text = self._convert(subv) elif isinstance(v, dict): elem.append(self._xmlForFossil(v)) else: txt = self._convert(v) try: elem.text = txt except Exception: Logger.get("xmlSerializer").exception( "Setting XML text value failed (id: {}, value {!r})".format(id, txt) ) return felement def _execute(self, fossil, xml_declaration=True): if type(fossil) == list: # collection of fossils doc = etree.ElementTree(etree.Element("collection")) for elem in fossil: self._xmlForFossil(elem, doc) result = doc else: result = self._xmlForFossil(fossil) return etree.tostring(result, pretty_print=self.pretty, xml_declaration=xml_declaration, encoding="utf-8") Serializer.register("xml", XMLSerializer)