Example #1
0
from datetime import datetime
from threading import RLock
import traceback
import codecs
import sys
import os

from text import encode, decode, get_encoding

DEBUG, INFO, WARN, ERROR = xrange(4)
LEVELS = ['DEBUG', 'INFO', 'WARN', 'ERROR']

DEFAULT_LEVEL = INFO
DEFAULT_FORMAT = '[%(time)s] %(level)s: %(message)s'
DEFAULT_TIME_FORMAT = '%c'
DEFAULT_ENCODING = get_encoding()

NoTrap = SystemExit, KeyboardInterrupt

lock = RLock()

class LoggerError(Exception):

    def __str__(self):
        return '%s: %r' % (self.args[0], self.args[1])


class StreamHandler(object):

    def __init__(self, stream, encoding=None, level=None):
        if encoding is None:
Example #2
0
        pass


def metacharset(data):
    """Parse data for HTML meta character encoding"""
    for meta in meta_re.findall(data):
        attrs = parseattrs(meta)
        if (u'http-equiv' in attrs and
            attrs[u'http-equiv'].lower() == u'content-type' and
            u'content' in attrs):
            content = attrs[u'content']
            content = parseattrs(content)
            if u'charset' in content:
                return lookup(content[u'charset'])


def parseattrs(data):
    """Parse key=val attributes"""
    #log.warn('PARSEATTRS: %r' % data)
    attrs = {}
    for key, rest, val in attr_re.findall(data):
        if not rest:
            val = None
        elif val[:1] == '\'' == val[-1:] or val[:1] == '"' == val[-1:]:
            val = val[1:-1]
        attrs[key.lower()] = val
    return attrs


ENCODING = get_encoding()