Python sets 模块,BaseSet() 实例源码

我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用sets.BaseSet()

项目:true_review_web2py    作者:lucadealfaro    | 项目源码 | 文件源码
def escape_item(val, charset):
    if type(val) in [tuple, list, set]:
        return escape_sequence(val, charset)
    if type(val) is dict:
        return escape_dict(val, charset)
    if PYTHON3 and hasattr(val, "decode") and not isinstance(val, unicode):
        # deal with py3k bytes
        val = val.decode(charset)
    encoder = encoders[type(val)]
    val = encoder(val)
    if type(val) in [str, int]:
        return val
    val = val.encode(charset)
    return val
项目:true_review_web2py    作者:lucadealfaro    | 项目源码 | 文件源码
def convert_time(connection, field, obj):
    """Returns a TIME column as a time object:

      >>> time_or_None('15:06:17')
      datetime.time(15, 6, 17)

    Illegal values are returned as None:

      >>> time_or_None('-25:06:17') is None
      True
      >>> time_or_None('random crap') is None
      True

    Note that MySQL always returns TIME columns as (+|-)HH:MM:SS, but
    can accept values as (+|-)DD HH:MM:SS. The latter format will not
    be parsed correctly by this function.

    Also note that MySQL's TIME column corresponds more closely to
    Python's timedelta and not time. However if you want TIME columns
    to be treated as time-of-day and not a time offset, then you can
    use set this function as the converter for FIELD_TYPE.TIME.
    """
    try:
        microseconds = 0
        if "." in obj:
            (obj, tail) = obj.split('.')
            microseconds = int(tail)
        hours, minutes, seconds = obj.split(':')
        return datetime.time(hour=int(hours), minute=int(minutes),
                             second=int(seconds), microsecond=microseconds)
    except ValueError:
        return None
项目:true_review_web2py    作者:lucadealfaro    | 项目源码 | 文件源码
def convert_set(s):
    return set(s.split(","))
项目:true_review_web2py    作者:lucadealfaro    | 项目源码 | 文件源码
def __ne__(self, other):
        if isinstance(other, set):
            return super(DBAPISet, self).__ne__(self, other)
        else:
            return other not in self
项目:spc    作者:whbrewer    | 项目源码 | 文件源码
def escape_item(val, charset):
    if type(val) in [tuple, list, set]:
        return escape_sequence(val, charset)
    if type(val) is dict:
        return escape_dict(val, charset)
    if PYTHON3 and hasattr(val, "decode") and not isinstance(val, unicode):
        # deal with py3k bytes
        val = val.decode(charset)
    encoder = encoders[type(val)]
    val = encoder(val)
    if type(val) in [str, int]:
        return val
    val = val.encode(charset)
    return val
项目:spc    作者:whbrewer    | 项目源码 | 文件源码
def convert_time(connection, field, obj):
    """Returns a TIME column as a time object:

      >>> time_or_None('15:06:17')
      datetime.time(15, 6, 17)

    Illegal values are returned as None:

      >>> time_or_None('-25:06:17') is None
      True
      >>> time_or_None('random crap') is None
      True

    Note that MySQL always returns TIME columns as (+|-)HH:MM:SS, but
    can accept values as (+|-)DD HH:MM:SS. The latter format will not
    be parsed correctly by this function.

    Also note that MySQL's TIME column corresponds more closely to
    Python's timedelta and not time. However if you want TIME columns
    to be treated as time-of-day and not a time offset, then you can
    use set this function as the converter for FIELD_TYPE.TIME.
    """
    try:
        microseconds = 0
        if "." in obj:
            (obj, tail) = obj.split('.')
            microseconds = int(tail)
        hours, minutes, seconds = obj.split(':')
        return datetime.time(hour=int(hours), minute=int(minutes),
                             second=int(seconds), microsecond=microseconds)
    except ValueError:
        return None
项目:spc    作者:whbrewer    | 项目源码 | 文件源码
def convert_set(s):
    return set(s.split(","))
项目:spc    作者:whbrewer    | 项目源码 | 文件源码
def __ne__(self, other):
        if isinstance(other, set):
            return super(DBAPISet, self).__ne__(self, other)
        else:
            return other not in self
项目:Problematica-public    作者:TechMaz    | 项目源码 | 文件源码
def escape_item(val, charset):
    if type(val) in [tuple, list, set]:
        return escape_sequence(val, charset)
    if type(val) is dict:
        return escape_dict(val, charset)
    if PYTHON3 and hasattr(val, "decode") and not isinstance(val, unicode):
        # deal with py3k bytes
        val = val.decode(charset)
    encoder = encoders[type(val)]
    val = encoder(val)
    if type(val) in [str, int]:
        return val
    val = val.encode(charset)
    return val
