Generate the AuthNetReceiver::Transaction model fields from the given JSON data
11459
def fields_from_json(json)
      fields = {
        :transaction_id => json['x_trans_id'],
        :invoice_num => json['x_invoice_num'],
        :subscription_id => json['x_subscription_id'],
        :subscription_paynum => json['x_subscription_paynum'],
        :transaction_type => json['x_type'],
        :card_type => json['x_card_type'],
        :account_number => json['x_account_number'],
        :description => json['x_description'],
        :response_reason_code => json['x_response_reason_code'],
        :response_reason_text => json['x_response_reason_text']
      }
      begin
        fields[:amount] = BigDecimal.new(json['x_amount'])
      rescue TypeError
        fields[:amount] = nil
      end
      return fields
    end
702281
def as_json_api(*)
      attributes.slice(self.class.primary_key, :type).tap do |h|
        relationships_for_serialization.tap do |r|
          h[:relationships] = self.class.key_formatter.format_keys(r) unless r.empty?
        end
        h[:attributes] = self.class.key_formatter.format_keys(attributes_for_serialization)
      end
    end
245012
def to_message
      @fields ||= {}
      arr = Array.new(self.class.default_fields)
      type_id + @fields.inject(arr) { |a,(k,v)| a[k-1] = v; a }.join("|")
    end
1127583
def do_processing
      json = self.json_data
      if md5_hash_is_valid?(json)
        fields = fields_from_json(json).merge({:raw_transaction_id => self.id})
        transaction = Transaction.new(fields)
        if transaction.save()
          self.update_attributes(:is_processed => true, :is_authentic => true)
          return true
        else
          return false
        end
      else
        self.update_attributes(:is_processed => true, :is_authentic => false)
        return false
      end
    end
474279
def jsondump(model, fp):
    '''
    
    '''
    fp.write('[')
    links_ser = []
    for link in model:
        links_ser.append(json.dumps(link))
    fp.write(',\n'.join(links_ser))
    fp.write(']')
1034257
def ToJson(self):
        
        jsn = super(RegisterTransaction, self).ToJson()

        asset = {
            'type': self.AssetType,
            'name': self.Name.decode('utf-8'),
            'amount': self.Amount.value,
            'precision': self.Precision if type(self.Precision) is int else self.Precision.decode('utf-8'),
            'owner': self.Owner.ToString(),
            'admin': Crypto.ToAddress(self.Admin)
        }
        jsn['asset'] = asset

        return jsn
999439
def deserialize_transactions(self, transactions=None, deserialize_only=None):
        

        if (
            not self.allow_self
            and transactions.filter(producer=socket.gethostname()).exists()
        ):
            raise TransactionDeserializerError(
                f"Not deserializing own transactions. Got "
                f"allow_self=False, hostname={socket.gethostname()}"
            )
        for transaction in transactions:
            json_text = self.aes_decrypt(cipher_text=transaction.tx)
            json_text = self.custom_parser(json_text)
            deserialized = next(self.deserialize(json_text=json_text))
            if not deserialize_only:
                if transaction.action == DELETE:
                    deserialized.object.delete()
                else:
                    self.save(obj=deserialized.object, m2m_data=deserialized.m2m_data)
                transaction.is_consumed = True
                transaction.save()
967649
def ToJson(self):
        
        json = super(AccountState, self).ToJson()
        addr = Crypto.ToAddress(self.ScriptHash)

        json['address'] = addr
        json['script_hash'] = str(self.ScriptHash)
        json['frozen'] = self.IsFrozen
        json['votes'] = [v.hex() for v in self.Votes]

        balances = []
        for key, value in self.Balances.items():
            balances.append({'asset': key.To0xString(), 'value': value.ToString()})

        json['balances'] = balances
        return json
814059
def ToJson(self):
        
        jsn = super(EnrollmentTransaction, self).ToJson()
        jsn['pubkey'] = self.PublicKey.ToString()
        return jsn
