This commit is contained in:
Kovid Goyal 2010-12-16 10:57:15 -07:00
parent 6a6b2a6f58
commit 5ce7afa6e2
2 changed files with 18 additions and 0 deletions

View File

@ -17,6 +17,7 @@ pdfreflow, pdfreflow_error = plugins['pdfreflow']
def get_metadata(stream, cover=True):
if pdfreflow is None:
raise RuntimeError(pdfreflow_error)
stream.seek(0)
raw = stream.read()
#isbn = _isbn_pat.search(raw)
#if isbn is not None:

View File

@ -5,6 +5,8 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import gc
## {{{ http://code.activestate.com/recipes/286222/ (r1)
import os
@ -52,4 +54,19 @@ def stacksize(since=0.0):
## end of http://code.activestate.com/recipes/286222/ }}}
def gc_histogram():
"""Returns per-class counts of existing objects."""
result = {}
for o in gc.get_objects():
t = type(o)
count = result.get(t, 0)
result[t] = count + 1
return result
def diff_hists(h1, h2):
"""Prints differences between two results of gc_histogram()."""
for k in h1:
if h1[k] != h2[k]:
print "%s: %d -> %d (%s%d)" % (
k, h1[k], h2[k], h2[k] > h1[k] and "+" or "", h2[k] - h1[k])