コード例 #1
0
 def __or__(self, other) -> Flag:
     if not isinstance(other, self.__class__):
         return NotImplemented
     self_components = _decompose(self.__class__, self._value_)[0]
     other_components = _decompose(self.__class__, other._value_)[0]
     self_primary = list(
         filter(lambda x: x in self._uncombinable, self_components))[:1][0]
     other_combinable = list(
         filter(lambda x: x not in self._uncombinable, other_components))
     usable_output = self_primary
     for val in other_combinable:
         usable_output = Flag.__or__(usable_output, val)
     usable_output._name_ = None if len(
         other_combinable) > 0 else usable_output._name_
     return usable_output
コード例 #2
0
    Counter,
    ByteString,
    ChainMap,
)
import collections as cl
from enum import Enum, Flag
from bourbaki.application.typed_io.config_decode import config_decoder


class SomeEnum(Enum):
    foo = 1
    bar = 2
    baz = 3


SomeFlag = Flag("SomeFlag", names="foo bar baz".split())


def same_value(a, b):
    assert a == b
    assert type(a) is type(b)


def same_contents(a, b):
    assert len(a) == len(b)
    assert type(a) is type(b)
    for a_, b_ in zip(a, b):
        same_value(a_, b_)


def same_keyvals(d, e):
コード例 #3
0
from enum import Flag

from botometer import Botometer, NoTimelineError

from twitter_cleanup.authentication import authentication

BotometerStatus = Flag("BotometerStatus", "PENDING READY UNAVAILABLE")


class BotometerResult:
    """Holds Botometer result and avoids repeating the request to their API"""
    def __init__(self):
        kwargs = authentication.botometer.copy()
        kwargs["wait_on_rate_limit"] = True
        self.botometer = Botometer(**kwargs)

        self.status = BotometerStatus.PENDING
        self._probability = None
        self.user_id = None

    def _get_result(self):
        try:
            result = self.botometer.check_account(self.user_id)
        except NoTimelineError:
            self.status = BotometerStatus.UNAVAILABLE
        else:
            self._probability = result.get("cap", {}).get("universal")
            self.status = BotometerStatus.READY

    @property
    def probability(self):
コード例 #4
0
ファイル: artefact.py プロジェクト: drmoose/faber
# Boost Software License, Version 1.0.
# (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt)

import asyncio
from enum import Enum, Flag, IntEnum
from os.path import dirname, lexists
from os import stat, makedirs, remove, rmdir
from collections import defaultdict
import logging

logger = logging.getLogger('scheduler')
summary_logger = logging.getLogger('summary')

flag = Flag('flag', 'NONE '
            'TEMP NOCARE NOTFILE TOUCHED '
            'LEAVES NOUPDATE XX RMOLD '
            'INTERNAL PRECIOUS NOPROPAGATE',
            start=0)
binding = Enum('binding', 'UNBOUND MISSING PARENTS EXISTS')
fate = IntEnum(
    'fate', 'INIT MAKING STABLE NEWER SPOIL '
    'ISTMP BUILD TOUCHED REBUILD MISSING NEEDTMP '
    'OUTDATED UPDATE BROKEN CANTFIND CANTMAKE')
progress = IntEnum('progress', 'INIT LAUNCHED BOUND RUNNING DONE NOEXEC_DONE')


def _cyclic(artefact, root=None):
    if root == artefact:
        yield True
    root = root or artefact
    for p in artefact.prerequisites:
コード例 #5
0
ファイル: inotify.py プロジェクト: pombredanne/trio-inotify
import trio
from enum import Flag
from pathlib import Path
from typing import Callable, Dict, List, NamedTuple, Type
from trio_inotify._inotify_bridge import (
    ffi as inotify_ffi,
    lib as inotify_lib,
    inotify_init,
    inotify_add_watch,
    inotify_rm_watch,
)
from trio_inotify._ioctl_c import lib as ioctl_lib

InotifyMasks = Flag(
    "InotifyMasks",
    [(mask_name, getattr(inotify_lib, mask_name))
     for mask_name in dir(inotify_lib) if mask_name.startswith("IN_")],
)


@attr.s(auto_attribs=True)
class WatchManager:
    """Add, remove and track watches on an inotify interface.
    """

    _watches: Dict[str, int] = attr.ib(init=False, default={})
    _rev_watches: Dict[int, str] = attr.ib(init=False, default={})
    recursive: bool = attr.ib(init=False, default=False)
    inotify_fd: int = attr.ib(init=False, default=inotify_init())
    inotify_event_flags: Type[InotifyMasks] = attr.ib(init=False,
                                                      default=InotifyMasks)
コード例 #6
0
 def __str__(self):
     if self.value == 0:
         return stubs['emptyAttrs']
     else:
         return Flag.__str__(self)[self.__class__.__name__.__len__() + 1:]
コード例 #7
0
 def flags(self) -> list:
     return Flag.__str__(self)[self.__class__.__name__.__len__() +
                               1:].split('|')
コード例 #8
0
# 2020-11-11 Antonio F. G. Sevilla <*****@*****.**>
# Licensed under the Open Software License version 3.0

from enum import Flag
import json
from pathlib import Path
from shutil import copyfile

Target = Flag('AnnotationTarget', 'LOGO GRAPH')


class Annotation:
    '''Class representing a single annotation of either a logogram of a
    sign or signs in the dataset or an isolated grapheme.

    Args:
        path: the full path to the annotation files (either source image or tag
            dictionary, which should share path and filename but not extension
            (the annotation dictionary need not exist).
        '''

    target = None  # Should be set by concrete class

    def __init__(self, path):
        path = Path(path)
        #: Number which identifies this annotation in its subset.
        self.id = path.stem
        #: Path to the json annotation file. It is the id plus `json` extension.
        self.json_path = path.with_suffix('.json')
        #: Path to the source image for the annotation. It is the id plus `png` extension.
        self.image_path = path.with_suffix('.png')
コード例 #9
0
    OE_OV # O(|E|+|V|)
    OV_OD
    OV_OlogD
    OlogV_OD
    OlogVD # O(log(|V|*max_degree))


    OW # assume graph is a subgraph of graph with vertices [0..W-1]
'''
GraphAlgoSpeed = Flag(
    'GraphAlgoSpeed', '''
    OW
    OE
    OVV
    OV
    OD
    O1

    OlogE
    OlogV
    OlogD
    '''.split())
# Oa|Ob means O(a*b)
# {Oa, Ob} means O(a+b)
# prime_speed :: GraphAlgoSpeed             # product
# macro_speed :: frozenset<GraphAlgoSpeed>  # sum of product
macro_O1 = frozenset([GraphAlgoSpeed.O1])


def prime_graph_algo_speed_mul(prime_speedL, prime_speedR):
    return prime_speedL | prime_speedR