97958
def create_from_json(cls, json_data):
        
        prop = Property()
        address_info = json_data["address_info"]
        prop.address = address_info["address"]
        prop.block_id = address_info["block_id"]
        prop.zipcode = address_info["zipcode"]
        prop.zipcode_plus4 = address_info["zipcode_plus4"]
        prop.address_full = address_info["address_full"]
        prop.city = address_info["city"]
        prop.county_fips = address_info["county_fips"]
        prop.geo_precision = address_info["geo_precision"]
        prop.lat = address_info["lat"]
        prop.lng = address_info["lng"]
        prop.slug = address_info["slug"]
        prop.state = address_info["state"]
        prop.unit = address_info["unit"]

        prop.meta = None
        if "meta" in json_data:
            prop.meta = json_data["meta"]

        prop.component_results = _create_component_results(json_data, "address_info")

        return prop
327743
def json_to_model(self, model_name, j, validate=False):
        """"""
        if validate:
            self.api_spec.validate(model_name, j)
        return self.api_spec.json_to_model(model_name, j)
22868
def field_pk_from_json(self, data):
        """"""
        model = get_model(data['app'], data['model'])
        return PkOnlyModel(self, model, data['pk'])
282615
def generate_annotations_json_string(source_path, only_simple=False):
    # type: (str, bool) -> List[FunctionData]
    
    items = parse_json(source_path)
    results = []
    for item in items:
        signature = unify_type_comments(item.type_comments)
        if is_signature_simple(signature) or not only_simple:
            data = {
                'path': item.path,
                'line': item.line,
                'func_name': item.func_name,
                'signature': signature,
                'samples': item.samples
            }  # type: FunctionData
            results.append(data)
    return results
672283
def _txtinfo_to_jsoninfo(self, data):
        
        # replace INFINITE with inf, which is convertible to float
        data = data.replace('INFINITE', 'inf')
        # find interesting section
        lines = data.split('\n')

        # process links in topology section
        try:
            start = lines.index('Table: Topology') + 2
            end = lines[start:].index('') + start
        except ValueError:
            raise ParserError('Unrecognized format')
        topology_lines = lines[start:end]
        # convert topology section to jsoninfo format
        topology = []
        for line in topology_lines:
            values = line.split('\t')
            topology.append({
                'destinationIP': values[0],
                'lastHopIP': values[1],
                'linkQuality': float(values[2]),
                'neighborLinkQuality': float(values[3]),
                'tcEdgeCost': float(values[4]) * 1024.0
            })

        # process alias (MID) section
        try:
            start = lines.index('Table: MID') + 2
            end = lines[start:].index('') + start
        except ValueError:
            raise ParserError('Unrecognized format')
        mid_lines = lines[start:end]
        # convert mid section to jsoninfo format
        mid = []
        for line in mid_lines:
            values = line.split('\t')
            node = values[0]
            aliases = values[1].split(';')
            mid.append({
                'ipAddress': node,
                'aliases': [{'ipAddress': alias} for alias in aliases]
            })

        return {
            'topology': topology,
            'mid': mid
        }
1154228
def field_pk_to_json(self, model, pk):
        """"""
        app_label = model._meta.app_label
        model_name = model._meta.model_name
        return {
            'app': app_label,
            'model': model_name,
            'pk': pk,
        }
1010630
private Map<byte[], byte[]> getColumns(Object connection, String hashKey, Map<byte[], byte[]> columns)
    {
        if (resource != null && resource.isActive())
        {
            // Why transaction API returns response in byte[] format/?
            Response response = ((Transaction) connection).hgetAll(getEncodedBytes(hashKey));
            ((RedisTransaction) resource).onExecute(((Transaction) connection));
            // ((Transaction) connection).exec();
            Map<String, String> cols = (Map<String, String>) response.get();
            connection = getConnection();

            if (cols != null)
            {
                for (String name : cols.keySet())
                {
                    columns.put(getEncodedBytes(name), getEncodedBytes(cols.get(name)));
                }
            }
        }
        else
        {
            columns = ((Jedis) connection).hgetAll(getEncodedBytes(hashKey));
        }
        return columns;
    }
