Internal function: serialize native types.
16321
def _serialize_item(item):
    """"""
    # Recursively serialize lists, tuples, and dicts.
    if isinstance(item, (list, tuple)):
        return [_serialize_item(subitem) for subitem in item]
    elif isinstance(item, dict):
        return dict([(key, _serialize_item(value))
                     for (key, value) in iteritems(item)])

    # Serialize strings.
    elif isinstance(item, string_types):
        # Replace glSomething by something (needed for WebGL commands).
        if item.startswith('gl'):
            return re.sub(r'^gl([A-Z])', lambda m: m.group(1).lower(), item)
        else:
            return item

    # Process NumPy arrays that are not buffers (typically, uniform values).
    elif isinstance(item, np.ndarray):
        return _serialize_item(item.ravel().tolist())

    # Serialize numbers.
    else:
        try:
            return np.asscalar(item)
        except Exception:
            return item
269048
def _serialize_lnk(lnk):
    """"""
    s = ""
    if lnk is not None:
        s = '<'
        if lnk.type == Lnk.CHARSPAN:
            cfrom, cto = lnk.data
            s += ''.join([str(cfrom), ':', str(cto)])
        elif lnk.type == Lnk.CHARTSPAN:
            cfrom, cto = lnk.data
            s += ''.join([str(cfrom), '#', str(cto)])
        elif lnk.type == Lnk.TOKENS:
            s += ' '.join([str(t) for t in lnk.data])
        elif lnk.type == Lnk.EDGE:
            s += ''.join(['@', str(lnk.data)])
        s += '>'
    return s
49613
def as_base_types(self):
    """"""
    if not self._cached:
      # Create the single cache file the first time this is called.
      self._cached = {
          'name': self.name,
          'outcome': self.outcome.name,
      }
      if self.validators:
        self._cached['validators'] = data.convert_to_base_types(
            tuple(str(v) for v in self.validators))
      if self.dimensions:
        self._cached['dimensions'] = data.convert_to_base_types(self.dimensions)
      if self.units:
        self._cached['units'] = data.convert_to_base_types(self.units)
      if self.docstring:
        self._cached['docstring'] = self.docstring
    if self.measured_value.is_value_set:
      self._cached['measured_value'] = self.measured_value.basetype_value()
    return self._cached
809699
def _serialize_buffer(buffer, array_serialization=None):
    """"""
    if array_serialization == 'binary':
        # WARNING: in NumPy 1.9, tostring() has been renamed to tobytes()
        # but tostring() is still here for now for backward compatibility.
        return buffer.ravel().tostring()
    elif array_serialization == 'base64':
        return {'storage_type': 'base64',
                'buffer': base64.b64encode(buffer).decode('ascii')
                }
    raise ValueError("The array serialization method should be 'binary' or "
                     "'base64'.")
