Coverage for mtools.util.pattern : 49%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
rv = [] for item in data: if isinstance(item, unicode): item = item.encode('utf-8') elif isinstance(item, list): item = _decode_pattern_list(item) elif isinstance(item, dict): item = _decode_pattern_dict(item) rv.append(item)
rv = sorted(rv) return rv
value = 1 return _decode_pattern_dict(value)
value = _decode_pattern_list(value) value = _decode_pattern_dict(value) else:
""" converts JSON format (even mongo shell notation without quoted key names) to a query pattern """ # make valid JSON by wrapping field names in quotes # convert values to 1 where possible, to get rid of things like new Date(...)
# now convert to dictionary, converting unicode to ascii except ValueError: return None
s = '{d: {$gt: 2, $lt: 4}, b: {$gte: 3}, c: {$nin: [1, "foo", "bar"]}, "$or": [{a:1}, {b:1}] }' print json2pattern(s)
s = '{a: {$gt: 2, $lt: 4}, "b": {$nin: [1, 2, 3]}, "$or": [{a:1}, {b:1}] }' print json2pattern(s)
s = '{ a: 1, b: { c: 2, d: "text" }, e: "more test" }' print json2pattern(s)
s = '{ _id: ObjectId(\'528556616dde23324f233168\'), config: { _id: 2, host: "localhost:27017" }, ns: "local.oplog.rs" }' print json2pattern(s) |