How to use frozendict - 10 common examples

To help you get started, we’ve selected a few frozendict examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Bristol-Braille / canute-ui / ui / actions.py View on Github external
if page < 0:
            page = 0

        if state['help_menu']['visible']:
            location = 'help_menu'
        else:
            location = state['location']

        if location == 'library':
            books = state['user']['books']
            max_pages = (len(books) - 1) // (height - 1)
            if page > max_pages:
                page = max_pages
            elif page < 0:
                page = 0
            library = frozendict({'page': page})
            return state.copy(library=library)
        elif location == 'book':
            book_n = state['user']['current_book']
            book = state['user']['books'][book_n]
            books = OrderedDict(state['user']['books'])
            book = book.set_page(page)
            books[book_n] = book
            return state.copy(user=state['user'].copy(books=FrozenOrderedDict(books)))
        elif location == 'bookmarks_menu':
            book_n = state['user']['current_book']
            book = state['user']['books'][book_n]
            bookmarks_data = book.bookmarks
            # Account for title line.
            effective_height = height - 1
            num_pages = (len(bookmarks_data) + (effective_height-1)) // effective_height
            if page >= num_pages - 1:
github Bristol-Braille / canute-ui / ui / actions.py View on Github external
if location == 'library':
            books = state['user']['books']
            max_pages = (len(books) - 1) // (height - 1)
            if page > max_pages:
                page = max_pages
            elif page < 0:
                page = 0
            library = frozendict({'page': page})
            return state.copy(library=library)
        elif location == 'book':
            book_n = state['user']['current_book']
            book = state['user']['books'][book_n]
            books = OrderedDict(state['user']['books'])
            book = book.set_page(page)
            books[book_n] = book
            return state.copy(user=state['user'].copy(books=FrozenOrderedDict(books)))
        elif location == 'bookmarks_menu':
            book_n = state['user']['current_book']
            book = state['user']['books'][book_n]
            bookmarks_data = book.bookmarks
            # Account for title line.
            effective_height = height - 1
            num_pages = (len(bookmarks_data) + (effective_height-1)) // effective_height
            if page >= num_pages - 1:
                page = num_pages - 1
            bookmarks_menu = state['bookmarks_menu'].copy(page=page)
            return state.copy(bookmarks_menu=bookmarks_menu)
        elif location == 'language':
            lang_n = state['user'].get('current_language', 'en_GB:en')
            lang = list(state['languages']['available'].keys())[lang_n]
            language_menu = state['user'].copy(current_language=lang)
            return state.copy(language=language_menu)
