Adds Attribute Exchange data (Hash) to an OpenID response. See:
 http://rakuto.blogspot.com/2008/03/ruby-fetch-and-store-some-attributes.html
973866
def add_ax(resp, data)
      ax_resp = OpenID::AX::FetchResponse.new
      ax_args = data.reverse_merge('mode' => 'fetch_response')
      ax_resp.parse_extension_args(ax_args)
      resp.add_extension(ax_resp)
      resp
    end
215612
def to_hash
      {}.tap do |hash|
        _attributes.each do |key, value|
          hash[key] = value.respond_to?(:to_hash) ? value.to_hash : value
        end
      end
    end
960965
def add_data_to_attribute(scenario_id, resource_attr_id, dataset,**kwargs):
    
    user_id = kwargs.get('user_id')

    _check_can_edit_scenario(scenario_id, user_id)

    scenario_i = _get_scenario(scenario_id, user_id)

    try:
        r_scen_i = db.DBSession.query(ResourceScenario).filter(
                                ResourceScenario.scenario_id==scenario_id,
                                ResourceScenario.resource_attr_id==resource_attr_id).one()
        log.info("Existing resource scenario found for %s in scenario %s", resource_attr_id, scenario_id)
    except NoResultFound:
        log.info("No existing resource scenarios found for %s in scenario %s. Adding a new one.", resource_attr_id, scenario_id)
        r_scen_i = ResourceScenario()
        r_scen_i.scenario_id      = scenario_id
        r_scen_i.resource_attr_id = resource_attr_id
        scenario_i.resourcescenarios.append(r_scen_i)

    data_type = dataset.type.lower()

    value = dataset.parse_value()

    dataset_metadata = dataset.get_metadata_as_dict(user_id=kwargs.get('user_id'),
                                                    source=kwargs.get('source'))
    if value is None:
        raise HydraError("Cannot set value to attribute. "
            "No value was sent with dataset %s", dataset.id)

    data_hash = dataset.get_hash(value, dataset_metadata)

    assign_value(r_scen_i, data_type, value, dataset.unit_id, dataset.name,
                          metadata=dataset_metadata, data_hash=data_hash, user_id=user_id)

    db.DBSession.flush()
    return r_scen_i
1227027
def update_attributes(attr = {})
      attr.each_pair do |k, v|
        if v.is_a?(Array) || v.is_a?(Hash)
          send("#{k}=", v.dup)
        else
          send("#{k}=", v)
        end
      end
    end
902586
def save_modified_attributes!(opts={})
    options = { :validate => true }.merge(opts)
    if options[:validate]
      # Complain if we aren't valid
      raise InvalidRecord, @errors.full_messages.join(", ") unless valid?
    end
    # Send the save request
    response = self.class.session.connection.set_entry(self.class._module.name, serialize_modified_attributes)
    # Complain if we don't get a parseable response back
    raise RecordsaveFailed, "Failed to save record: #{self}.  Response was not a Hash" unless response.is_a? Hash
    # Complain if we don't get a valid id back
    raise RecordSaveFailed, "Failed to save record: #{self}.  Response did not contain a valid 'id'." if response["id"].nil?
    # Save the id to the record, if it's a new record
    @attributes[:id] = response["id"] if new?
    raise InvalidRecord, "Failed to update id for: #{self}." if id.nil?
    # Clear the modified attributes Hash
    @modified_attributes = {}
    true
  end
1341993
def add_key(self, attributes, store_key):
        
        undefined = False
        try:
            value = self.get_value(attributes)
        except (KeyError, IndexError):
            undefined = True

        # We remove old values in _reverse_index
        self.remove_key(store_key)
        if not undefined:
            if isinstance(value, (list,tuple)):
                # We add an extra hash value for the list itself
                # (this allows for querying the whole list)
                values = value
                hash_value = self.get_hash_for(value)
                self.add_hashed_value(hash_value, store_key)
            else:
                values = [value]

            for value in values:
                hash_value = self.get_hash_for(value)
                self.add_hashed_value(hash_value, store_key)
        else:
            self.add_undefined(store_key)