517322
function __serializeData(type, data, options=DEFAULT_OPTIONS) {
	let buffers = [];
	if (type === DATA_TYPE.NULL) {
		buffers = __serializeNull();
	}
	else if (type === DATA_TYPE.FALSE || type === DATA_TYPE.TRUE) {
		buffers = __serializeBoolean();
	}
	else if (type === DATA_TYPE.UINT8) {
		buffers = [data._ab];
	}
	else if (type === DATA_TYPE.UINT16) {
		buffers = [data._ab];
	}
	else if (type === DATA_TYPE.UINT32) {
		buffers = [data._ab];
	}
	else if (type === DATA_TYPE.INT8) {
		buffers = [data._ab];
	}
	else if (type === DATA_TYPE.INT16) {
		buffers = [data._ab];
	}
	else if (type === DATA_TYPE.INT32) {
		buffers = [data._ab];
	}
	else if (type === DATA_TYPE.INT64) {
		buffers = __serializeInt64(data);
	}
	else if (type === DATA_TYPE.INT128) {
		buffers = __serializeInt128(data);
	}
	else if (type === DATA_TYPE.INT256) {
		buffers = __serializeInt256(data);
	}
	else if (type === DATA_TYPE.INT512) {
		buffers = __serializeInt512(data);
	}
	else if (type === DATA_TYPE.INTVAR) {
		buffers = __serializeIntVar(data);
	}
	else if (type === DATA_TYPE.UINT64) {
		buffers = __serializeUInt64(data);
	}
	else if (type === DATA_TYPE.UINT128) {
		buffers = __serializeUInt128(data);
	}
	else if (type === DATA_TYPE.UINT256) {
		buffers = __serializeUInt256(data);
	}
	else if (type === DATA_TYPE.UINT512) {
		buffers = __serializeUInt512(data);
	}
	else if (type === DATA_TYPE.UINTVAR) {
		buffers = __serializeUIntVar(data);
	}
	else if (type === DATA_TYPE.FLOAT64) {
		buffers = __serializeDouble(data);
	}
	else if (type === DATA_TYPE.STRING) {
		buffers = __serializeString(data);
	}
	else if (type === DATA_TYPE.ARRAY) {
		buffers = __serializeArray(data, options);
	}
	else if (type === DATA_TYPE.ARRAY_START) {
		buffers = __serializeArrayStreaming(data, options);
	}
	else if (type === DATA_TYPE.OBJECT) {
		buffers = __serializeObject(data, options);
	}
	else if (type === DATA_TYPE.OBJECT_START) {
		buffers = __serializeObjectStreaming(data, options);
	}
	else if (type === DATA_TYPE.DATE) {
		buffers = __serializeDate(data);
	}
	else if (type === DATA_TYPE.OBJECTID) {
		buffers = __serializeObjectId(data);
	}
	else if (type === DATA_TYPE.BINARY) {
		buffers = __serializeArrayBuffer(data.toBytes());
	}
	else if (type === DATA_TYPE.ARRAY_BUFFER) {
		buffers = __serializeArrayBuffer(data);
	}
	else if (type === DATA_TYPE.DATA_VIEW) {
		buffers = __serializeArrayBuffer(data.buffer);
	}
	else if (type === DATA_TYPE.UINT8_ARRAY) {
		buffers = __serializeArrayBuffer(data.buffer);
	}
	else if (type === DATA_TYPE.INT8_ARRAY) {
		buffers = __serializeArrayBuffer(data.buffer);
	}
	else if (type === DATA_TYPE.UINT16_ARRAY) {
		buffers = __serializeArrayBuffer(data.buffer);
	}
	else if (type === DATA_TYPE.INT16_ARRAY) {
		buffers = __serializeArrayBuffer(data.buffer);
	}
	else if (type === DATA_TYPE.UINT32_ARRAY) {
		buffers = __serializeArrayBuffer(data.buffer);
	}
	else if (type === DATA_TYPE.INT32_ARRAY) {
		buffers = __serializeArrayBuffer(data.buffer);
	}
	else if (type === DATA_TYPE.FLOAT32_ARRAY) {
		buffers = __serializeArrayBuffer(data.buffer);
	}
	else if (type === DATA_TYPE.FLOAT64_ARRAY) {
		buffers = __serializeArrayBuffer(data.buffer);
	}
	else if (HAS_NODE_BUFFER && type === DATA_TYPE.SPECIAL_BUFFER) {
		let buff = Buffer.alloc(data.length);
		data.copy(buff, 0);
		buffers = __serializeArrayBuffer(buff.buffer);
	}
	
	return buffers;
}
1075893
def serialize(self, value, **kwargs):
        """"""
        kwargs.update({'include_class': kwargs.get('include_class', True)})
        if self.serializer is not None:
            return self.serializer(value, **kwargs)
        if value is None:
            return None
        serial_list = [self.prop.serialize(val, **kwargs)
                       for val in value]
        return serial_list
390920
def serialize(self, obj):
        """"""
        if hasattr(obj, '_jsid'):
            return {'immutable': False, 'value': obj._jsid}
        else:
            obj_json = {'immutable': True}
            try:
                json.dumps(obj)
                obj_json['value'] = obj
            except:
                pass
            if callable(obj):
                guid = str(uuid.uuid4())
                callback_registry[guid] = obj
                obj_json['callback'] = guid
            return obj_json
195800
def to_native(self, obj, name, value):
		""""""
		
		if isinstance(value, self.List):
			return value
		
		result = self.List(super(Array, self).to_native(obj, name, i) for i in value)
		obj.__data__[self.__name__] = result
		
		return result
