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


Python enum.unique方法代碼示例

本文整理匯總了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 
開發者ID:csvance,項目名稱:armchair-expert,代碼行數:25,代碼來源:markov_engine.py

示例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)) 
開發者ID:RTIInternational,項目名稱:gobbli,代碼行數:21,代碼來源:util.py

示例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)
""" 
開發者ID:p4lang,項目名稱:p4runtime-shell,代碼行數:18,代碼來源:shell.py

示例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"
        ) 
開發者ID:Mirantis,項目名稱:ceph-lcm,代碼行數:27,代碼來源:task.py

示例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 
開發者ID:twschiller,項目名稱:open-synthesis,代碼行數:10,代碼來源:models.py

示例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) 
開發者ID:ibis-project,項目名稱:ibis,代碼行數:12,代碼來源:rules.py

示例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) 
開發者ID:QData,項目名稱:deepWordBug,代碼行數:13,代碼來源:service.py

示例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 
開發者ID:hexway,項目名稱:apple_bleee,代碼行數:8,代碼來源:zeroconf.py

示例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 
開發者ID:hexway,項目名稱:apple_bleee,代碼行數:16,代碼來源:zeroconf.py

示例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 
開發者ID:hexway,項目名稱:apple_bleee,代碼行數:38,代碼來源:zeroconf.py

示例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_) 
開發者ID:RTIInternational,項目名稱:gobbli,代碼行數:16,代碼來源:util.py

示例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 
開發者ID:RTIInternational,項目名稱:gobbli,代碼行數:8,代碼來源:util.py

示例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 
開發者ID:RTIInternational,項目名稱:gobbli,代碼行數:11,代碼來源:io.py

示例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() 
開發者ID:quay,項目名稱:quay,代碼行數:9,代碼來源:datatypes.py

示例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 
開發者ID:google,項目名稱:vulncode-db,代碼行數:40,代碼來源:statemachine.py


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