Add docs and updated copyright.

This commit is contained in:
Bastian Kleineidam 2012-10-10 06:53:16 +02:00
parent 63cf8adf54
commit 871508ef5d
9 changed files with 21 additions and 5 deletions

View file

@ -27,6 +27,7 @@ from ..decorators import synchronized
_lock = get_lock("addrinfo")
class AddrInfo(object):
"""Cache for socket.getaddrinfo() results."""
def __init__(self):
"""Initialize address info cache and cache statistics."""

View file

@ -1,5 +1,5 @@
# -*- coding: iso-8859-1 -*-
# Copyright (C) 2005-2011 Bastian Kleineidam
# Copyright (C) 2005-2012 Bastian Kleineidam
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -37,10 +37,12 @@ DefaultLimits = dict(
)
def get_connection_id(connection):
"""Return unique id for connection object."""
return id(connection)
def is_expired(curtime, conn_data):
"""Test if connection is expired."""
return (curtime+5.0) >= conn_data[2]

View file

@ -24,6 +24,7 @@ from ..decorators import synchronized
_lock = get_lock("checksums")
class ChecksumInfo(object):
"""Cache for content checksums."""
def __init__(self):
"""Initialize checksums and cache statistics."""
@ -68,4 +69,3 @@ def get_checksum_urls(url, content):
@rtype: list of unicode"""
checksum = hashlib.sha1(content).hexdigest()
return _checksuminfo.get_checksum_urls(url, checksum)

View file

@ -48,6 +48,8 @@ class RobotsTxt (object):
return self._allows_url(roboturl, url, proxy, user, password, callback)
def _allows_url (self, roboturl, url, proxy, user, password, callback):
"""Ask robots.txt allowance. Assumes only single thread per robots.txt
URL calls this function."""
with cache_lock:
if roboturl in self.cache:
self.hits += 1
@ -69,4 +71,5 @@ class RobotsTxt (object):
@synchronized(robot_lock)
def get_lock(self, roboturl):
"""Return lock for robots.txt url."""
return self.roboturl_locks.setdefault(roboturl, get_lock(roboturl))

View file

@ -96,6 +96,7 @@ class LCOptionParser (optparse.OptionParser, object):
@notimplemented
def get_usage (self):
"""Print usage text."""
pass
def print_help_msg (self, s, out):
@ -109,6 +110,7 @@ class LCOptionParser (optparse.OptionParser, object):
@notimplemented
def print_help (self, file=None):
"""Print help text to given file."""
pass

View file

@ -70,6 +70,7 @@ class CONSOLE_SCREEN_BUFFER_INFO(Structure):
("dwMaximumWindowSize", COORD),
]
def __str__(self):
"""Get string representation of console screen buffer info."""
return '(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)' % (
self.dwSize.Y, self.dwSize.X
, self.dwCursorPosition.Y, self.dwCursorPosition.X
@ -79,6 +80,7 @@ class CONSOLE_SCREEN_BUFFER_INFO(Structure):
)
def GetConsoleScreenBufferInfo(stream_id=STDOUT):
"""Get console screen buffer info object."""
handle = handles[stream_id]
csbi = CONSOLE_SCREEN_BUFFER_INFO()
success = windll.kernel32.GetConsoleScreenBufferInfo(
@ -87,6 +89,7 @@ def GetConsoleScreenBufferInfo(stream_id=STDOUT):
def SetConsoleTextAttribute(stream_id, attrs):
"""Set a console text attribute."""
handle = handles[stream_id]
return windll.kernel32.SetConsoleTextAttribute(handle, attrs)
@ -111,6 +114,7 @@ _default_style = None
def init():
"""Initialize foreground and background attributes."""
global _default_foreground, _default_background, _default_style
attrs = GetConsoleScreenBufferInfo(STDOUT).wAttributes
_default_foreground = attrs & 7
@ -119,10 +123,12 @@ def init():
def get_attrs(foreground, background, style):
"""Get foreground and background attributes."""
return foreground + (background << 4) + style
def set_console(stream=STDOUT, foreground=None, background=None, style=None):
"""Set console foreground and background attributes."""
if foreground is None:
foreground = _default_foreground
if background is None:
@ -134,8 +140,10 @@ def set_console(stream=STDOUT, foreground=None, background=None, style=None):
def reset_console(stream=STDOUT):
"""Reset the console."""
set_console(stream=stream)
def get_console_size():
"""Get the console size."""
return GetConsoleScreenBufferInfo(STDOUT).dwSize

View file

@ -1,5 +1,5 @@
# -*- coding: iso-8859-1 -*-
# Copyright (C) 2005-2011 Bastian Kleineidam
# Copyright (C) 2005-2012 Bastian Kleineidam
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,5 @@
# -*- coding: iso-8859-1 -*-
# Copyright (C) 2010 Bastian Kleineidam
# Copyright (C) 2010-2012 Bastian Kleineidam
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,5 @@
# -*- coding: iso-8859-1 -*-
# Copyright (C) 2006-2010 Bastian Kleineidam
# Copyright (C) 2006-2012 Bastian Kleineidam
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by