<commit_before>import ConfigParser
import datetime
import sys
import os
import cherrypy
import json
import traceback
import types

import tangelo
import tangelo.util


class Directive(object):
    HTTPRedirect = 1
    InternalRedirect = 2
    ListPlugins = 3

    def __init__(self, t, argument=None):
        self.type = t
        self.argument = argument


class Content(object):
    NotFound = 1
    Directory = 2
    File = 3
    Service = 4
    Restricted = 5

    def __init__(self, t, path=None, pargs=None):
        self.type = t
        self.path = path
        self.pargs = pargs


class UrlAnalysis(object):
    def __init__(self):
        self.directive = None
        self.content = None
        self.reqpathcomp = None
        self.pathcomp = None


def analyze_url(raw_reqpath):
    webroot = cherrypy.config.get("webroot")
    plugins = cherrypy.config.get("plugins")

    reqpath = raw_reqpath

    analysis = UrlAnalysis()

    # If the request path is blank, redirect to /.
    if reqpath == "":
        analysis.directive = Directive(Directive.HTTPRedirect, argument="/")
        return analysis

    if plugins is not None and reqpath[0] == "/" and reqpath.split("/")[1] == "plugin":
        plugin_comp = reqpath.split("/")<commit_msg>Adding a pretty-printer __str__() to UrlAnalysis class<commit_after>import ConfigParser
import datetime
import sys
import os
import cherrypy
import json
import traceback
import types

import tangelo
import tangelo.util


class Directive(object):
    HTTPRedirect = 1
    InternalRedirect = 2
    ListPlugins = 3

    def __init__(self, t, argument=None):
        self.type = t
        self.argument = argument


class Content(object):
    NotFound = 1
    Directory = 2
    File = 3
    Service = 4
    Restricted = 5

    def __init__(self, t, path=None, pargs=None):
        self.type = t
        self.path = path
        self.pargs = pargs


class UrlAnalysis(object):
    def __init__(self):
        self.directive = None
        self.content = None
        self.reqpathcomp = None
        self.pathcomp = None

    def __str__(self):
        import pprint
        d = {}
        for k, v in self.__dict__.iteritems():
            if v is not None and k in ["content", "directive"]:
                d[k] = v.__dict__
            else:
                d[k] = v
        return pprint.pformat(d)


def analyze_url(raw_reqpath):
    webroot = cherrypy.config.get("webroot")
    plugins = cherrypy.config.get("plugins")

    reqpath = raw_reqpath

    analysis = UrlAnalysis()

    # If the request path is blank, redirect to /.
    if reqpath == "":
        analysis.directive = Directive(Directive.HTTPRedirect, argument="/")
        return analysis

    if plugins is not None and reqpath[0] == "/" and reqpath.split("/")[1] == "plugin":
        plugin_comp = reqpath.split("/")
{'fraction_non_alphanumeric': 0.09869580542826929, 'fraction_numerical': 0.007049700387733521, 'mean_word_length': 2.4441747572815533, 'pattern_counts': {'":': 4, '<': 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': '3918538', 'n_tokens_mistral': 903, 'n_tokens_neox': 846, 'n_words': 248}