def test_json_load(self):
     outfile = StringIO()
     json_serialization.JSONSerializer().serialize(self.acc, outfile)
     outfile.seek(0)
     content = json_serialization.JSONSerializer().deserialize(outfile)
     self.assertEqual(str(content), "  comment       date  value\n" + \
                      "0    test 2017-04-04    123\n" + \
                      "1   test1 2017-04-04    321")
Esempio n. 2
0
def main(raw_args=None):
    args = arg_parser.parse_args(raw_args)
    
    json = json_serialization.JSONSerializer(json_types,
        transparent=args.transparent,
        indent=4 if args.pretty else None,
        separators=(",\n", ": ") if args.pretty else None)
    
    if args.command == "gen-key":
        out = open_filename(args.key, "w")
        
        open_filename(args.key, "w")
        json.dump(crypto.RSAKey(), out)
    
    elif args.command == "pub-key":
        in_ = open_filename(args.key, "r")
        out = open_filename(args.public_key, "w")
        
        json.dump(json.load(in_, crypto.RSAKey).public, out)
    
    elif args.command == "sign":
        key_file = open_filename(args.key, "r")
        in_ = open_filename(args.raw_data, "rb")
        out = open_filename(args.signed_data, "w")
        
        key = json.load(key_file, crypto.RSAKey)
        signed = key.wrap_signature(in_.read())
        
        json.dump(signed, out)
    
    else:
        raise NotImplementedError()
 def test_json_save(self):
     outfile = StringIO()
     json_serialization.JSONSerializer().serialize(self.acc, outfile)
     outfile.seek(0)
     content = outfile.read()
     self.assertEqual(content, "[{\"comment\": \"test\", \"date\": \"2017-04-04 00:00:00\", \"value\": 123}, {"
                               "\"comment\": \"test1\", \"date\": \"2017-04-04 00:00:00\", \"value\": 321}]")
Esempio n. 4
0
 def __init__(self,
              acc=pd.DataFrame(),
              data_file='accounter',
              config_file='configuration.ini'):
     """Create new Accounter object from existing DataFrame.
     >>> print(Accounter())
     List of notes is empty
     >>> print(Accounter(pd.DataFrame([{'date': pd.Timestamp("20170404"),
     ... 'value': 100, 'comment': 'new money'}])))
          comment       date  value
     0  new money 2017-04-04    100
     """
     self.account = acc
     self.data_file = data_file
     self.config_file = config_file
     self.json_serializer = json_s.JSONSerializer()
     self.pickle_serializer = pick_s.PickleSerializer()
     self.yaml_serializer = yaml_s.YAMLSerializer()
Esempio n. 5
0
#!/usr/bin/env python2.7
from __future__ import division, print_function, unicode_literals

import unittest
import sys

sys.path[0:0] = [".."]

import binary
import json_serialization

json = json_serialization.JSONSerializer()


class ByteArrayTests(unittest.TestCase):
    """Basic, non-comprehensive tests for binary.ByteArray."""
    def test_integer_conversion_sanity(self):
        self.assertEquals(binary.ByteArray.from_int(0).to_int(), 0)

        for power in range(0, 128, 4):
            n = 2**power
            b = binary.ByteArray.from_int(n)
            np = b.to_int()

            self.assertEquals(n, np)

    def test_to_integer(self):
        self.assertEquals(
            binary.ByteArray([3, 2, 1]).to_int(),
            1 * 2**16 + 2 * 2**8 + 3 * 2**0)
Esempio n. 6
0
from __future__ import division, print_function, unicode_literals

import unittest
import sys

sys.path[0:0] = [".."]

import asciiarmor
import crypto
import binary

import json_serialization

json = json_serialization.JSONSerializer({
    "rsa-key": crypto.RSAKey,
    "binary": binary.ByteArray,
    "signed-binary": crypto.SignedBinary
})

# TODO: Generate some real example cases using OpenSSL directly.

cases = [{
    "data": b"",
    "signature": b"",
    "key_binary": b"",
    "key_pem": "",
    "pub_key_binary": b"",
    "pub_key_pem": b""
}]