r22883 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22882‎ | r22883 | r22884 >
Date:14:56, 10 June 2007
Author:Mark Bergsma
Status:old
Tags:
Comment:
Cleaner handling of filters
Modified paths:
  • /trunk/wmfmailadmin/wmfmailadmin.py (modified) (history)

Diff [purge]

Index: trunk/wmfmailadmin/wmfmailadmin.py
@@ -28,7 +28,7 @@
2929 'i': ('id', "Id", None, None),
3030 'q': ('quota', "Quota", 2**30/1024, None),
3131 'a': ('active', "Active", True, None),
32 - 'f': ('filter', "Filter", None, None)
 32+ 'f': ('filter', "Filter", None, "Filter file or '-' for stdin")
3333 }
3434 longmappings = {}
3535
@@ -37,6 +37,8 @@
3838
3939 supported_hash_algorithms = ('{SHA1}')
4040
 41+max_filter_size = 4096
 42+
4143 def list_accounts(fields):
4244 """
4345 List accounts in the database
@@ -171,11 +173,14 @@
172174 cur = conn.cursor()
173175 cur.execute("SELECT " + field + " FROM account WHERE " + where_clause, fields)
174176
175 - value = cur.fetchone()[0]
176 - if value is not None:
177 - print value
178 - else:
179 - print >> sys.stderr, "(NULL)"
 177+ try:
 178+ value = cur.fetchone()[0]
 179+ if value is not None:
 180+ print value
 181+ else:
 182+ print >> sys.stderr, "(NULL)"
 183+ except:
 184+ print >> sys.stderr, "(No rows returned)"
180185
181186 def require_fields(required_fields, fields):
182187 """
@@ -222,6 +227,8 @@
223228 Reads a filter from a file into fields['filter'] (overwriting)
224229 """
225230
 231+ global max_filter_size
 232+
226233 if fields['filter'] == "": return
227234
228235 if fields['filter'] == '-':
@@ -232,7 +239,10 @@
233240 except IOError, e:
234241 raise Exception("Could not open filter file %s: %e" % (fields['filter'], e.message))
235242
236 - fields['filter'] = filterfile.read(4096)
 243+ fields['filter'] = filterfile.read(max_filter_size)
 244+
 245+ if len(fields['filter']) == max_filter_size and filterfile.read(1):
 246+ print >> sys.stderr, "Warning: filter truncated at %d bytes!" % max_filter_size
237247
238248 def add_index(dct, fieldindex):
239249 """

Status & tagging log