<commit_before>#!/usr/bin/env python
"""
Copyright (C) 2012 <NAME> <<EMAIL>>
"""

"""static - A stupidly simple WSGI way to serve static (or mixed) content.

(See the docstrings of the various functions and classes.)

Copyright (C) 2006-2009 <NAME> - http://lukearno.com/

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to:

The Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor,
Boston, MA  02110-1301, USA.

Luke Arno can be found at http://lukearno.com/

"""

import mimetypes
import email.utils as rfc822
import time
import string
import sys
from os import path, stat
from wsgiref import util
from wsgiref.headers import Headers
from wsgiref.simple_server import make_server
from optparse import OptionParser

try:
    from pkg_resources import resource_filename, Requirement
except:
    pass

try:
    import kid
except:
    pass

try:
    from genshi.template import MarkupTemplate
except:
    pass

if sys.version < '3':
    import codecs

    def u(x):
        return codecs.unicode_escape_decode(x)[0]
else:
    def u(x):
        return x


class MagicError(Exception):
    pass


def _encode(string, encoding):
    if sys.version_info[0] > 2:
        return string.encode(encoding=encoding, errors='strict')
    else:
        if type(u('')) == type(string):
            string = string.encode(encoding)
        return string


def _decode(string, encoding):
    if sys.version_info[0] > 2:
        return string.decode(encoding=encoding, errors='strict')
    else:
        return string


def _open(filename, encoding):
    if sys.version_info[0] > 2:
        return open(filename, 'r', encoding=encoding, errors='strict')
    else:
        return open(filename, 'rb')


class StatusApp:

    """Used by WSGI apps to return some HTTP status."""

    def __init__(self, status, message=None, encoding=sys.getdefaultencoding()):
        self.status = status
        self.encoding = encoding
        if message is None:
            self.message = status
        else:
            self.message = message

    def __call__(self, environ, start_response, headers=[]):
        if self.message:
            Headers(headers).add_header('Content-type', 'text/plain')
        start_response(self.status, headers)
        if environ['REQUEST_METHOD'] == 'HEAD':
            return [_encode("", self.econding)]
        else:
            return [_encode(self.message, self.encoding)]


class Cling(object):

    """A stupidly simple way to serve static content via WSGI.

    Serve the file of the same path as PATH_INFO in self.datadir.

    Look up the Content-type in self.content_types by extension<commit_msg>Fix type (econding -> encoding)<commit_after>#!/usr/bin/env python
"""
Copyright (C) 2012 <NAME> <<EMAIL>>
"""

"""static - A stupidly simple WSGI way to serve static (or mixed) content.

(See the docstrings of the various functions and classes.)

Copyright (C) 2006-2009 <NAME> - http://lukearno.com/

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to:

The Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor,
Boston, MA  02110-1301, USA.

Luke Arno can be found at http://lukearno.com/

"""

import mimetypes
import email.utils as rfc822
import time
import string
import sys
from os import path, stat
from wsgiref import util
from wsgiref.headers import Headers
from wsgiref.simple_server import make_server
from optparse import OptionParser

try:
    from pkg_resources import resource_filename, Requirement
except:
    pass

try:
    import kid
except:
    pass

try:
    from genshi.template import MarkupTemplate
except:
    pass

if sys.version < '3':
    import codecs

    def u(x):
        return codecs.unicode_escape_decode(x)[0]
else:
    def u(x):
        return x


class MagicError(Exception):
    pass


def _encode(string, encoding):
    if sys.version_info[0] > 2:
        return string.encode(encoding=encoding, errors='strict')
    else:
        if type(u('')) == type(string):
            string = string.encode(encoding)
        return string


def _decode(string, encoding):
    if sys.version_info[0] > 2:
        return string.decode(encoding=encoding, errors='strict')
    else:
        return string


def _open(filename, encoding):
    if sys.version_info[0] > 2:
        return open(filename, 'r', encoding=encoding, errors='strict')
    else:
        return open(filename, 'rb')


class StatusApp:

    """Used by WSGI apps to return some HTTP status."""

    def __init__(self, status, message=None, encoding=sys.getdefaultencoding()):
        self.status = status
        self.encoding = encoding
        if message is None:
            self.message = status
        else:
            self.message = message

    def __call__(self, environ, start_response, headers=[]):
        if self.message:
            Headers(headers).add_header('Content-type', 'text/plain')
        start_response(self.status, headers)
        if environ['REQUEST_METHOD'] == 'HEAD':
            return [_encode("", self.encoding)]
        else:
            return [_encode(self.message, self.encoding)]


class Cling(object):

    """A stupidly simple way to serve static content via WSGI.

    Serve the file of the same path as PATH_INFO in self.datadir.

    Look up the Content-type in self.content_types by extension
{'fraction_non_alphanumeric': 0.0871473354231975, 'fraction_numerical': 0.01128526645768025, 'mean_word_length': 3.2258278145695365, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 18, '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': '4382386', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1781, 'n_words': 704}