437877
def convert_to_json_with_mac(self, md5digest, hmacdigest):
        # type: (EncryptionMetadata, str, str) -> dict
        
        # encrypt keys
        enc_content_key = blobxfer.operations.crypto.\
            rsa_encrypt_key_base64_encoded(
                None, self._rsa_public_key, self.symmetric_key)
        enc_sign_key = blobxfer.operations.crypto.\
            rsa_encrypt_key_base64_encoded(
                None, self._rsa_public_key, self.signing_key)
        # generate json
        encjson = {
            EncryptionMetadata._JSON_KEY_ENCRYPTION_MODE:
            EncryptionMetadata._ENCRYPTION_MODE,
            EncryptionMetadata._JSON_KEY_CONTENT_IV:
            blobxfer.util.base64_encode_as_string(self.content_encryption_iv),
            EncryptionMetadata._JSON_KEY_WRAPPEDCONTENTKEY: {
                EncryptionMetadata._JSON_KEY_KEYID: 'private:pem',
                EncryptionMetadata._JSON_KEY_ENCRYPTED_KEY: enc_content_key,
                EncryptionMetadata._JSON_KEY_ENCRYPTED_AUTHKEY: enc_sign_key,
                EncryptionMetadata._JSON_KEY_ALGORITHM:
                EncryptionMetadata._ENCRYPTED_KEY_SCHEME,
            },
            EncryptionMetadata._JSON_KEY_ENCRYPTION_AGENT: {
                EncryptionMetadata._JSON_KEY_PROTOCOL:
                EncryptionMetadata._ENCRYPTION_PROTOCOL_VERSION,
                EncryptionMetadata._JSON_KEY_ENCRYPTION_ALGORITHM:
                EncryptionMetadata._ENCRYPTION_ALGORITHM,
            },
            EncryptionMetadata._JSON_KEY_INTEGRITY_AUTH: {
                EncryptionMetadata._JSON_KEY_ALGORITHM:
                EncryptionMetadata._AUTH_ALGORITHM,
            },
            EncryptionMetadata._JSON_KEY_KEY_WRAPPING_METADATA: {},
        }
        if md5digest is not None:
            encjson[EncryptionMetadata._JSON_KEY_BLOBXFER_EXTENSIONS] = {
                EncryptionMetadata._JSON_KEY_PREENCRYPTED_MD5: md5digest
            }
        if hmacdigest is not None:
            encjson[EncryptionMetadata._JSON_KEY_INTEGRITY_AUTH][
                EncryptionMetadata._JSON_KEY_MAC] = hmacdigest
        bencjson = json.dumps(
            encjson, sort_keys=True, ensure_ascii=False).encode(
                EncryptionMetadata._AUTH_ENCODING_TYPE)
        encjson = {
            EncryptionMetadata._METADATA_KEY_NAME:
            json.dumps(encjson, sort_keys=True)
        }
        # compute MAC over encjson
        hmacsha256 = hmac.new(self._signkey, digestmod=hashlib.sha256)
        hmacsha256.update(bencjson)
        authjson = {
            EncryptionMetadata._JSON_KEY_AUTH_METAAUTH: {
                EncryptionMetadata._JSON_KEY_ALGORITHM:
                EncryptionMetadata._AUTH_ALGORITHM,
                EncryptionMetadata._JSON_KEY_AUTH_ENCODING:
                EncryptionMetadata._AUTH_ENCODING_TYPE,
                EncryptionMetadata._JSON_KEY_MAC:
                blobxfer.util.base64_encode_as_string(hmacsha256.digest()),
            }
        }
        encjson[EncryptionMetadata._METADATA_KEY_AUTH_NAME] = json.dumps(
            authjson, sort_keys=True)
        return encjson