Encode a list for the DynamoDB format
438766
def encode_list(dynamizer, value):
    
    encoded_list = []
    dict(map(dynamizer.raw_encode, value))
    for v in value:
        encoded_type, encoded_value = dynamizer.raw_encode(v)
        encoded_list.append({
            encoded_type: encoded_value,
        })
    return 'L', encoded_list
900098
def encode_collection(collection):
    """"""
    tree = etree.Element('collection')
    etree.SubElement(tree, 'source').text = collection.source
    etree.SubElement(tree, 'date').text = collection.date
    etree.SubElement(tree, 'key').text = collection.key
    encode_infons(tree, collection.infons)
    for doc in collection.documents:
        tree.append(encode_document(doc))
    return tree
1111661
def encode(self):
        

        blob = bytearray()

        for record in self.records:
            blob += record.encode()

        header = struct.pack("<LL", self.SCRIPT_MAGIC, len(blob) + self.SCRIPT_HEADER_LENGTH)
        blob = header + blob

        sha = hashlib.sha256()
        sha.update(blob)
        hash_value = sha.digest()[:16]

        return bytearray(hash_value) + blob
302127
def dump_key(engine, obj):
    
    key = {}
    for key_column in obj.Meta.keys:
        key_value = getattr(obj, key_column.name, missing)
        if key_value is missing:
            raise MissingKey("{!r} is missing {}: {!r}".format(
                obj, "hash_key" if key_column.hash_key else "range_key",
                key_column.name
            ))
        # noinspection PyProtectedMember
        key_value = engine._dump(key_column.typedef, key_value)
        key[key_column.dynamo_name] = key_value
    return key
635680
def save_list(key, *values):
    
    return json.dumps({key: [_get_json(value) for value in values]})
20251
def as_list(self, decode=False):
        
        items = self.database.lrange(self.key, 0, -1)
        return [_decode(item) for item in items] if decode else items
1003194
def maybe_encode_keys(self, keys):
        
        ret = {}
        for k, v in six.iteritems(keys):
            if is_dynamo_value(v):
                return keys
            elif not is_null(v):
                ret[k] = self.encode(v)
        return ret
276466
def encode_simple(d):
    """"""
    if isinstance(d, unicode):
        return d.encode()
    if isinstance(d, list):
        return list(map(encode_simple, d))
    if isinstance(d, dict):
        return dict([(encode_simple(k), encode_simple(v)) for k, v in d.items()])
    return d
614978
def batch_encode(self, iterator, *args, **kwargs):
        
        return [self.encode(object_, *args, **kwargs) for object_ in iterator]
1012671
def to_list_str(value, encode=None):
    
    result = []
    for index, v in enumerate(value):
        if isinstance(v, dict):
            result.append(to_dict_str(v, encode))
            continue

        if isinstance(v, list):
            result.append(to_list_str(v, encode))
            continue

        if encode:
            result.append(encode(v))
        else:
            result.append(default_encode(v))

    return result
11142
def reformat_record(record):
    """"""
    return {
        "key": record["dynamodb"].get("Keys", None),
        "new": record["dynamodb"].get("NewImage", None),
        "old": record["dynamodb"].get("OldImage", None),

        "meta": {
            "created_at": record["dynamodb"]["ApproximateCreationDateTime"],
            "event": {
                "id": record["eventID"],
                "type": record["eventName"].lower(),
                "version": record["eventVersion"]
            },
            "sequence_number": record["dynamodb"]["SequenceNumber"],
        }
    }
425287
def encode_to_json(order_list):
    
    rowsets = []
    for items_in_region_list in order_list._orders.values():
        region_id = items_in_region_list.region_id
        type_id = items_in_region_list.type_id
        generated_at = gen_iso_datetime_str(items_in_region_list.generated_at)

        rows = []
        for order in items_in_region_list.orders:
            issue_date = gen_iso_datetime_str(order.order_issue_date)

            # The order in which these values are added is crucial. It must
            # match STANDARD_ENCODED_COLUMNS.
            rows.append([
                order.price,
                order.volume_remaining,
                order.order_range,
                order.order_id,
                order.volume_entered,
                order.minimum_volume,
                order.is_bid,
                issue_date,
                order.order_duration,
                order.station_id,
                order.solar_system_id,
            ])

        rowsets.append(dict(
            generatedAt = generated_at,
            regionID = region_id,
            typeID = type_id,
            rows = rows,
        ))

    json_dict = {
        'resultType': 'orders',
        'version': '0.1',
        'uploadKeys': order_list.upload_keys,
        'generator': order_list.order_generator,
        'currentTime': gen_iso_datetime_str(now_dtime_in_utc()),
        # This must match the order of the values in the row assembling portion
        # above this.
        'columns': STANDARD_ENCODED_COLUMNS,
        'rowsets': rowsets,
    }

    return json.dumps(json_dict)
1033690
private List<Integer> encodeInfoKeys(Collection<String> keys) {
        // sorted key list
        List<Integer> idxKeys = new ArrayList<>(keys.size());
        for (String key : keys) {
            if (!IGNORED_ATTRIBUTE_KEYS.contains(key) && (includeAllFormats || attributeFields.contains(key))) {
                Integer idx = infoKeyIndexMap.get(key);
                if (idx != null) {
                    idxKeys.add(idx);
                } else {
                    throw new IllegalArgumentException("Unknown key value " + key);
                }
            }
        }
        idxKeys.sort(Integer::compareTo);
        return idxKeys;
    }
1269162
def _encode_list(self, obj):# do
        """"""

        self._increment_nested_level()

        buffer = []
        for element in obj:
            buffer.append(self._encode(element))

        self._decrement_nested_level()

        return '['+ ','.join(buffer) + ']'
951396
function encodeParams(params) {
    var queryString;
    if (params && Object.keys(params)) {
        queryString = [].slice.call(arguments).reduce(function (a, b) {
            return a.concat(b instanceof Array ? b : [b]);
        }, []).filter(function (c) {
            return "object" === typeof c;
        }).reduce(function (p, c) {
            !(c instanceof Array) ? p = p.concat(Object.keys(c).map(function (key) {
                return [key, c[key]];
            })) : p.push(c);
            return p;
        }, []).reduce(function (p, c) {
            c.length === 2 ? p.push(c) : p = p.concat(c);
            return p;
        }, []).reduce(function (p, c) {
            c[1] instanceof Array ? c[1].forEach(function (v) {
                p.push([c[0], v]);
            }) : p.push(c);
            return p;
        }, []).map(function (c) {
            c[1] = encodeURIComponent(c[1]);
            return c.join("=");
        }).join("&");
    }
    return queryString;
}
210112
def _encode_write(dynamizer, data, action, key):
    
    # Strip null values out of data
    data = dict(((k, dynamizer.encode(v)) for k, v in six.iteritems(data) if
                 not is_null(v)))
    return {
        action: {
            key: data,
        }
    }
214538
def _format_list(self, data):
        
        dataset = "["
        i = 0
        for el in data:
            if pd.isnull(el):
                dataset += "null"
            else:
                dtype = type(data[i])
                if dtype == int or dtype == float:
                    dataset += str(el)
                else:
                    dataset += '"' + el + '"'
            if i < len(data) - 1:
                dataset += ', '
        dataset += "]"
        return dataset