示例#1
0
 def request(self, method, path, data, headers):
     req = webob.Request.blank(path)
     req.method = method
     req.body = data
     req.headers = headers
     req.headers['Accept'] = 'text/html'
     req.host = self.host
     # Call the WSGI app, get the HTTP response
     resp = str(req.get_response(self.app))
     # For some reason, the response doesn't have "HTTP/1.0 " prepended; I
     # guess that's a function the web server usually provides.
     resp = "HTTP/1.0 %s" % resp
     self.sock = FakeHttplibSocket(resp)
     self.http_response = HTTPResponse(self.sock)
     # NOTE(vish): boto is accessing private variables for some reason
     self._HTTPConnection__response = self.http_response
     self.http_response.begin()
示例#2
0
文件: test_api.py 项目: kumarcv/nova
class FakeHttplibConnection(object):
    """A fake httplib.HTTPConnection for boto to use

    requests made via this connection actually get translated and routed into
    our WSGI app, we then wait for the response and turn it back into
    the HTTPResponse that boto expects.
    """

    def __init__(self, app, host, is_secure=False):
        self.app = app
        self.host = host

    def request(self, method, path, data, headers):
        req = webob.Request.blank(path)
        req.method = method
        req.body = data
        req.headers = headers
        req.headers["Accept"] = "text/html"
        req.host = self.host
        # Call the WSGI app, get the HTTP response
        resp = str(req.get_response(self.app))
        # For some reason, the response doesn't have "HTTP/1.0 " prepended; I
        # guess that's a function the web server usually provides.
        resp = "HTTP/1.0 %s" % resp
        self.sock = FakeHttplibSocket(resp)
        self.http_response = HTTPResponse(self.sock)
        # NOTE(vish): boto is accessing private variables for some reason
        self._HTTPConnection__response = self.http_response
        self.http_response.begin()

    def getresponse(self):
        return self.http_response

    def getresponsebody(self):
        return self.sock.response_string

    def close(self):
        """Required for compatibility with boto/tornado."""
        pass
示例#3
0
def user_info(request):
    
    if 'credentials' not in request.session:
        return HttpResponseRedirect(reverse('home_page'))
     
    
    credentials = client.OAuth2Credentials.from_json(request.session['credentials'])

     
    if credentials.access_token_expired:
        return HttpResponseRedirect(reverse('home_page'))

    
    http_auth = credentials.authorize(httplib2.Http())
    service = discovery.build('plus', 'v1', http=http_auth)
    google_request = service.people().get(userId='me')
    result = google_request.execute(http=http_auth)
    
    if 'domain' not in result.keys():
        return HttpResponse("Not a valid user to register") 
    
    elif result['domain'] == "above-inc.com":
        email = result['emails'][0]['value']
        username = email[:-14]
        password = result['id']
    else:
        return HttpResponse("Nothing")
    try:
        saved_user = User.objects.get(username = username,password=password,email = email)   
    except Exception as e:
        print e
        saved_user = User(username=username,password=password,email = email)
        saved_user.save()
    
            
    try:    
        user = authenticate(username=saved_user, password=password)
         
    except Exception as e:
        print e
        return HTTPResponse("not authenticated")
    
    if user is not None:
        if user.is_active:
            login(request,user)
            return HttpResponseRedirect(reverse('userdetails'))
        else:
            return HttpResponseRedirect(reverse("home_page"))
    else:
        print "some were wrong in else login else"
        return HttpResponseRedirect(reverse("home_page"))    
示例#4
0
class FakeHttplibConnection(object):
    """A fake httplib.HTTPConnection for boto to use

    requests made via this connection actually get translated and routed into
    our WSGI app, we then wait for the response and turn it back into
    the HTTPResponse that boto expects.
    """
    def __init__(self, app, host, is_secure=False):
        self.app = app
        self.host = host

    def request(self, method, path, data, headers):
        req = webob.Request.blank(path)
        req.method = method
        req.body = data
        req.headers = headers
        req.headers['Accept'] = 'text/html'
        req.host = self.host
        # Call the WSGI app, get the HTTP response
        resp = str(req.get_response(self.app))
        # For some reason, the response doesn't have "HTTP/1.0 " prepended; I
        # guess that's a function the web server usually provides.
        resp = "HTTP/1.0 %s" % resp
        self.sock = FakeHttplibSocket(resp)
        self.http_response = HTTPResponse(self.sock)
        # NOTE(vish): boto is accessing private variables for some reason
        self._HTTPConnection__response = self.http_response
        self.http_response.begin()

    def getresponse(self):
        return self.http_response

    def getresponsebody(self):
        return self.sock.response_string

    def close(self):
        """Required for compatibility with boto/tornado"""
        pass
示例#5
0
文件: test_api.py 项目: xww/nova-old
 def request(self, method, path, data, headers):
     req = webob.Request.blank(path)
     req.method = method
     req.body = data
     req.headers = headers
     req.headers['Accept'] = 'text/html'
     req.host = self.host
     # Call the WSGI app, get the HTTP response
     resp = str(req.get_response(self.app))
     # For some reason, the response doesn't have "HTTP/1.0 " prepended; I
     # guess that's a function the web server usually provides.
     resp = "HTTP/1.0 %s" % resp
     self.sock = FakeHttplibSocket(resp)
     self.http_response = HTTPResponse(self.sock)
     # NOTE(vish): boto is accessing private variables for some reason
     self._HTTPConnection__response = self.http_response
     self.http_response.begin()
示例#6
0
文件: views.py 项目: OneDay2017/tlweb
def page404(request):

    return HTTPResponse("444")