Giter VIP home page Giter VIP logo

Comments (1)

ziima avatar ziima commented on July 30, 2024

It should be even bit more complicated to fulfill conditions from protocol.

def normal_dict(request):
    """
    Converts a django request arguments (MultiValueDict request.GET, request.POST) into a standard python dict 
    whose values are the last value from each of the MultiValueDict's value lists. This avoids the OpenID library's 
    refusal to deal with dicts whose values are lists, because in OpenID, each key in the query arg set can have at most one value.
    Also converts keys from unicode to string, so they can be used as arguments in functions.

    If request method is POST silently throw out OpenID-like arguments from GET see
    U{http://openid.net/specs/openid-authentication-2_0.html#rfc.section.4.1.2}

    @param request: Django request object 
    @type request: C{django.http.HttpRequest}
    @return: Dictionary with request arguments
    @rtype: C{dict}
    """
    if request.method == 'POST':
        normal = {}
        #take GET first, override them with POST
        for key, value in request.GET.items():
            #all openid arguments must be in POST
            try:
                prefix, rest = key.split('.', 1)
                if prefix != 'openid':
                    normal[str(key)] = value
            except ValueError: #no prefix
                normal[str(key)] = value

        for key, value in request.POST.items():
            normal[str(key)] = value
        return normal
    else:
        #if not POST, all arguments are GET
        normal = {}
        for key, value in request.GET.items():
            normal[str(key)] = value
        return normal

from python-openid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.