當前位置: 首頁>>代碼示例>>Python>>正文


Python son.RE_TYPE屬性代碼示例

本文整理匯總了Python中bson.son.RE_TYPE屬性的典型用法代碼示例。如果您正苦於以下問題:Python son.RE_TYPE屬性的具體用法?Python son.RE_TYPE怎麽用?Python son.RE_TYPE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在bson.son的用法示例。


在下文中一共展示了son.RE_TYPE屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: from_native

# 需要導入模塊: from bson import son [as 別名]
# 或者: from bson.son import RE_TYPE [as 別名]
def from_native(cls, regex):
        """Convert a Python regular expression into a ``Regex`` instance.

        Note that in Python 3, a regular expression compiled from a
        :class:`str` has the ``re.UNICODE`` flag set. If it is undesirable
        to store this flag in a BSON regular expression, unset it first::

          >>> pattern = re.compile('.*')
          >>> regex = Regex.from_native(pattern)
          >>> regex.flags ^= re.UNICODE
          >>> db.collection.insert({'pattern': regex})

        :Parameters:
          - `regex`: A regular expression object from ``re.compile()``.

        .. warning::
           Python regular expressions use a different syntax and different
           set of flags than MongoDB, which uses `PCRE`_. A regular
           expression retrieved from the server may not compile in
           Python, or may match a different set of strings in Python than
           when used in a MongoDB query.

        .. _PCRE: http://www.pcre.org/
        """
        if not isinstance(regex, RE_TYPE):
            raise TypeError(
                "regex must be a compiled regular expression, not %s"
                % type(regex))

        return Regex(regex.pattern, regex.flags) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:32,代碼來源:regex.py


注:本文中的bson.son.RE_TYPE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。