From eb1c714abd283ec844803611ab01b7bc3221becb Mon Sep 17 00:00:00 2001 From: Brian Clapper Date: Fri, 6 Jun 2008 15:01:16 +0000 Subject: [PATCH] Bug fix --- fortune.wpr | 147 +++++++++++++++++++++++--------------------- fortune/__init__.py | 16 ++--- 2 files changed, 86 insertions(+), 77 deletions(-) diff --git a/fortune.wpr b/fortune.wpr index eacf818..585943e 100644 --- a/fortune.wpr +++ b/fortune.wpr @@ -21,7 +21,7 @@ proj.file-type = 'normal' guimgr.overall-gui-state = {'windowing-policy': 'combined-window', 'windows': [{'name': 'VsP9AM1ogLRvgyGcPNIomhVGfK'\ 'cv9m8S', - 'size-state': '', + 'size-state': 'maximized', 'type': 'dock', 'view': {'area': 'tall', 'current_pages': [1, @@ -92,9 +92,9 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window', 'fMatchCase': False, 'fOmitBinary': True, 'fRegexFlags': 46, - 'fReplaceText': u'make_fortune_data_file', + 'fReplaceText': u'fortune_file', 'fReverse': False, - 'fSearchText': u'makeFortuneDataFile', + 'fSearchText': u'fortune_file', 'fStartPos': 0, 'fStyle': 'text', 'fWholeWords': False, @@ -362,54 +362,13 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window', 19), 'current-loc': loc('fortune/__init__.py'), 'editor-states': {loc('fortune/__init__.py'): {'attrib-starts': [], - 'first-line': 201, + 'first-line': 0, 'sel-line': 0, 'sel-line-start': 0, 'selection_end': 0, 'selection_start': 0}}, 'has-focus': False}, - {'bookmarks': ([[loc('../../../../ctr3.py'), - {'attrib-starts': [('init_logging', - 43)], - 'first-line': 40, - 'sel-line': 45, - 'sel-line-start': 1273, - 'selection_end': 1290, - 'selection_start': 1290}, - 1200582943.181272], - (loc('../grizzled/grizzled/db/__init__.py'), - {'attrib-starts': [], - 'first-line': 200, - 'sel-line': 0, - 'sel-line-start': 0, - 'selection_end': 0, - 'selection_start': 0}, - 1208198623.163512), - (loc('../grizzled/grizzled/file/__init__.py'), - {'attrib-starts': [], - 'first-line': 40, - 'sel-line': 0, - 'sel-line-start': 0, - 'selection_end': 0, - 'selection_start': 0}, - 1208198641.055481), - (loc('../grizzled/grizzled/config.py'), - {'attrib-starts': [], - 'first-line': 160, - 'sel-line': 0, - 'sel-line-start': 0, - 'selection_end': 0, - 'selection_start': 0}, - 1208198647.6414609), - (loc('../grizzled/grizzled/file/includer.py'), - {'attrib-starts': [], - 'first-line': 80, - 'sel-line': 0, - 'sel-line-start': 0, - 'selection_end': 0, - 'selection_start': 0}, - 1208200808.3614011), - (loc('../grizzled/grizzled/db/__init__.py'), + {'bookmarks': ([(loc('../grizzled/grizzled/db/__init__.py'), {'attrib-starts': [], 'first-line': 57, 'sel-line': 0, @@ -464,7 +423,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window', 'selection_end': 3419, 'selection_start': 3419}, 1208295584.032558), - [loc('unknown: #1'), + [loc('unknown: #238'), {'attrib-starts': [], 'first-line': 0, 'sel-line': 0, @@ -531,23 +490,65 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window', 'selection_end': 7209, 'selection_start': 7209}, 1208381027.3971729), + (loc('fortune/__init__.py'), + {'attrib-starts': [], + 'first-line': 0, + 'sel-line': 0, + 'sel-line-start': 0, + 'selection_end': 0, + 'selection_start': 0}, + 1209425546.786469), + (loc('fortune/__init__.py'), + {'attrib-starts': [], + 'first-line': 0, + 'sel-line': 6, + 'sel-line-start': 83, + 'selection_end': 85, + 'selection_start': 83}, + 1212237382.0654449), + (loc('fortune/__init__.py'), + {'attrib-starts': [], + 'first-line': 118, + 'sel-line': 147, + 'sel-line-start': 5424, + 'selection_end': 5424, + 'selection_start': 5424}, + 1212237386.542619), + (loc('fortune/__init__.py'), + {'attrib-starts': [('get_random_fortune', + 148)], + 'first-line': 118, + 'sel-line': 157, + 'sel-line-start': 5668, + 'selection_end': 5680, + 'selection_start': 5680}, + 1212237449.688982), + (loc('fortune/__init__.py'), + {'attrib-starts': [('make_fortune_data_file', + 197)], + 'first-line': 159, + 'sel-line': 212, + 'sel-line-start': 7120, + 'selection_end': 7136, + 'selection_start': 7131}, + 1212237464.185307), [loc('fortune/__init__.py'), - {'attrib-starts': [('makeFortuneDataFile', - 196)], - 'first-line': 200, + {'attrib-starts': [('make_fortune_data_file', + 197)], + 'first-line': 159, 'sel-line': 212, - 'sel-line-start': 7194, - 'selection_end': 7209, - 'selection_start': 7209}, - 1209425546.786469]], + 'sel-line-start': 7120, + 'selection_end': 7136, + 'selection_start': 7131}, + 1212237501.3030331]], 19), 'current-loc': loc('fortune/__init__.py'), 'editor-states': {loc('fortune/__init__.py'): {'attrib-starts': [], - 'first-line': 0, - 'sel-line': 0, - 'sel-line-start': 0, - 'selection_end': 0, - 'selection_start': 0}}, + 'first-line': 204, + 'sel-line': 36, + 'sel-line-start': 1030, + 'selection_end': 1030, + 'selection_start': 1030}}, 'has-focus': False}), 'open_files': [u'fortune/__init__.py']}, 'split_percents': {0: 0.5}, @@ -560,8 +561,8 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window', 'user_data': {}}, 'window-alloc': (0, 25, - 1670, - 972)}, + 1251, + 919)}, {'name': 'nz8sdCZFY1fM2ZHHgdqsqa9sPhFohhIY', 'size-state': '', 'type': 'panel-tall', @@ -584,7 +585,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window', 'user_data': {}}, 'window-alloc': (259, 496, - 1389, + 1011, 116)}]} guimgr.recent-documents = [loc('fortune/__init__.py')] guimgr.visual-state = {loc('fortune/__init__.py'): {'attrib-starts': [], @@ -593,42 +594,49 @@ guimgr.visual-state = {loc('fortune/__init__.py'): {'attrib-starts': [], 'sel-line-start': 0, 'selection_end': 0, 'selection_start': 0}, - loc('unknown: #7'): {'attrib-starts': [], + loc('unknown: #237'): {'attrib-starts': [], + 'first-line': 0, + 'history': {}, + 'sel-line': 0, + 'sel-line-start': 0, + 'selection_end': 0, + 'selection_start': 0}, + loc('unknown: #244'): {'attrib-starts': [], 'first-line': 0, 'history': {}, 'sel-line': 0, 'sel-line-start': 0, 'selection_end': 0, 'selection_start': 0}, - loc('unknown: #5'): {'attrib-starts': [], + loc('unknown: #239'): {'attrib-starts': [], 'first-line': 0, 'history': {}, 'sel-line': 0, 'sel-line-start': 0, 'selection_end': 0, 'selection_start': 0}, - loc('unknown: #4'): {'attrib-starts': [], + loc('unknown: #242'): {'attrib-starts': [], 'first-line': 0, 'history': {}, 'sel-line': 0, 'sel-line-start': 0, 'selection_end': 0, 'selection_start': 0}, - loc('unknown: #2'): {'attrib-starts': [], + loc('unknown: #241'): {'attrib-starts': [], 'first-line': 0, 'history': {}, 'sel-line': 0, 'sel-line-start': 0, 'selection_end': 0, 'selection_start': 0}, - loc('unknown: #3'): {'attrib-starts': [], + loc('unknown: #240'): {'attrib-starts': [], 'first-line': 0, 'history': {}, 'sel-line': 0, 'sel-line-start': 0, 'selection_end': 0, 'selection_start': 0}, - loc('unknown: #6'): {'attrib-starts': [], + loc('unknown: #243'): {'attrib-starts': [], 'first-line': 0, 'history': {}, 'sel-line': 0, @@ -639,5 +647,6 @@ proj.env-vars = {None: ('default', [''])} proj.revision-control = 1 proj.revision-control-system = u'svn' -search.search-history = [u'getRandomFortune', +search.search-history = [u'fortune_file', + u'getRandomFortune', u'argParser'] diff --git a/fortune/__init__.py b/fortune/__init__.py index 612c7bc..95f5a77 100644 --- a/fortune/__init__.py +++ b/fortune/__init__.py @@ -158,11 +158,11 @@ def get_random_fortune(fortune_file): :rtype: str :return: the random fortune """ - fortuneIndexFile = fortune_file + '.dat' - if not os.path.exists(fortuneIndexFile): - raise ValueError, 'Can\'t find file "%s"' % fortuneIndexFile + fortune_index_file = fortune_file + '.dat' + if not os.path.exists(fortune_index_file): + raise ValueError, 'Can\'t find file "%s"' % fortune_index_file - fortuneIndex = open(fortuneIndexFile) + fortuneIndex = open(fortune_index_file) data = pickle.load(fortuneIndex) fortuneIndex.close() randomRecord = random.randint(0, len(data) - 1) @@ -205,19 +205,19 @@ def make_fortune_data_file(fortune_file, quiet=False): quiet : bool If ``True``, don't display progress messages """ - fortuneIndexFile = fortune_file + '.dat' + fortune_index_file = fortune_file + '.dat' if not quiet: - print 'Updating "%s" from "%s"...' % (fortuneIndexFile, fortune_file) + print 'Updating "%s" from "%s"...' % (fortune_index_file, fortune_file) data = [] shortest = sys.maxint longest = 0 - for start, length, fortune in _readFortunes(open(fortune_file, 'rU')): + for start, length, fortune in _read_fortunes(open(fortune_file, 'rU')): data += [(start, length)] shortest = min(shortest, length) longest = max(longest, length) - fortuneIndex = open(fortuneIndexFile, 'wb') + fortuneIndex = open(fortune_index_file, 'wb') pickle.dump(data, fortuneIndex, _PICKLE_PROTOCOL) fortuneIndex.close()