dummy_encoder.py 文件源码

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

项目:roulier 作者: akretion 项目源码 文件源码
def encode(self, api_input, action):
        """Transform input to dummy zpl."""
        if not (action in DUMMY_ACTIONS):
            raise Exception(
                'action %s not in %s' % (action, ', '.join(DUMMY_ACTIONS)))

        api = DummyApi()
        if not api.validate(api_input):
            raise InvalidApiInput(
                'Input error : %s' % api.errors(api_input))
        data = api.normalize(api_input)

        data['to_address']['dept'] = data['to_address']['zip'][0:2]

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

        template = env.get_template("dummy_%s.zpl" % action)
        return template.render(
            auth=data['auth'],
            service=data['service'],
            parcel=data['parcel'],
            sender_address=data['from_address'],
            receiver_address=data['to_address'])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号