<commit_before># -*- encoding: utf-8 -*-
import django

__author__ = 'jond'

import os


import django.test.client

import django_offline.handlers

from PyQt4 import QtCore, QtNetwork

class NetworkAccessManager(QtNetwork.QNetworkAccessManager):
    """
    Our network access manager that is used instead of the default
    This allows us to jump in and interrupt the calls to usually external
    services
    """
    def createRequest(self, operation, request, data):
        """
        Deal with the request when it comes in
        """
        if data is None:
            data = {}

        # Set up the handler
        handler = django_offline.handlers.FakeHandler()
        # Convert the request to a django request
        dj_request = None
        rf = django.test.client.RequestFactory()
        urlstring = unicode(request.url().toString())
        if operation == QtNetwork.QNetworkAccessManager.PostOperation:
            dj_request = rf.post(urlstring, data)
        elif operation == QtNetwork.QNetworkAccessManager.GetOperation:
            dj_request = rf.get(urlstring, data)
        # add the response from django to the reply
        response = handler.get_response(dj_request)
        reply = django_offline.handlers.FakeReply(self, request, operation, response)
        # set up the reply with the correct status
        #reply.setAttribute(QtNetwork.QNetworkRequest.HttpStatusCodeAttribute, 200)
        if reply is None:
            reply = QtNetwork.QNetworkAccessManager.createRequest(self, operation, request, data)
        return reply<commit_msg>switched to wsgi hsndler. don't know if its the correct thing to do but seems more in keeping<commit_after># -*- encoding: utf-8 -*-
import django
from django.http import HttpResponse

__author__ = 'jond'

import os


import django.test.client

import django_offline.handlers

from PyQt4 import QtCore, QtNetwork

class NetworkAccessManager(QtNetwork.QNetworkAccessManager):
    """
    Our network access manager that is used instead of the default
    This allows us to jump in and interrupt the calls to usually external
    services
    """
    def createRequest(self, operation, request, data):
        """
        Deal with the request when it comes in
        """
        if data is None:
            data = {}

        # Set up the handler
        from django.core.wsgi import get_wsgi_application
        handler = get_wsgi_application()
        # Convert the request to a django request
        dj_request = None
        rf = django.test.client.RequestFactory()
        urlstring = unicode(request.url().toString())
        if operation == QtNetwork.QNetworkAccessManager.PostOperation:
            dj_request = rf.post(urlstring, data)
        elif operation == QtNetwork.QNetworkAccessManager.GetOperation:
            dj_request = rf.get(urlstring, data)
        # add the response from django to the reply
        response = handler(dj_request.environ, HttpResponse)
        reply = django_offline.handlers.FakeReply(self, request, operation, response)
        # set up the reply with the correct status
        #reply.setAttribute(QtNetwork.QNetworkRequest.HttpStatusCodeAttribute, 200)
        if reply is None:
            reply = QtNetwork.QNetworkAccessManager.createRequest(self, operation, request, data)
        return reply
{'fraction_non_alphanumeric': 0.07222389407162202, 'fraction_numerical': 0.003009328919650918, 'mean_word_length': 2.8339100346020762, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3095319', 'n_tokens_mistral': 870, 'n_tokens_neox': 849, 'n_words': 285}