示例#1
0
    def __init__(self, reg=None):
        self.reg = reg
        self.d = []

        self.load(self.reg)

        self.ret = defDict()
示例#2
0
    def __init__(self, init=None, *args, **kwargs):
        """
            Initialization of the NIST Object.
            
            :param init: Initialization data. Can be a NIST object, a file link, or a raw string.
            :type init: NIST or str
            
            All biometric information are stored in the self.data recursive
            default dictionary object. The information is stored as following:
            
                self.data[ ntype ][ idc ][ tagid ]
            
            To get and set data, use the :func:`~NIST.traditional.NIST.get_field`
            and :func:`~NIST.traditional.NIST.set_field()` functions.
        """
        debug.info("Initialization of the NIST object")

        self.stdver = ""

        self.fileuri = None
        self.filename = None
        self.data = defDict()

        self.date = datetime.datetime.now().strftime("%Y%m%d")
        self.timestamp = int(time.time())

        if init != None:
            self.load_auto(init)
示例#3
0
    def to_json(self, return_bin=True, **options):
        """
            Export the content of the NIST object to JSON.
            
            :param return_bin: Include binary data in the JSON string. 
            :type return_bin: boolean
            
            :param options: Options to pass to the :func:`json.dumps()` function.
            :type options: kwargs
            
            :return: JSON string.
            :rtype: str
            
            .. note:: If the binary data is included in the JSON string, the data will be exported as hexadecimal representation.
            
        """
        self.clean()
        databis = defDict()
        for ntype, idc, tagid in self.get_all_tagid():
            value = self.get_field((ntype, tagid), idc)

            if self.is_binary(ntype, tagid):
                if return_bin:
                    databis[ntype][idc][tagid] = join(
                        multimap([ord, myhex], value))

            else:
                databis[ntype][idc][tagid] = value

        databis = databis.to_dict()

        return json.dumps(databis, **options)
示例#4
0
    def from_json(self, data):
        """
            Load the data from a JSON file. If some binary filds are present in
            the JSON file, the data will be converted from hexadecimal format to
            binary.
            
            :param data: JSON file or JSON string to import.
            :type data: str
            
            :return: NIST object.
            :rtype: NIST object
            
            Usage:
            
                >>> from NIST import NIST
                >>> n = NIST()
                >>> n.from_json( "sample/mark-pairing-nobinary.json" )
                >>> n
                NIST object, Type-01, Type-02, Type-09, Type-13
        """
        if isinstance(data, str) and os.path.isfile(data):
            with open(data) as fp:
                data = json.load(fp)

        elif isinstance(data, str):
            data = json.loads(data)

        self.data = defDict()

        for ntype, idcs in data.iteritems():
            ntype = int(ntype)
            self.add_ntype(ntype)

            for idc, tagids in idcs.iteritems():
                idc = int(idc)
                self.add_idc(ntype, idc)

                for tagid, value in tagids.iteritems():
                    tagid = int(tagid)

                    if self.is_binary(ntype, tagid):
                        value = join(
                            multimap([hex_to_int, chr], split(value, 2)))

                    self.set_field((ntype, tagid), value, idc)