项目:Problematica-public    作者:TechMaz    | 项目源码 | 文件源码
def convert_time(connection, field, obj):
    """Returns a TIME column as a time object:

      >>> time_or_None('15:06:17')
      datetime.time(15, 6, 17)

    Illegal values are returned as None:

      >>> time_or_None('-25:06:17') is None
      True
      >>> time_or_None('random crap') is None
      True

    Note that MySQL always returns TIME columns as (+|-)HH:MM:SS, but
    can accept values as (+|-)DD HH:MM:SS. The latter format will not
    be parsed correctly by this function.

    Also note that MySQL's TIME column corresponds more closely to
    Python's timedelta and not time. However if you want TIME columns
    to be treated as time-of-day and not a time offset, then you can
    use set this function as the converter for FIELD_TYPE.TIME.
    """
    try:
        microseconds = 0
        if "." in obj:
            (obj, tail) = obj.split('.')
            microseconds = int(tail)
        hours, minutes, seconds = obj.split(':')
        return datetime.time(hour=int(hours), minute=int(minutes),
                             second=int(seconds), microsecond=microseconds)
    except ValueError:
        return None
项目:Problematica-public    作者:TechMaz    | 项目源码 | 文件源码
def convert_set(s):
    return set(s.split(","))
项目:Problematica-public    作者:TechMaz    | 项目源码 | 文件源码
def __ne__(self, other):
        if isinstance(other, set):
            return super(DBAPISet, self).__ne__(self, other)
        else:
            return other not in self
项目:slugiot-client    作者:slugiot    | 项目源码 | 文件源码
def escape_item(val, charset):
    if type(val) in [tuple, list, set]:
        return escape_sequence(val, charset)
    if type(val) is dict:
        return escape_dict(val, charset)
    if PYTHON3 and hasattr(val, "decode") and not isinstance(val, unicode):
        # deal with py3k bytes
        val = val.decode(charset)
    encoder = encoders[type(val)]
    val = encoder(val)
    if type(val) in [str, int]:
        return val
    val = val.encode(charset)
    return val
项目:slugiot-client    作者:slugiot    | 项目源码 | 文件源码
def convert_time(connection, field, obj):
    """Returns a TIME column as a time object:

      >>> time_or_None('15:06:17')
      datetime.time(15, 6, 17)

    Illegal values are returned as None:

      >>> time_or_None('-25:06:17') is None
      True
      >>> time_or_None('random crap') is None
      True

    Note that MySQL always returns TIME columns as (+|-)HH:MM:SS, but
    can accept values as (+|-)DD HH:MM:SS. The latter format will not
    be parsed correctly by this function.

    Also note that MySQL's TIME column corresponds more closely to
    Python's timedelta and not time. However if you want TIME columns
    to be treated as time-of-day and not a time offset, then you can
    use set this function as the converter for FIELD_TYPE.TIME.
    """
    try:
        microseconds = 0
        if "." in obj:
            (obj, tail) = obj.split('.')
            microseconds = int(tail)
        hours, minutes, seconds = obj.split(':')
        return datetime.time(hour=int(hours), minute=int(minutes),
                             second=int(seconds), microsecond=microseconds)
    except ValueError:
        return None
项目:slugiot-client    作者:slugiot    | 项目源码 | 文件源码
def convert_set(s):
    return set(s.split(","))
项目:slugiot-client    作者:slugiot    | 项目源码 | 文件源码
def __ne__(self, other):
        if isinstance(other, set):
            return super(DBAPISet, self).__ne__(self, other)
        else:
            return other not in self
项目:StuffShare    作者:StuffShare    | 项目源码 | 文件源码
def escape_item(val, charset):
    if type(val) in [tuple, list, set]:
        return escape_sequence(val, charset)
    if type(val) is dict:
        return escape_dict(val, charset)
    if PYTHON3 and hasattr(val, "decode") and not isinstance(val, unicode):
        # deal with py3k bytes
        val = val.decode(charset)
    encoder = encoders[type(val)]
    val = encoder(val)
    if type(val) in [str, int]:
        return val
    val = val.encode(charset)
    return val
项目:StuffShare    作者:StuffShare    | 项目源码 | 文件源码
def convert_time(connection, field, obj):
    """Returns a TIME column as a time object:

      >>> time_or_None('15:06:17')
      datetime.time(15, 6, 17)

    Illegal values are returned as None:

      >>> time_or_None('-25:06:17') is None
      True
      >>> time_or_None('random crap') is None
      True

    Note that MySQL always returns TIME columns as (+|-)HH:MM:SS, but
    can accept values as (+|-)DD HH:MM:SS. The latter format will not
    be parsed correctly by this function.

    Also note that MySQL's TIME column corresponds more closely to
    Python's timedelta and not time. However if you want TIME columns
    to be treated as time-of-day and not a time offset, then you can
    use set this function as the converter for FIELD_TYPE.TIME.
    """
    try:
        microseconds = 0
        if "." in obj:
            (obj, tail) = obj.split('.')
            microseconds = int(tail)
        hours, minutes, seconds = obj.split(':')
        return datetime.time(hour=int(hours), minute=int(minutes),
                             second=int(seconds), microsecond=microseconds)
    except ValueError:
        return None
项目:StuffShare    作者:StuffShare    | 项目源码 | 文件源码
def convert_set(s):
    return set(s.split(","))
项目:StuffShare    作者:StuffShare    | 项目源码 | 文件源码
def __ne__(self, other):
        if isinstance(other, set):
            return super(DBAPISet, self).__ne__(self, other)
        else:
            return other not in self