606455
def default(self, obj):
        """"""
        if hasattr(obj, '__dict__'):
            return obj.__dict__.copy()
        elif HAS_NUMPY and isinstance(obj, np.ndarray):
            return obj.copy().tolist()
        else:
            raise TypeError(("Object of type {:s} with value of {:s} is not "
                             "JSON serializable").format(type(obj), repr(obj)))
1225565
function serialize(type, source, options) {
  var codec = type.codec
  if (!codec)
    return postEncode(new Buffer([ type.byte ]), options)

  var buffer = codec.encode(source, bytewise)

  if (options && options.nested && codec.escape)
    buffer = codec.escape(buffer)

  var hint = typeof codec.length === 'number' ? (codec.length + 1) : void 0 
  var buffers = [ new Buffer([ type.byte ]), buffer ]
  return postEncode(Buffer.concat(buffers, hint), options)
}
956002
def serialize(self):
        
        return {"hstart": self.hstart, "mstart": self.mstart,
                "hend": self.hend, "mend": self.mend,
                "is_valid": self.is_valid}
217740
def serialize(self):
        """"""
        if type(self.value) == int:
            return "i{:X}s".format(self.value).encode('ascii')

        if type(self.value) == str:
            value = self.value.encode('utf-8')
            return "{:X}:".format(len(value)).encode('ascii') + value

        if type(self.value) == bytes:
            value = base64.standard_b64encode(self.value)
            return "u{:X}:".format(len(value)).encode('ascii') + value

        if type(self.value) == list:
            items = [LiveMessageToken(m).serialize() for m in self.value]
            return b'l' + b''.join(items) + b's'

        if type(self.value) == dict:
            items = []
            for key, value in self.value.items():
                items.append(LiveMessageToken(str(key)).serialize())
                items.append(LiveMessageToken(value).serialize())
            return b'h' + b''.join(items) + b's'

        raise RuntimeError("Unknown type %s" % type(self.value))
750757
def build_native_type_dictionary(fields, respect_required=False, wrap_field=True, name=''):
    
    # a place to start when building the input field attributes
    input_fields = {}
    # go over every input in the summary
    for field in fields:
        field_name = name + field['name']
        field_type = field['type']

        # if the type field is a string
        if isinstance(field_type, str):
            # compute the native api type for the field
            field_type = convert_typestring_to_api_native(field_type)(
                # required=respect_required and field['required']
            )
            # add an entry in the attributes
            input_fields[field['name']] = field_type

        # we could also be looking at a dictionary
        elif isinstance(field_type, dict):

            object_fields = field_type['fields']

            # add the dictionary to the parent as a graphql object type
            input_fields[field['name']] = graphql_type_from_summary(
                summary={
                    'name': field_name+"ArgType",
                    'fields': object_fields
                }
            )

            # if we are supposed to wrap the object in a field
            if wrap_field:
                # then wrap the value we just added
                input_fields[field['name']] = graphene.Field(input_fields[field['name']])


    # we're done
    return input_fields
1226274
def serialize(self):
        """"""
        data = {'doc': self.doc}
        if isinstance(self.query, Query):
            data['query'] = self.query.serialize()
        return data
1130699
def serialize_dtype(o):
    
    if len(o) == 0:
        return dict(
            _type='np.dtype',
            descr=str(o))
    return dict(
        _type='np.dtype',
        descr=o.descr)
419074
def serialize(self, raw=False):
        '''
        '''
        if raw:
            return self._key.encode()
        return self._key.encode(nacl.encoding.Base64Encoder)
921964
def serialize(self, serializable: Optional[Union[SerializableType, List[SerializableType]]]) \
            -> PrimitiveJsonType:
        
        if serializable is None:
            # Implements #17
            return None
        elif isinstance(serializable, List):
            return [self.serialize(item) for item in serializable]
        else:
            serialized = self._create_serialized_container()

            for mapping in self._property_mappings:
                if mapping.object_property_getter is not None and mapping.serialized_property_setter is not None:
                    value = mapping.object_property_getter(serializable)
                    if not (mapping.optional and value is None):
                        if isinstance(value, type(mapping.collection_factory([]))):
                            value = list(mapping.collection_iter(value))
                        encoded_value = self._serialize_property_value(value, mapping.serializer_cls)
                        mapping.serialized_property_setter(serialized, encoded_value)

            return serialized