Skip to content

Commit

Permalink
Make most functions and all data structures private.
Browse files Browse the repository at this point in the history
I'm about to make a release, and I want to minimize the initial public
API.

The purpose of this package is to be a reference parser and importer
for Senate LD-1/LD-2 documents, so it'd be nice if it were easily
extensible -- more of a toolkit than a production
parser/importer. That's why all functions and data structures were
initially part of the public API. However, in its current state, you
need a lot of knowledge about the internals of the parser and database
schema to make changes that don't break other parts, so hide all of
the guts for now until I come up with a more robust mechanism for
extending and/or hooking it.
  • Loading branch information
Drew Hess committed Oct 13, 2008
1 parent c53d5ca commit 514d0ad
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 193 deletions.
39 changes: 19 additions & 20 deletions lobbyists/benchmark.py
Expand Up @@ -19,54 +19,54 @@

"""Internal benchmarking functions for the lobbyists package."""

import lobbyists
from . import lobbyists
import time
import sys


def timed_func(func):
def _timed_func(func):
def timer(*args):
t1 = time.clock()
start = time.clock()
result = func(*args)
t2 = time.clock()
return result, t2 - t1
finish = time.clock()
return result, finish - start
return timer


def parse_all(doc):
def _parse_all(doc):
return list(lobbyists.parse_filings(doc))


def skip_import_list(record, con):
def _skip_import_list(record, con):
return list()


def skip_import(record, con):
def _skip_import(record, con):
return None


def time_parse(doc):
timed_parser = timed_func(parse_all)
timed_parser = _timed_func(_parse_all)
return timed_parser(doc)


skippers = {'registrant': skip_import,
'client': skip_import,
'lobbyists': skip_import_list,
'govt_entities': skip_import_list,
'issues': skip_import_list,
'affiliated_orgs': skip_import_list}
_skippers = {'registrant': _skip_import,
'client': _skip_import,
'lobbyists': _skip_import_list,
'govt_entities': _skip_import_list,
'issues': _skip_import_list,
'affiliated_orgs': _skip_import_list}


def time_import(filings, cur, skiplist=[]):
def time_import(filings, cur, skiplist=list()):
for key in skiplist:
lobbyists.entity_importers[key] = skippers[key]
timed_importer = timed_func(lobbyists.import_filings)
lobbyists._entity_importers[key] = _skippers[key]
timed_importer = _timed_func(lobbyists.import_filings)
return timed_importer(cur, filings)


def main(argv=None):
import sqlite3
import sys
import optparse
import os.path

Expand Down Expand Up @@ -116,5 +116,4 @@ def main(argv=None):


if __name__ == "__main__":
import sys
sys.exit(main())

0 comments on commit 514d0ad

Please sign in to comment.