<s> from . objects import MongoDBCollection <EOL> from ... metadata import * <EOL> from ... errors import * <EOL> from ... prototypes import * <EOL> from ... objects import * <EOL> def prepare_mongo_key ( key ) : <EOL> key = prepare_key ( key ) <EOL> return { name : <NUM_LIT:1> for name in key } <EOL> @ field_filter . register ( "<STR_LIT>" ) <EOL> def _ ( ctx , obj , keep = None , drop = None , rename = None , filter = None ) : <EOL> if rename : <EOL> raise NotImplementedError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if filter : <EOL> if keep or drop or rename : <EOL> raise OperationError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> field_filter = filter <EOL> else : <EOL> field_filter = FieldFilter ( keep = keep , drop = drop , rename = rename ) <EOL> new_fields = field_filter . filter ( obj . fields ) <EOL> return obj . clone ( fields = new_fields ) <EOL> @ distinct . register ( "<STR_LIT>" ) <EOL> def _ ( ctx , obj , key = None ) : <EOL> if not key : <EOL> key = obj . fields . names ( ) <EOL> key = prepare_mongo_key ( key ) <EOL> new_fields = obj . fields . fields ( key ) <EOL> cursor = obj . collection . group ( key , { } , { } , "<STR_LIT>" ) <EOL> return IterableRecordsDataSource ( cursor , new_fields ) </s>
