data.py 文件源码

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

项目:farnsworth 作者: mechaphish 项目源码 文件源码
def to_xml(self):
        if self.format is not None:
            tag = Element('data', attrib={'format': self.format})
        else:
            tag = Element('data')

        if self.format == 'hex':
            tag.text = self.data.encode('hex')
        else:   # asciic case
            encoded = ''
            for c in self.data:
                if c in _PRINTABLE:
                    encoded += c
                elif c in ('\n', '\r', '\t'):
                    encoded += {
                        '\n': '\\n',
                        '\r': '\\r',
                        '\t': '\\t',
                    }[c]
                else:
                    encoded += '\\x{:02x}'.format(ord(c))
            tag.text = encoded
        return tag
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号