github Yelp / pgctl / tests / unit / config.py View on Github external
def it_handles_frozen_maps(self):
        from frozendict import frozendict
        assert C.merge((
            frozendict({
                'map': frozendict({
                    'a': 'b',
                    'c': 'd',
                }),
            }),
            frozendict({
                'map': frozendict({
                    'a': 'e',
                    'f': 'g',
                }),
            }),
        )) == {
            'map': {
                'a': 'e',
                'c': 'd',
                'f': 'g',
github Bristol-Braille / canute-ui / ui / initial_state.py View on Github external
toml_file = to_state_file(book_file)
        book = BookFile(filename=book_file, width=40, height=9)
        if os.path.exists(toml_file):
            t = toml.load(toml_file)
            if 'current_page' in t:
                book = book._replace(page_number=t['current_page'] - 1)
            if 'bookmarks' in t:
                book = book._replace(bookmarks=tuple(sorted(book.bookmarks + tuple(
                    bm - 1 for bm in t['bookmarks']))))
        books[book_file] = book
    books[cleaning_filename] = CleaningAndTesting.create()

    if current_book not in books:
        current_book = manual_filename

    user_state = frozendict(books=FrozenOrderedDict(
        books), current_book=current_book, current_language=current_language)
    prev = user_state
    return user_state.copy(books=user_state['books'])
github erigones / esdc-ce / api / mon / backends / abstract / __init__.py View on Github external
import re


_VM_KWARGS = (
    ('ostype', 1),
    ('ostype_text', 'test'),
    ('dc_name', 'test'),
    ('disk_image', 'test'),
    ('disk_image_abbr', 'test'),
)

VM_KWARGS = frozendict(_VM_KWARGS)
VM_KWARGS_KEYS = tuple(VM_KWARGS.keys())
VM_KWARGS_NIC = frozendict(_VM_KWARGS + (('net', 1), ('nic_id', 2)))
VM_KWARGS_DISK = frozendict(_VM_KWARGS + (('disk', 1), ('disk_id', 2)))
NODE_KWARGS = frozendict()
NODE_KWARGS_KEYS = tuple(NODE_KWARGS.keys())


class FakeDetailLog(object):
    """
    Dummy list-like object used for collecting log lines.
    """
    def add(self, *args):
        pass


LOG = FakeDetailLog()


class MonitoringError(Exception):
    """
github opesci / devito / devito / mpi / halo_scheme.py View on Github external
    @classmethod
    def build(cls, fmapper, honored):
        obj = object.__new__(HaloScheme)
        obj._mapper = frozendict(fmapper)
        obj._honored = frozendict(honored)
        return obj
github aertslab / pySCENIC / src / pyscenic / genesig.py View on Github external
def convert(genes):
    # Genes supplied as dictionary.
    if isinstance(genes, Mapping):
        return frozendict(genes)
    # Genes supplied as iterable of (gene, weight) tuples.
    elif isinstance(genes, Iterable) and all(isinstance(n, tuple) for n in genes):
        return frozendict(genes)
    # Genes supplied as iterable of genes.
    elif isinstance(genes, Iterable) and all(isinstance(n, str) for n in genes):
        return frozendict(zip(genes, repeat(1.0)))
github devitocodes / devito / devito / mpi / halo_scheme.py View on Github external
# *What* halo exchanges do we need?
        classification = hs_classify(scope)

        for f, v in classification.items():
            # *How much* halo do we have to exchange?
            halos = hs_comp_halos(f, [d for d, hl in v.items() if hl is STENCIL], dspace)
            halos.extend(hs_comp_halos(f, [d for d, hl in v.items() if hl is FULL]))

            # *What* are the local (i.e., non-halo) indices?
            loc_indices = hs_comp_locindices(f, [d for d, hl in v.items() if hl is NONE],
                                             ispace, dspace, scope)

            if halos:
                self._mapper[f] = HaloSchemeEntry(frozendict(loc_indices), tuple(halos))

        self._mapper = frozendict(self._mapper)
github erigones / esdc-ce / api / fields.py View on Github external
}
    """
    _key_field_class = CIDRField
    _val_field_class = IPNICField


class MetadataField(BaseDictField):
    _key_field_class = RegexField
    _key_field_params = frozendict(regex=r'^[A-Za-z0-9\.\-_:]+$', max_length=128)
    _val_field_class = CharField
    _default_max_size = 1024 * 1024 * 2  # 2 MB (mentioned in user guide)


class URLDictField(BaseDictField):
    _key_field_class = RegexField
    _key_field_params = frozendict(regex=r'^[a-z0-9][a-z0-9\.\-_]*$', max_length=32)
    _val_field_class = URLField


class SafeCharField(RegexField):
    type_name = 'CharField'

    def __init__(self, *args, **kwargs):
        super(SafeCharField, self).__init__(SAFE_CHARS, *args, **kwargs)
github cyanogen / uchroma / uchroma / dbus_utils.py View on Github external
continue
                r_obj, r_sig = dbus_prepare(item, variant=is_variant)
                if r_obj is None:
                    continue

                tmp.append(r_obj)

            if is_variant:
                sig += 'v'
            else:
                sig += dbus_prepare(tmp[0])[1]

            obj = tmp

        elif isinstance(obj, (dict, frozendict)):
            if isinstance(obj, frozendict):
                tmp = {}
            else:
                tmp = obj.__class__()
            sig = 'a{s'
            vals = [x for x in obj.values() if x is not None]
            is_variant = use_variant or _check_variance(vals)

            for k, v in obj.items():
                if v is None:
                    continue
                r_obj, r_sig = dbus_prepare(v)
                if r_obj is None:
                    continue
                if camel_keys:
                    k = snake_to_camel(k)
                if is_variant:

frozendict

A simple immutable dictionary

LGPL-3.0
Latest version published 2 months ago

Package Health Score

82 / 100
Full package analysis

Similar packages