Serialize the context as a dictionnary from a given request.
195040
def as_dict(self):
        '''
        
        '''
        data = {}
        if settings.JS_CONTEXT_ENABLED:
            for context in RequestContext(self.request):
                for key, value in six.iteritems(context):
                    if settings.JS_CONTEXT and key not in settings.JS_CONTEXT:
                        continue
                    if settings.JS_CONTEXT_EXCLUDE and key in settings.JS_CONTEXT_EXCLUDE:
                        continue
                    handler_name = 'process_%s' % key
                    if hasattr(self, handler_name):
                        handler = getattr(self, handler_name)
                        data[key] = handler(value, data)
                    elif isinstance(value, SERIALIZABLE_TYPES):
                        data[key] = value
        if settings.JS_USER_ENABLED:
            self.handle_user(data)
        return data
1336205
function serialiseRequest (request, toObject) {
  if (!(request instanceof Request)) {
    throw new Error('Expecting request to be instance of Request')
  }

  var headers = []
  var headerNames = request.headers.keys()
  for (var i = 0; i < headerNames.length; i++) {
    var headerName = headerNames[i]
    headers[headerName] = request.headers.get(headerName)
  }

  var serialised = {
    method: request.method,
    url: request.url,
    headers: headers,
    context: request.context,
    referrer: request.referrer,
    mode: request.mode,
    credentials: request.credentials,
    redirect: request.redirect,
    integrity: request.integrity,
    cache: request.cache,
    bodyUsed: request.bodyUsed
  }

  return request
    .blob()
    .then(blobUtil.blobToBase64String)
    .then(function (base64) {
      serialised.__body = base64
      return toObject
        ? serialised
        : JSON.stringify(serialised)
    })
}
732756
def raw(request):
    """"""
    foos = foobar_models.Foo.objects.all()
    return HttpResponse(tree.xml(foos), mimetype='text/xml')
430404
def serialize(self, resources):
        """"""
        serialized = {
            'meta': {
                'sqlalchemy_jsonapi_version': '4.0.9'
            },
            'jsonapi': {
                'version': '1.0'
            }
        }
        # Determine multiple resources by checking for SQLAlchemy query count.
        if hasattr(resources, 'count'):
            serialized['data'] = []
            for resource in resources:
                serialized['data'].append(
                    self._render_resource(resource))
        else:
            serialized['data'] = self._render_resource(resources)

        return serialized
1091001
def get(context, request, key=None):
    
    registry_records = api.get_registry_records_by_keyword(key)

    # Prepare batch
    size = req.get_batch_size()
    start = req.get_batch_start()
    batch = api.make_batch(registry_records, size, start)

    return {
        "pagesize": batch.get_pagesize(),
        "next": batch.make_next_url(),
        "previous": batch.make_prev_url(),
        "page": batch.get_pagenumber(),
        "pages": batch.get_numpages(),
        "count": batch.get_sequence_length(),
        "items": [registry_records],
        "url": api.url_for("senaite.jsonapi.v1.registry", key=key),
    }
253615
def serialized(func):
    """"""

    @wraps(func)
    def wrapper(*args, **kwargs):
        return '\n'.join(
            ' '.join(parts) if isinstance(parts, tuple) else parts
            for parts in func(*args, **kwargs)
        )

    return wrapper
1253897
def serialize(self, entity, request=None):
        

        def should_we_insert(value, field_spec):
            return value not in self.missing or field_spec.required

        errors = {}
        ret = {}

        for field_name, field_spec in self.spec.fields.items():
            value = self._get_value_for_serialization(entity, field_name, field_spec)
            func = self._get_serialize_func(field_name, self.spec)
            try:
                # perform serialization
                value = func(value, entity, request)
                if should_we_insert(value, field_spec):
                    ret[field_name] = value
            except ValidationError, e:
                if hasattr(e, 'message_dict'):
                    # prefix error keys with top level field name
                    errors.update(dict(zip(
                        [field_name + '.' + key for key in e.message_dict.keys()],
                        e.message_dict.values())))
                else:
                    errors[field_name] = e.messages

        if errors:
            raise ValidationError(errors)

        return None if ret == {} else ret
181635
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'global' in _dict:
            args['global_'] = MessageContextGlobal._from_dict(
                _dict.get('global'))
        if 'skills' in _dict:
            args['skills'] = MessageContextSkills._from_dict(
                _dict.get('skills'))
        return cls(**args)
