我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用sets.BaseSet()。
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
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
def convert_set(s): return set(s.split(","))
def __ne__(self, other): if isinstance(other, set): return super(DBAPISet, self).__ne__(self, other) else: return other not in self