How to use the frozendict.FrozenOrderedDict function in frozendict

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 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 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 Bristol-Braille / canute-ui / ui / actions.py View on Github external
def close_menu(self, state, value):
        books = state['user']['books']
        # fully delete deleted bookmarks
        changed_books = OrderedDict()
        for filename in books:
            book = books[filename]
            bookmarks = tuple(bm for bm in book.bookmarks if bm != 'deleted')
            book = book._replace(bookmarks=bookmarks)
            changed_books[filename] = book
        bookmarks_menu = state['bookmarks_menu']
        return state.copy(location='book',
                          bookmarks_menu=bookmarks_menu.copy(page=0),
                          home_menu_visible=False, go_to_page_selection='',
                          help_menu=frozendict({'visible': False, 'page': 0}),
                          user=state['user'].copy(books=FrozenOrderedDict(changed_books)))
github Bristol-Braille / canute-ui / ui / library / reducers.py View on Github external
def sort_books(books):
    return FrozenOrderedDict(sorted(books.items(), key=lambda x: x[1].title.lower()))
github Bristol-Braille / canute-ui / ui / library / reducers.py View on Github external
def remove_book(self, state, book):
        books = OrderedDict(state['user']['books'])
        if book.filename in books:
            del books[book.filename]
        books = FrozenOrderedDict(books)
        return state.copy(user=state['user'].copy(books=books))
github consbio / gis-metadata-parser / gis_metadata / iso_metadata_parser.py View on Github external
('_attr_root', 'FC_FeatureCatalogue'),
    ('_attr_base', 'featureType/FC_FeatureType/carrierOfCharacteristics/FC_FeatureAttribute'),
    ('_attr_def', '{_attr_base}/definitionReference/FC_DefinitionReference/definitionSource/FC_DefinitionSource'),
    ('_attr_src', '{_attr_def}/source/CI_Citation/citedResponsibleParty/CI_ResponsibleParty'),

    # References to separate file ISO-19110 from: MD_Metadata
    ('_attr_citation', 'contentInfo/MD_FeatureCatalogueDescription/featureCatalogueCitation'),
    ('_attr_contact', '{_attr_citation}/CI_Citation/citedResponsibleParty/CI_ResponsibleParty/contactInfo/CI_Contact'),
    ('_attr_contact_url', '{_attr_contact}/onlineResource/CI_OnlineResource/linkage/URL')
))


# Two passes required because of self references within roots dict
ISO_TAG_ROOTS.update(format_xpaths(ISO_TAG_ROOTS, **ISO_TAG_ROOTS))
ISO_TAG_ROOTS.update(format_xpaths(ISO_TAG_ROOTS, **ISO_TAG_ROOTS))
ISO_TAG_ROOTS = FrozenOrderedDict(ISO_TAG_ROOTS)

ISO_TAG_FORMATS = {
    # Property-specific xpath roots: the base from which each element repeats
    '_attribute_accuracy_root': '{_dataqual_report}',
    '_attributes_root': 'featureType/FC_FeatureType/carrierOfCharacteristics',
    '_bounding_box_root': '{_idinfo_extent}/geographicElement',
    '_contacts_root': '{_idinfo}/pointOfContact',
    '_dataset_completeness_root': '{_dataqual_report}',
    '_dates_root': '{_idinfo_extent}/temporalElement',
    '_digital_forms_root': '{_distinfo}/distributionFormat',
    '_dist_liability_root': '{_idinfo}/resourceConstraints',
    '_transfer_options_root': '{_distinfo}/transferOptions/MD_DigitalTransferOptions/onLine',
    '_keywords_root': '{_idinfo}/descriptiveKeywords',
    '_larger_works_root': '{_idinfo_aggregate_citation}',
    '_process_steps_root': '{_dataqual_lineage}/processStep',
    '_raster_info_root': '{_srinfo_grid_rep}/axisDimensionProperties',
github Bristol-Braille / canute-ui / ui / bookmarks / reducers.py View on Github external
book_n = state['user']['current_book']
        books = OrderedDict(state['user']['books'])
        book = books[book_n]
        bookmarks = book.bookmarks
        line = page * height
        # don't delete go-to-start end and go-to-end bookmarks
        if (line + n) == 0 or (line + n) == (len(bookmarks) - 1):
            return state
        changed_bookmarks = list(bookmarks[line:line + height])
        if n >= len(changed_bookmarks):
            return state
        changed_bookmarks[n] = 'deleted'
        bookmarks = bookmarks[0:line] + tuple(changed_bookmarks) \
            + bookmarks[line + height:len(bookmarks)]
        books[book_n] = book._replace(bookmarks=bookmarks)
        return state.copy(user=state['user'].copy(books=FrozenOrderedDict(books)))
github Bristol-Braille / canute-ui / ui / book / reducers.py View on Github external
def set_book_page(self, state, page):
        width, height = state_helpers.dimensions(state)
        book_n = state['user']['current_book']
        books = OrderedDict(state['user']['books'])
        book = books[book_n].set_page(page)
        bookmarks = tuple(bm for bm in book.bookmarks if bm != 'deleted')
        book = book._replace(bookmarks=bookmarks)
        books[book_n] = book
        return state.copy(user=state['user'].copy(books=FrozenOrderedDict(books)),
                          location='book', home_menu_visible=False)

frozendict

A simple immutable dictionary

LGPL-3.0
Latest version published 5 months ago

Package Health Score

84 / 100
Full package analysis

Similar packages