本文整理汇总了Python中indico.web.http_api.metadata.serializer.Serializer类的典型用法代码示例。如果您正苦于以下问题:Python Serializer类的具体用法?Python Serializer怎么用?Python Serializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Serializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _process
def _process(self):
filename = "%s-Categ.atom" % self._target.getName().replace("/", "")
hook = CategoryEventHook({'from': 'today'}, 'categ', {'idlist': self._target.getId(), 'dformat': 'atom'})
res = hook(self.getAW())
resultFossil = {'results': res[0], 'url': str(self._uh.getURL(self._target))}
serializer = Serializer.create('atom')
return send_file(filename, StringIO(serializer(resultFossil)), 'ATOM')
示例2: _process
def _process( self ):
filename = "%s-Session.ics"%self._session.getTitle()
hook = SessionHook({}, 'session', {'event': self._conf.getId(), 'idlist':self._session.getId(), 'dformat': 'ics'})
res = hook(self.getAW())
resultFossil = {'results': res[0]}
serializer = Serializer.create('ics')
return send_file(filename, StringIO(serializer(resultFossil)), 'ICAL')
示例3: _process
def _process(self):
filename = "%s-Event.ics" % self._target.getTitle()
hook = CategoryEventHook({'detail': self._detailLevel}, 'event',
{'idlist': self._conf.getId(), 'dformat': 'ics'})
res = hook(self.getAW())
resultFossil = {'results': res[0]}
serializer = Serializer.create('ics')
return send_file(filename, StringIO(serializer(resultFossil)), 'ICAL')
示例4: _process
def _process( self ):
if not self._target.isScheduled():
raise NoReportError(_("You cannot export the contribution with id %s because it is not scheduled")%self._target.getId())
filename = "%s-Contribution.ics"%self._target.getTitle()
hook = ContributionHook({}, 'contribution', {'event': self._conf.getId(), 'idlist':self._contrib.getId(), 'dformat': 'ics'})
res = hook(self.getAW())
resultFossil = {'results': res[0]}
serializer = Serializer.create('ics')
return send_file(filename, StringIO(serializer(resultFossil)), 'ICAL')
示例5: _process
def _process(self):
hook = CategoryEventHook({"from": ["today"]}, "categ", {"idlist": self._target.getId(), "dformat": "atom"})
res = hook(self.getAW(), self._req)
resultFossil = {"results": res[0], "url": str(self._uh.getURL(self._target))}
serializer = Serializer.create("atom")
data = serializer(resultFossil)
cfg = Config.getInstance()
mimetype = cfg.getFileTypeMimeType("ATOM")
self._req.content_type = """%s""" % (mimetype)
return data
示例6: _process
def _process( self ):
hook = CategoryEventHook({'from': ['today']}, 'categ', {'idlist':self._target.getId(), 'dformat': 'atom'})
res = hook(self.getAW(), self._req)
resultFossil = {'results': res[0], 'url': str(self._uh.getURL(self._target))}
serializer = Serializer.create('atom')
data = serializer(resultFossil)
cfg = Config.getInstance()
mimetype = cfg.getFileTypeMimeType( "ATOM" )
self._req.content_type = """%s"""%(mimetype)
return data
示例7: _process
def _process( self ):
filename = "%s-Session.ics"%self._session.getTitle()
hook = SessionHook({}, 'session', {'event': self._conf.getId(), 'idlist':self._session.getId(), 'dformat': 'ics'})
res = hook(self.getAW(), self._req)
resultFossil = {'results': res[0]}
serializer = Serializer.create('ics')
data = serializer(resultFossil)
self._req.headers_out["Content-Length"] = "%s"%len(data)
cfg = Config.getInstance()
mimetype = cfg.getFileTypeMimeType( "ICAL" )
self._req.content_type = """%s"""%(mimetype)
self._req.headers_out["Content-Disposition"] = """inline; filename="%s\""""%cleanHTMLHeaderFilename(filename)
return data
示例8: _process
def _process(self):
if not self._target.isScheduled():
raise NoReportError(
_("You cannot export the contribution with id {0} because it is not scheduled").format(
self._target.getId()
)
)
filename = "{0}-Contribution.ics".format(self._target.getTitle())
hook = ContributionHook(
{}, "contribution", {"event": self._conf.getId(), "idlist": self._contrib.getId(), "dformat": "ics"}
)
res = hook(self.getAW())
resultFossil = {"results": res[0]}
serializer = Serializer.create("ics")
return send_file(filename, StringIO(serializer(resultFossil)), "ICAL")
示例9: _process
def _process( self ):
if not self._target.isScheduled():
raise NoReportError(_("You cannot export the contribution with id %s because it is not scheduled")%self._target.getId())
filename = "%s-Contribution.ics"%self._target.getTitle()
hook = ContributionHook({}, 'contribution', {'event': self._conf.getId(), 'idlist':self._contrib.getId(), 'dformat': 'ics'})
res = hook(self.getAW(), self._req)
resultFossil = {'results': res[0]}
serializer = Serializer.create('ics')
data = serializer(resultFossil)
self._req.headers_out["Content-Length"] = "%s"%len(data)
cfg = Config.getInstance()
mimetype = cfg.getFileTypeMimeType( "ICAL" )
self._req.content_type = """%s"""%(mimetype)
self._req.headers_out["Content-Disposition"] = """inline; filename="%s\""""%cleanHTMLHeaderFilename(filename)
return data
示例10: schema
pass # retry
else:
break
else:
# No need to commit stuff if we didn't use an API key
# (nothing was written)
if minfo.getRoomBookingModuleActive():
Factory.getDALManager().rollback()
Factory.getDALManager().disconnect()
dbi.endRequest(False)
# Log successful POST api requests
if error is None and req.method == 'POST':
logger.info('API request: %s?%s' % (path, query))
serializer = Serializer.create(dformat, pretty=pretty, typeMap=typeMap,
**remove_lists(queryParams))
if error:
if not serializer.schemaless:
# if our serializer has a specific schema (HTML, ICAL, etc...)
# use JSON, since it is universal
serializer = Serializer.create('json')
result = fossilize(error)
else:
if serializer.encapsulate:
result = fossilize(HTTPAPIResult(result, path, query, ts, complete, extra), IHTTPAPIExportResultFossil)
del result['_fossil']
try:
data = serializer(result)
serializer.set_headers(req)
示例11: schema
pass # retry
else:
break
else:
# No need to commit stuff if we didn't use an API key
# (nothing was written)
if minfo.getRoomBookingModuleActive():
Factory.getDALManager().rollback()
Factory.getDALManager().disconnect()
dbi.endRequest(False)
# Log successful POST api requests
if error is None and request.method == 'POST':
logger.info('API request: %s?%s' % (path, query))
serializer = Serializer.create(dformat, pretty=pretty, typeMap=typeMap,
**queryParams)
if error:
if not serializer.schemaless:
# if our serializer has a specific schema (HTML, ICAL, etc...)
# use JSON, since it is universal
serializer = Serializer.create('json')
result = fossilize(error)
else:
if serializer.encapsulate:
result = fossilize(HTTPAPIResult(result, path, query, ts, complete, extra), IHTTPAPIExportResultFossil)
del result['_fossil']
try:
data = serializer(result)
serializer.set_headers(responseUtil)
示例12: 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)
示例13: 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)
示例14: isinstance
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)
示例15: get_contribution_ical_file
def get_contribution_ical_file(contrib):
data = {'results': serialize_contribution_for_ical(contrib)}
serializer = Serializer.create('ics')
return BytesIO(serializer(data))