laposte_encoder.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:roulier 作者: akretion 项目源码 文件源码
def encode(self, api_input, action):
        """Transform input to laposte compatible xml."""
        if not (action in LAPOSTE_ACTIONS):
            raise InvalidApiInput(
                'action %s not in %s' % (action, ', '.join(LAPOSTE_ACTIONS)))

        api = LaposteApi()
        if not api.validate(api_input):
            _logger.warning('Laposte api call exception:')
            raise InvalidApiInput(
                {'api_call_exception': api.errors(api_input)})
        data = api.normalize(api_input)

        data['service']['labelFormat'] = self.lookup_label_format(
            data['service']['labelFormat'])

        env = Environment(
            loader=PackageLoader('roulier', '/carriers/laposte/templates'),
            extensions=['jinja2.ext.with_', 'jinja2.ext.autoescape'],
            autoescape=True)

        template = env.get_template("laposte_%s.xml" % action)
        return {
            "body": template.render(
                service=data['service'],
                parcel=data['parcels'][0],
                auth=data['auth'],
                sender_address=data['from_address'],
                receiver_address=data['to_address'],
                customs=data['customs']),
            "headers": data['auth'],
            "output_format": data['service']['labelFormat']
        }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号