Commit 85c5bf46 by Luo

init.

parents
__pycache__
dist
build
*.egg-info*
*.pyc
*.aux
*.log
*.pdf
*.synctex.gz
UC-Results
*.project
*.pydevproject
MIT License
Copyright (c) 2016 MASS Project
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# Common Helper Encoder
Json encoding helpers.
\ No newline at end of file
from .json_encoder import ReportEncoder
__all__ = [
'ReportEncoder',
]
import json
import datetime
from base64 import standard_b64encode
class ReportEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime.datetime):
return obj.isoformat()
elif isinstance(obj, bytes):
return standard_b64encode(obj).decode('utf-8')
return json.JSONEncoder.default(self, obj)
import unittest
from common_helper_encoder.json_encoder import ReportEncoder
import datetime
class Test_json_encoder(unittest.TestCase):
def setUp(self):
self.encoder = ReportEncoder()
def test_byte_encoding(self):
input_data = b'TEST'
result = self.encoder.default(input_data)
self.assertEqual(result, "VEVTVA==", "base64 encoding not correct")
def test_datetime_encoding(self):
input_data = datetime.datetime(1970, 4, 23, 19, 0, 24)
result = self.encoder.default(input_data)
self.assertEqual(result, "1970-04-23T19:00:24")
if __name__ == "__main__":
unittest.main()
from setuptools import setup, find_packages
VERSION = "0.2.1"
setup(
name="common_helper_encoder",
version=VERSION,
packages=find_packages(),
description="Json Encoder",
license="MIT License"
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment