| 153 | |
| 154 | |
| 155 | def sanitize_cmd(cmd): |
| 156 | cp = cmd.copy() |
| 157 | cp.pop("$clusterTime", None) |
| 158 | cp.pop("$db", None) |
| 159 | cp.pop("$readPreference", None) |
| 160 | cp.pop("lsid", None) |
| 161 | if MONGODB_API_VERSION: |
| 162 | # Stable API parameters |
| 163 | cp.pop("apiVersion", None) |
| 164 | # OP_MSG encoding may move the payload type one field to the |
| 165 | # end of the command. Do the same here. |
| 166 | name = next(iter(cp)) |
| 167 | try: |
| 168 | identifier = message._FIELD_MAP[name] |
| 169 | docs = cp.pop(identifier) |
| 170 | cp[identifier] = docs |
| 171 | except KeyError: |
| 172 | pass |
| 173 | return cp |
| 174 | |
| 175 | |
| 176 | def sanitize_reply(reply): |