diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2018-06-20 11:39:40 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2018-06-20 11:39:58 +0200 |
commit | 4302c6735d2985ed76e4a2d4a3319c7ef2c7ca84 (patch) | |
tree | a7b11932eef7d7325f5e561271c04b3e8bc81088 /crocoite/controller.py | |
parent | 7730e0d64ec895091a0dd7eb0e3c6ce2ed02d981 (diff) | |
download | crocoite-4302c6735d2985ed76e4a2d4a3319c7ef2c7ca84.tar.gz crocoite-4302c6735d2985ed76e4a2d4a3319c7ef2c7ca84.tar.bz2 crocoite-4302c6735d2985ed76e4a2d4a3319c7ef2c7ca84.zip |
Add __slots__ to classes
This is mainly a quality of life change
Diffstat (limited to 'crocoite/controller.py')
-rw-r--r-- | crocoite/controller.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/crocoite/controller.py b/crocoite/controller.py index cdae268..84001b7 100644 --- a/crocoite/controller.py +++ b/crocoite/controller.py @@ -23,6 +23,8 @@ Controller classes, handling actions required for archival """ class ControllerSettings: + __slots__ = ('logBuffer', 'maxBodySize', 'idleTimeout', 'timeout') + def __init__ (self, logBuffer=1000, maxBodySize=50*1024*1024, idleTimeout=2, timeout=10): self.logBuffer = logBuffer self.maxBodySize = maxBodySize @@ -38,6 +40,8 @@ defaultSettings = ControllerSettings () class EventHandler: """ Abstract base class for event handler """ + __slots__ = () + # this handler wants to know about exceptions before they are reraised by # the controller acceptException = False @@ -48,6 +52,8 @@ class EventHandler: from .browser import BrowserCrashed class StatsHandler (EventHandler): + __slots__ = ('stats') + acceptException = True def __init__ (self): @@ -72,6 +78,8 @@ from .browser import ChromeService, SiteLoader, Item from .util import getFormattedViewportMetrics class ControllerStart: + __slots__ = ('payload') + def __init__ (self, payload): self.payload = payload @@ -83,6 +91,8 @@ class SinglePageController: (stats, warc writer). """ + __slots__ = ('url', 'output', 'service', 'behavior', 'settings', 'logger', 'handler') + def __init__ (self, url, output, service=ChromeService (), behavior=cbehavior.available, \ logger=logging.getLogger(__name__), settings=defaultSettings, handler=[]): self.url = url @@ -183,6 +193,9 @@ class SinglePageController: class RecursionPolicy: """ Abstract recursion policy """ + + __slots__ = () + def __call__ (self, urls): raise NotImplementedError @@ -192,6 +205,9 @@ class DepthLimit (RecursionPolicy): depth==0 means no recursion, depth==1 is the page and outgoing links, … """ + + __slots__ = ('maxdepth') + def __init__ (self, maxdepth=0): self.maxdepth = maxdepth @@ -213,6 +229,9 @@ class PrefixLimit (RecursionPolicy): ignored: http://example.com/bar http://offsite.example/foo accepted: http://example.com/foobar http://example.com/foo/bar """ + + __slots__ = ('prefix') + def __init__ (self, prefix): self.prefix = prefix @@ -233,6 +252,9 @@ class RecursiveController (EventHandler): Visits links acording to recursionPolicy """ + __slots__ = ('url', 'output', 'service', 'behavior', 'settings', 'logger', + 'recursionPolicy', 'handler', 'urls', 'have') + def __init__ (self, url, output, service=ChromeService (), behavior=cbehavior.available, \ logger=logging.getLogger(__name__), settings=defaultSettings, recursionPolicy=DepthLimit (0), handler=[]): |