@@ -40,6 +40,8 @@ static PyObject* DBRef = NULL;
4040static PyObject * RECompile = NULL ;
4141static PyObject * UUID = NULL ;
4242static PyObject * Timestamp = NULL ;
43+ static PyObject * MinKey = NULL ;
44+ static PyObject * MaxKey = NULL ;
4345static PyTypeObject * REType = NULL ;
4446
4547#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN )
@@ -272,6 +274,8 @@ static int _reload_python_objects(void) {
272274 _reload_object (& ObjectId , "pymongo.objectid" , "ObjectId" ) ||
273275 _reload_object (& DBRef , "pymongo.dbref" , "DBRef" ) ||
274276 _reload_object (& Timestamp , "pymongo.timestamp" , "Timestamp" ) ||
277+ _reload_object (& MinKey , "pymongo.min_key" , "MinKey" ) ||
278+ _reload_object (& MaxKey , "pymongo.max_key" , "MaxKey" ) ||
275279 _reload_object (& RECompile , "re" , "compile" )) {
276280 return 1 ;
277281 }
@@ -666,6 +670,12 @@ static int write_element_to_buffer(bson_buffer* buffer, int type_byte, PyObject*
666670 }
667671 * (buffer -> buffer + type_byte ) = 0x0B ;
668672 return 1 ;
673+ } else if (PyObject_IsInstance (value , MinKey )) {
674+ * (buffer -> buffer + type_byte ) = 0xFF ;
675+ return 1 ;
676+ } else if (PyObject_IsInstance (value , MaxKey )) {
677+ * (buffer -> buffer + type_byte ) = 0x7F ;
678+ return 1 ;
669679 } else if (first_attempt ) {
670680 /* Try reloading the modules and having one more go at it. */
671681 if (WARN (PyExc_RuntimeWarning , "couldn't encode - reloading python "
@@ -1518,6 +1528,16 @@ static PyObject* get_value(const char* buffer, int* position, int type,
15181528 * position += 8 ;
15191529 break ;
15201530 }
1531+ case -1 :
1532+ {
1533+ value = PyObject_CallFunctionObjArgs (MinKey , NULL );
1534+ break ;
1535+ }
1536+ case 127 :
1537+ {
1538+ value = PyObject_CallFunctionObjArgs (MaxKey , NULL );
1539+ break ;
1540+ }
15211541 default :
15221542 {
15231543 PyObject * InvalidDocument = _error ("InvalidDocument" );
0 commit comments