597432
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'environment_id' in _dict:
            args['environment_id'] = _dict.get('environment_id')
        if 'name' in _dict:
            args['name'] = _dict.get('name')
        if 'description' in _dict:
            args['description'] = _dict.get('description')
        if 'created' in _dict:
            args['created'] = string_to_datetime(_dict.get('created'))
        if 'updated' in _dict:
            args['updated'] = string_to_datetime(_dict.get('updated'))
        if 'status' in _dict:
            args['status'] = _dict.get('status')
        if 'read_only' in _dict:
            args['read_only'] = _dict.get('read_only')
        if 'size' in _dict:
            args['size'] = _dict.get('size')
        if 'requested_size' in _dict:
            args['requested_size'] = _dict.get('requested_size')
        if 'index_capacity' in _dict:
            args['index_capacity'] = IndexCapacity._from_dict(
                _dict.get('index_capacity'))
        if 'search_status' in _dict:
            args['search_status'] = SearchStatus._from_dict(
                _dict.get('search_status'))
        return cls(**args)
952018
def serialize_value(self, value):
        
        # Create a list of serialize methods to run the value through
        serialize_methods = [
            self.serialize_model,
            self.serialize_json_string,
            self.serialize_list,
            self.serialize_dict
        ]

        # Run all of our serialize methods over our value
        for serialize_method in serialize_methods:
            value = serialize_method(value)

        # Return the serialized context value
        return value
93833
def schema_from_context(context):
    """"""
    item_class = context.get('class')
    return (
        serializer_mapping[item_class] if item_class else BaseSchema,
        context.get('many', False)
    )
870120
def serialize_to_dict(dictionary):
    ''''''
    retval = {}
    
    for k, v in dictionary.items():
        if isinstance(v, dict):
            retval[k] = serialize_to_dict(v)
        else:
            # This is when custom serialization happens
            if isinstance(v, np.ndarray):
                if v.dtype == 'float64':
                    # We don't support float64 on js side
                    v = v.astype('float32')

                retval[k] = encode_numpy(v)
            else:
                retval[k] = v
    
    return retval
668970
def serialize(self, value, primitive=False):
        """"""
        if hasattr(value, 'serialize'):
            # i.e. value is a nested model
            return value.serialize(primitive=primitive)
        else:
            return value
1365858
function copycontext(context) {
    var t = {};
    var keys =  context.keys();
    var i = keys.length;
    var k, v, j;
    while (i--) {
      k = keys[i];
      if (k[0] == '_')
        continue;
      v = context.get(k);
      if (v && {}.toString.call(v) === '[object Function]')
        continue;

      try {
        j = JSON.stringify(v);
        t[k] = JSON.parse(j);
      } catch(err) {
        t[k] = "Exception: " + err;
      }
    }
    
    return t;
  }
1216755
def render_serialization(self, context, result):
		""""""
		
		resp = context.response
		serial = context.serialize
		match = context.request.accept.best_match(serial.types, default_match=self.default)
		result = serial[match](result)
		
		if isinstance(result, str):
			result = result.decode('utf-8')
		
		resp.charset = 'utf-8'
		resp.content_type = match
		resp.text = result
		
		return True
731691
def _deserialize_dict_attributes(cls, cls_context, dict_):
        

        dict_deserialized = {}

        for key in dict_.keys():
            key_deserialized = cls._deserialize_key(key)
            value_specs = cls._get_value_specs(cls_context, key_deserialized)

            if value_specs is not None:
                dict_deserialized[value_specs.name] = cls._deserialize_value(
                    value_specs.types,
                    dict_[key]
                )
            else:
                cls._warn_key_unknown(cls_context, key)

        return dict_deserialized
1212451
def serialize(self):
        """"""
        # Serialize fields to a dict
        data = {}
        for field_name in self:
            value = self._values.get(field_name)
            field = self.fields.get(field_name)
            if value is not None:
                if field.all:
                    value = [field.serialize(v) for v in value]
                else:
                    value = field.serialize(value)
            # Skip empty fields unless field.null
            if not field.null and ((field.all and value == []) or (not field.all and value in {None, ''})):
                continue
            data[field.name] = value
        return data