571
def load(attributes, remove_root=false)
      attributes = attributes ? attributes.stringify_keys : {}
      self.class.belongs_to_with_parents.each do |belongs_to_param|
        attributes["#{belongs_to_param}_id"] ||= prefix_options["#{belongs_to_param}_id".intern]

        # also set prefix attributes as real attributes. Otherwise,
        # belongs_to attributes will be stripped out of the response
        # even if we aren't actually using the association.
        @attributes["#{belongs_to_param}_id"] = attributes["#{belongs_to_param}_id"]
      end
      super(attributes, remove_root)
    end
55680
def populate_token_attributes(self, response):
        """"""

        if 'access_token' in response:
            self.access_token = response.get('access_token')

        if 'refresh_token' in response:
            self.refresh_token = response.get('refresh_token')

        if 'token_type' in response:
            self.token_type = response.get('token_type')

        if 'expires_in' in response:
            self.expires_in = response.get('expires_in')
            self._expires_at = time.time() + int(self.expires_in)

        if 'expires_at' in response:
            self._expires_at = int(response.get('expires_at'))

        if 'mac_key' in response:
            self.mac_key = response.get('mac_key')

        if 'mac_algorithm' in response:
            self.mac_algorithm = response.get('mac_algorithm')
479818
def attributes
      _attributes.inject(HashWithIndifferentAccess.new) do |hash, attribute|
        hash.update attribute => send(attribute)
      end
    end
578721
def to_hash
      result = @response[:magic_response][:magic_result][:diffgram]
      result = strip_attributes(result)
      result = convert_dates_to_utc(result)

      if result.nil?
        return []
      end

      # All magic responses wrap their result in an ActionResponse element
      result = result.values.first

      # Often the first element in ActionResponse is an element
      # called ActionInfo, but in some cases it has a different name
      # so we just get the first element.
      result.values.first
    end
180847
def access_token_response_data(self, access_token, response_type=None, nonce=''):
        

        # Clear the scope for requests that do not use OpenID Connect.
        # Scopes for pure OAuth2 request are currently not supported.
        scope = constants.DEFAULT_SCOPE

        extra_data = {}

        # Add OpenID Connect `id_token` if requested.
        #
        # TODO: Unfourtunately because of how django-oauth2-provider implements
        # scopes, we cannot check if `openid` is the first scope to be
        # requested, as required by OpenID Connect specification.

        if provider.scope.check(constants.OPEN_ID_SCOPE, access_token.scope):
            id_token = self.get_id_token(access_token, nonce)
            extra_data['id_token'] = self.encode_id_token(id_token)
            scope = provider.scope.to_int(*id_token.scopes)

        # Update the token scope, so it includes only authorized values.
        access_token.scope = scope
        access_token.save()

        # Get the main fields for OAuth2 response.
        response_data = super(AccessTokenView, self).access_token_response_data(access_token)

        # Add any additional fields if OpenID Connect is requested. The order of
        # the addition makes sures the OAuth2 values are not overrided.
        response_data = dict(extra_data.items() + response_data.items())

        return response_data
126453
def user(id)
      data = request("/user/show", id: id)
      Hashie::Mash.new(data["user"])
    end
1237535
def to_hash
      hash = {}
      ATTRS.each do |attribute|
        hash[attribute] = self.send(attribute)
      end

      hash
    end
1034650
def data_object_attribute(data)
      attribute = @_object.__send__(data)
      attribute = attribute.as_json if
        is_collection?(attribute, false) &&
        attribute.respond_to?(:as_json)
      attribute
    end
394879
def addAttribute(self, attrib: Attribute):
        
        self._attributes[attrib.key()] = attrib
        req = attrib.ledgerRequest()
        if req:
            self.pendRequest(req, attrib.key())
        return len(self._pending)
538548
def set_attrs_from_response(response)
      unless response.body.nil? || (response.body.length < 2)
        json = self.class.parse_json(response.body)
        set_attrs(json)
      end
    end
944496
def update_page_related_attributes!(response)
      data = JSON.parse(response.body, symbolize_names: true)
      @attributes[:next] = data[:next]
      @attributes[:previous] = data[:previous]
      @attributes[:results] = data[:results]
      transform_results!
    end