File: dictdlib.txt

package info (click to toggle)
dictdlib 2.0.3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 440 kB
  • ctags: 68
  • sloc: python: 213; makefile: 118
file content (233 lines) | stat: -rw-r--r-- 9,346 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
Python Library Documentation: module dictdlib

NAME
    dictdlib

FILE
    /home/jgoerzen/tree/dictdlib/dictdlib.py

DESCRIPTION
    # Dictionary creation library
    # Copyright (C) 2002 John Goerzen
    # <jgoerzen@complete.org>
    #
    #    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
    #    the Free Software Foundation; either version 2 of the License, or
    #    (at your option) any later version.
    #
    #    This program is distributed in the hope that it will be useful,
    #    but WITHOUT ANY WARRANTY; without even the implied warranty of
    #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #    GNU General Public License for more details.
    #
    #    You should have received a copy of the GNU General Public License
    #    along with this program; if not, write to the Free Software
    #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

CLASSES
    DictDB
    DictReader
    DictWriter
    
    class DictDB
     |  Methods defined here:
     |  
     |  __init__(self, basename, mode='read', quiet=0)
     |      Initialize a DictDB object.
     |      
     |      Mode must be one of:
     |      
     |      read -- read-only access
     |      
     |      write -- write-only access, truncates existing files, does not work
     |      with .dz.  dict created if nonexistant.
     |      
     |      update -- read/write access, dict created if nonexistant.  Does not
     |      work with .dz.
     |      
     |      Read can read dict or dict.dz files.  Write and update will NOT work
     |      with dict.dz files.
     |      
     |      If quiet is nonzero, status messages
     |      will be suppressed.
     |  
     |  _initindex(self)
     |      Load the entire index off disk into memory.
     |  
     |  addentry(self, defstr, headwords)
     |      Writes an entry.  defstr holds the content of the definition.
     |      headwords is a list specifying one or more words under which this
     |      definition should be indexed.  This function always adds \n
     |      to the end of defstr.
     |  
     |  addindexentry(self, word, start, size)
     |      Adds an entry to the index.  word is the relevant word.
     |      start is the starting position in the dictionary and size is the
     |      size of the definition; both are integers.
     |  
     |  delindexentry(self, word, start=None, size=None)
     |      Removes an entry from the index; word is the word to search for.
     |      
     |      start and size are optional.  If they are specified, only index
     |      entries matching the specified values will be removed.
     |      
     |      For instance, if word is "foo" and start and size are not specified,
     |      all index entries for the word foo will be removed.  If start and size
     |      are specified, only those entries matching all criteria will be
     |      removed.
     |      
     |      This function does not actually remove the data from the .dict file.
     |      Therefore, information removed by this function will still
     |      exist on-disk in the .dict file, but the dict server will just
     |      not "see" it -- there will be no way to get to it anymore.
     |      
     |      Returns a count of the deleted entries.
     |  
     |  finish(self, dosort=1)
     |      Called to finish the writing process.
     |      **REQUIRED IF OPENED WITH 'update' OR 'write' MODES**.
     |      This will write the index and close the files.
     |      
     |      dosort is optional and defaults to true.  If set to false,
     |      dictlib will not sort the index file.  In this case, you
     |      MUST manually sort it through "sort -df" before it can be used.
     |  
     |  getdef(self, word)
     |      Given a definition name, returns a list of strings with all
     |      matching definitions.  This is an *exact* match, not a
     |      case-insensitive one.  Returns [] if word is not in the dictionary.
     |  
     |  getdeflist(self)
     |      Returns a list of strings naming all definitions contained
     |      in this dictionary.
     |  
     |  hasdef(self, word)
     |  
     |  setlonginfo(self, longinfo)
     |      Sets the extended information for this database.  If there was
     |      already long info specified, we will use delindexentry() on it
     |      first.
     |  
     |  setshortname(self, shortname)
     |      Sets the shortname for this database.  If there was already
     |      a shortname specified, we will use delindexentry() on it first.
     |  
     |  seturl(self, url)
     |      Sets the URL attribute of this database.  If there was
     |      already a URL specified, we will use delindexentry() on it
     |      first.
     |  
     |  update(self, string)
     |      Writes string out, if not quiet.
     |  
     |  ----------------------------------------------------------------------
     |  Data and non-method functions defined here:
     |  
     |  __doc__ = None
     |  
     |  __module__ = 'dictdlib'
     |      str(object) -> string
     |      
     |      Return a nice string representation of the object.
     |      If the argument is a string, the return value is the same object.
    
    class DictReader
     |  This object provides compatibility with earlier versions
     |  of dictdlib.  It is now deprecated.
     |  
     |  Methods defined here:
     |  
     |  __init__(self, basename)
     |      Initialize a DictReader object.  Provide it with the basename.
     |  
     |  getdef(self, defname)
     |      Given a definition name, returns a list of strings
     |      with all matching definitions.
     |  
     |  getdeflist(self)
     |      Returns a list of strings naming all definitions contained
     |      in this dictionary.
     |  
     |  ----------------------------------------------------------------------
     |  Data and non-method functions defined here:
     |  
     |  __doc__ = 'This object provides compatibility with earlier versions\n ...
     |      str(object) -> string
     |      
     |      Return a nice string representation of the object.
     |      If the argument is a string, the return value is the same object.
     |  
     |  __module__ = 'dictdlib'
     |      str(object) -> string
     |      
     |      Return a nice string representation of the object.
     |      If the argument is a string, the return value is the same object.
    
    class DictWriter
     |  This object provides compatibility with earlier versions
     |  of dictdlib.  It is now deprecated.
     |  
     |  Methods defined here:
     |  
     |  __init__(self, basename, url='unknown', shortname='unknown', longinfo='unknown', quiet=0)
     |      Initialize a DictWriter object.  Will create 'basename.dict' and
     |      'basename.index' files.  url, shortname, and longinfo specify the
     |      respective attributes of the database.  If quiet is 1,
     |      status messages are not printed.
     |  
     |  finish(self, dosort=1)
     |      Called to finish the writing process.  **REQUIRED**.
     |      This will write the index and close the files.
     |      
     |      dosort is optional and defaults to true.  If set to false,
     |      dictlib will not sort the index file.  In this case, you
     |      MUST manually sort it through "sort -df" before it can be used.
     |  
     |  writeentry(self, defstr, headwords)
     |      Writes an entry.  defstr holds the content of the definition.
     |      headwords is a list specifying one or more words under which this
     |      definition should be indexed.  This function always adds \n
     |      to the end of defstr.
     |  
     |  ----------------------------------------------------------------------
     |  Data and non-method functions defined here:
     |  
     |  __doc__ = 'This object provides compatibility with earlier versions\n ...
     |      str(object) -> string
     |      
     |      Return a nice string representation of the object.
     |      If the argument is a string, the return value is the same object.
     |  
     |  __module__ = 'dictdlib'
     |      str(object) -> string
     |      
     |      Return a nice string representation of the object.
     |      If the argument is a string, the return value is the same object.

FUNCTIONS
    b64_decode(str)
        Takes as input a string and returns an integer value of it decoded
        with the base64 algorithm used by dict indexes.
    
    b64_encode(val)
        Takes as input an integer val and returns a string of it encoded
        with the base64 algorithm used by dict indexes.
    
    sortfunc(x, y)
        Emulate sort -df.
    
    sortnormalize(x)
        Returns a value such that x is mapped to a format that sorts properly
        with standard comparison.

DATA
    __file__ = './dictdlib.py'
    __name__ = 'dictdlib'
    b64_list = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345...
    info_headword = '00-database-info'
    short_headword = '00-database-short'
    url_headword = '00-database-url'
    validdict = {'\t': 1, ' ': 1, '0': 1, '1': 1, '2': 1, '3': 1, '4': 1, ...
    x = '\t'