Revision 320e34df lib/query.py
b/lib/query.py | ||
---|---|---|
766 | 766 |
(utils.CommaJoin(errors), row)) |
767 | 767 |
|
768 | 768 |
|
769 |
def _FieldDictKey((fdef, _, flags, fn)): |
|
770 |
"""Generates key for field dictionary. |
|
771 |
|
|
772 |
""" |
|
773 |
assert fdef.name and fdef.title, "Name and title are required" |
|
774 |
assert FIELD_NAME_RE.match(fdef.name) |
|
775 |
assert TITLE_RE.match(fdef.title) |
|
776 |
assert (DOC_RE.match(fdef.doc) and len(fdef.doc.splitlines()) == 1 and |
|
777 |
fdef.doc.strip() == fdef.doc), \ |
|
778 |
"Invalid description for field '%s'" % fdef.name |
|
779 |
assert callable(fn) |
|
780 |
assert (flags & ~QFF_ALL) == 0, "Unknown flags for field '%s'" % fdef.name |
|
781 |
|
|
782 |
return fdef.name |
|
783 |
|
|
784 |
|
|
769 | 785 |
def _PrepareFieldList(fields, aliases): |
770 | 786 |
"""Prepares field list for use by L{Query}. |
771 | 787 |
|
... | ... | |
787 | 803 |
for (fdef, _, _, _) in fields) |
788 | 804 |
assert not duplicates, "Duplicate title(s) found: %r" % duplicates |
789 | 805 |
|
790 |
result = {} |
|
791 |
|
|
792 |
for field in fields: |
|
793 |
(fdef, _, flags, fn) = field |
|
794 |
|
|
795 |
assert fdef.name and fdef.title, "Name and title are required" |
|
796 |
assert FIELD_NAME_RE.match(fdef.name) |
|
797 |
assert TITLE_RE.match(fdef.title) |
|
798 |
assert (DOC_RE.match(fdef.doc) and len(fdef.doc.splitlines()) == 1 and |
|
799 |
fdef.doc.strip() == fdef.doc), \ |
|
800 |
"Invalid description for field '%s'" % fdef.name |
|
801 |
assert callable(fn) |
|
802 |
assert fdef.name not in result, \ |
|
803 |
"Duplicate field name '%s' found" % fdef.name |
|
804 |
assert (flags & ~QFF_ALL) == 0, "Unknown flags for field '%s'" % fdef.name |
|
805 |
|
|
806 |
result[fdef.name] = field |
|
806 |
result = utils.SequenceToDict(fields, key=_FieldDictKey) |
|
807 | 807 |
|
808 | 808 |
for alias, target in aliases: |
809 | 809 |
assert alias not in result, "Alias %s overrides an existing field" % alias |
Also available in: Unified diff