本文整理汇总了Python中enum.unique方法的典型用法代码示例。如果您正苦于以下问题:Python enum.unique方法的具体用法?Python enum.unique怎么用?Python enum.unique使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类enum
的用法示例。
在下文中一共展示了enum.unique方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: filter_input
# 需要导入模块: import enum [as 别名]
# 或者: from enum import unique [as 别名]
def filter_input(text: str):
if text is None:
return None
filtered = text
urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',
text)
# Replace all URLS with a unique token
url_token = 'URL%s' % random.getrandbits(64)
for url in urls:
filtered = filtered.replace(url, url_token)
filtered = re.sub(r'(&)', '', filtered)
filtered = re.sub(r'[,:;\'`\-_“^"<>(){}/\\*]', '', filtered)
# Swamp URLs back for token
for url in urls:
filtered = filtered.replace(url_token, url)
return filtered
示例2: collect_labels
# 需要导入模块: import enum [as 别名]
# 或者: from enum import unique [as 别名]
def collect_labels(y: Any) -> List[str]:
"""
Collect the unique labels in the given target variable, which could be in
multiclass or multilabel format.
Args:
y: Target variable
Returns:
An ordered list of all labels in y.
"""
if is_multilabel(y):
label_set: Set[str] = set()
for labels in y:
label_set.update(labels)
else:
label_set = set(y)
return list(sorted(label_set))
示例3: _set_docstring
# 需要导入模块: import enum [as 别名]
# 或者: from enum import unique [as 别名]
def _set_docstring(self):
self.__doc__ = "Match key fields for table '{}':\n\n".format(self._table_name)
for name, info in self._fields.items():
self.__doc__ += str(info)
self.__doc__ += """
Set a field value with <self>['<field_name>'] = '...'
* For exact match: <self>['<f>'] = '<value>'
* For ternary match: <self>['<f>'] = '<value>&&&<mask>'
* For LPM match: <self>['<f>'] = '<value>/<mask>'
* For range match: <self>['<f>'] = '<value>..<mask>'
If it's inconvenient to use the whole field name, you can use a unique suffix.
You may also use <self>.set(<f>='<value>')
\t(<f> must not include a '.' in this case, but remember that you can use a unique suffix)
"""
示例4: ensure_index
# 需要导入模块: import enum [as 别名]
# 或者: from enum import unique [as 别名]
def ensure_index(cls):
collection = cls.collection()
collection.create_index(
[
("execution_id", generic.SORT_ASC),
("task_type", generic.SORT_ASC)
],
name="index_execution_id",
unique=True
)
collection.create_index(
[
("time.created", generic.SORT_ASC),
("time.started", generic.SORT_ASC),
("time.completed", generic.SORT_ASC),
("time.cancelled", generic.SORT_ASC),
("time.failed", generic.SORT_ASC)
],
name="index_time"
)
collection.create_index(
TTL_FIELDNAME,
expireAfterSeconds=0,
name="index_task_ttl"
)
示例5: __init__
# 需要导入模块: import enum [as 别名]
# 或者: from enum import unique [as 别名]
def __init__(self, key, ordering):
"""Initialize Board Permission.
:param key: unique identifier, used in database
:param ordering: relative level of permissiveness (lower is less permissive)
"""
self.key = key
self.ordering = ordering
示例6: member_of
# 需要导入模块: import enum [as 别名]
# 或者: from enum import unique [as 别名]
def member_of(obj, arg):
if isinstance(arg, enum.Enum):
enum.unique(obj) # check that enum has unique values
arg = arg.name
if not hasattr(obj, arg):
raise com.IbisTypeError(
'Value with type {} is not a member of {}'.format(type(arg), obj)
)
return getattr(obj, arg)
示例7: show_scale_warnings
# 需要导入模块: import enum [as 别名]
# 或者: from enum import unique [as 别名]
def show_scale_warnings(self, desired_num):
if self.custom_container_name and desired_num > 1:
log.warn('The "%s" service is using the custom container name "%s". '
'Docker requires each container to have a unique name. '
'Remove the custom name to scale the service.'
% (self.name, self.custom_container_name))
if self.specifies_host_port() and desired_num > 1:
log.warn('The "%s" service specifies a port on the host. If multiple containers '
'for this service are created on a single host, the port will clash.'
% self.name)
示例8: __init__
# 需要导入模块: import enum [as 别名]
# 或者: from enum import unique [as 别名]
def __init__(self, name, type_, class_):
self.key = name.lower()
self.name = name
self.type = type_
self.class_ = class_ & _CLASS_MASK
self.unique = (class_ & _CLASS_UNIQUE) != 0
示例9: to_string
# 需要导入模块: import enum [as 别名]
# 或者: from enum import unique [as 别名]
def to_string(self, hdr, other):
"""String representation with additional information"""
result = "%s[%s,%s" % (hdr, self.get_type(self.type),
self.get_class_(self.class_))
if self.unique:
result += "-unique,"
else:
result += ","
result += self.name
if other is not None:
result += ",%s]" % other
else:
result += "]"
return result
示例10: write_record
# 需要导入模块: import enum [as 别名]
# 或者: from enum import unique [as 别名]
def write_record(self, record, now):
"""Writes a record (answer, authoritative answer, additional) to
the packet"""
if self.state == self.State.finished:
return 1
start_data_length, start_size = len(self.data), self.size
self.write_name(record.name)
self.write_short(record.type)
if record.unique and self.multicast:
self.write_short(record.class_ | _CLASS_UNIQUE)
else:
self.write_short(record.class_)
if now == 0:
self.write_int(record.ttl)
else:
self.write_int(record.get_remaining_ttl(now))
index = len(self.data)
# Adjust size for the short we will write before this record
self.size += 2
record.write(self)
self.size -= 2
length = sum((len(d) for d in self.data[index:]))
# Here is the short we adjusted for
self.insert_short(index, length)
# if we go over, then rollback and quit
if self.size > _MAX_MSG_ABSOLUTE:
while len(self.data) > start_data_length:
self.data.pop()
self.size = start_size
self.state = self.State.finished
return 1
return 0
示例11: multilabel_to_indicator_df
# 需要导入模块: import enum [as 别名]
# 或者: from enum import unique [as 别名]
def multilabel_to_indicator_df(y: List[List[str]], labels: List[str]) -> pd.DataFrame:
"""
Convert a list of label lists to a 0/1 indicator dataframe.
Args:
y: List of label lists
labels: List of all unique labels found in y
Returns:
The dataframe will have a column for each label and a row for each observation,
with a 1 if the observation has that label or a 0 if not.
"""
mlb = MultiLabelBinarizer(classes=labels)
return pd.DataFrame(mlb.fit_transform(y), columns=mlb.classes_)
示例12: generate_uuid
# 需要导入模块: import enum [as 别名]
# 或者: from enum import unique [as 别名]
def generate_uuid() -> str:
"""
Generate a universally unique ID to be used for randomly naming directories,
models, tasks, etc.
"""
return uuid.uuid4().hex
示例13: labels
# 需要导入模块: import enum [as 别名]
# 或者: from enum import unique [as 别名]
def labels(self) -> List[str]:
"""
Returns:
The set of unique labels in the data.
Sort and return a list for consistent ordering, in case that matters.
"""
# We verify these types are compatible during initialization, so ignore
# mypy warning about a possible mismatch due to the Union
return collect_labels(self.y_train + self.y_valid) # type: ignore
示例14: unique_id
# 需要导入模块: import enum [as 别名]
# 或者: from enum import unique [as 别名]
def unique_id(self):
"""
Returns a unique ID for this derived image.
This call will consistently produce the same unique ID across calls in the same code base.
"""
return hashlib.sha256(("%s:%s" % (self.verb, self._db_id)).encode("utf-8")).hexdigest()
示例15: __new__
# 需要导入模块: import enum [as 别名]
# 或者: from enum import unique [as 别名]
def __new__(mcs, cls, bases, classdict):
# check if the __new__ was invoked for StateMachine itself
try:
is_base_cls = StateMachine not in bases
except NameError:
is_base_cls = True
if not is_base_cls:
event_listeners = collections.defaultdict(list)
change_listeners = collections.defaultdict(list)
remove = set()
for name, value in classdict.items():
if hasattr(value, '_on_state'):
states = value._on_state
for state in states:
if isinstance(state, enum.Enum):
state = state.value
event_listeners[state].append(value)
remove.add(name)
if hasattr(value, '_on_transition'):
transitions = value._on_transition
for (current, next_state) in transitions:
if isinstance(current, enum.Enum):
current = current.value
if isinstance(next_state, enum.Enum):
next_state = next_state.value
change_listeners[(current, next_state)].append(value)
remove.add(name)
for name in remove:
del classdict[name]
classdict['__event_listeners__'] = dict(event_listeners)
classdict['__change_listeners__'] = dict(change_listeners)
obj = enum.unique(super().__new__(mcs, cls, bases, classdict))
if 0 not in obj._value2member_map_:
raise ValueError(f'No start state found in {obj!r}')
else:
obj = super().__new__(mcs, cls, bases, classdict)
return obj