当前位置: 首页>>代码示例>>Python>>正文


Python Serializer.register方法代码示例

本文整理汇总了Python中indico.web.http_api.metadata.serializer.Serializer.register方法的典型用法代码示例。如果您正苦于以下问题:Python Serializer.register方法的具体用法?Python Serializer.register怎么用?Python Serializer.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在indico.web.http_api.metadata.serializer.Serializer的用法示例。


在下文中一共展示了Serializer.register方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: isinstance

# 需要导入模块: from indico.web.http_api.metadata.serializer import Serializer [as 别名]
# 或者: from indico.web.http_api.metadata.serializer.Serializer import register [as 别名]
                            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)
开发者ID:DirkHoffmann,项目名称:indico,代码行数:32,代码来源:xml.py

示例2: _matchPath

# 需要导入模块: from indico.web.http_api.metadata.serializer import Serializer [as 别名]
# 或者: from indico.web.http_api.metadata.serializer.Serializer import register [as 别名]
        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)
开发者ID:VishrutMehta,项目名称:indico,代码行数:32,代码来源:file.py

示例3: JSONSerializer

# 需要导入模块: from indico.web.http_api.metadata.serializer import Serializer [as 别名]
# 或者: from indico.web.http_api.metadata.serializer.Serializer import register [as 别名]
## 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)
开发者ID:pferreir,项目名称:indico-backup,代码行数:32,代码来源:json.py

示例4: JSONSerializer

# 需要导入模块: from indico.web.http_api.metadata.serializer import Serializer [as 别名]
# 或者: from indico.web.http_api.metadata.serializer.Serializer import register [as 别名]
# 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)
开发者ID:OmeGak,项目名称:indico,代码行数:32,代码来源:json.py

示例5: isinstance

# 需要导入模块: from indico.web.http_api.metadata.serializer import Serializer [as 别名]
# 或者: from indico.web.http_api.metadata.serializer.Serializer import register [as 别名]
                            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)
开发者ID:pferreir,项目名称:indico-backup,代码行数:32,代码来源:xml.py


注:本文中的indico.web.http_api.metadata.serializer.Serializer.register方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。