code
stringlengths
1
18.2k
def delete_asset(self, asset_id=None): """Deletes an ``Asset``. :param asset_id: the ``Id`` of the ``Asset`` to remove :type asset_id: ``osid.id.Id`` :raise: ``NotFound`` -- ``asset_id`` not found :raise: ``NullArgument`` -- ``asset_id`` is ``null`` :raise: ``OperationFailed`` -- unable to complete request :raise: ``Pe...
def can_create_asset_content(self, asset_id=None): """Tests if this user can create content for ``Assets``. A return of true does not guarantee successful authorization. A return of false indicates that it is known creating an ``Asset`` will result in a ``PermissionDenied``. This is intended as a hint to an application...
def can_create_asset_content_with_record_types(self, asset_id=None, asset_content_record_types=None): """Tests if this user can create an ``AssetContent`` using the desired record types. While ``RepositoryManager.getAssetContentRecordTypes()`` can be used to test which records are supported, this method tests which rec...
def get_asset_content_form_for_create(self, asset_id=None, asset_content_record_types=None): """Gets an asset content form for creating new assets. :param asset_id: the ``Id`` of an ``Asset`` :type asset_id: ``osid.id.Id`` :param asset_content_record_types: array of asset content record types :type asset_content_record...
def create_asset_content(self, asset_content_form=None): """Creates new ``AssetContent`` for a given asset. :param asset_content_form: the form for this ``AssetContent`` :type asset_content_form: ``osid.repository.AssetContentForm`` :return: the new ``AssetContent`` :rtype: ``osid.repository.AssetContent`` :raise: ``Il...
did not originate from this session') if not asset_content_form.is_valid(): raise InvalidArgument('one or more of the form elements is invalid') url_path = construct_url('assets', bank_id=self._catalog_idstr, asset_id=asset_content_form._asset_id) asset = objects.Asset(self._get_request(url_path)) previous_contents = a...
def can_update_asset_contents(self, asset_id=None): """Tests if this user can update ``AssetContent``. A return of true does not guarantee successful authorization. A return of false indicates that it is known updating an ``AssetContent`` will result in a ``PermissionDenied``. This is intended as a hint to an applicati...
def get_asset_content_form_for_update(self, asset_content_id=None): """Gets the asset form for updating content for an existing asset. A new asset content form should be requested for each update transaction. :param asset_content_id: the ``Id`` of the ``AssetContent`` :type asset_content_id: ``osid.id.Id`` :return: the...
def update_asset_content(self, asset_content_form=None): """Updates an existing asset. :param asset_content_form: the form containing the elements to be updated :type asset_content_form: ``osid.repository.AssetContentForm`` :raise: ``IllegalState`` -- ``asset_content_form`` already used in an update transaction :raise:...
asset_content_form.is_valid(): raise InvalidArgument('one or more of the form elements is invalid') url_path = construct_url('assets', bank_id=self._catalog_idstr, asset_id=asset_content_form._asset_id) asset = objects.Asset(self._get_request(url_path)) index = 0 for ac in asset.get_asset_contents(): if str(ac.get_id()...
def can_delete_asset_contents(self, asset_id=None): """Tests if this user can delete ``AssetsContent`` from ``Assets``. A return of true does not guarantee successful authorization. A return of false indicates that it is known deleting an ``AssetContent`` will result in a ``PermissionDenied``. This is intended as a hin...
def delete_asset_content(self, asset_content_id=None): """Deletes content from an ``Asset``. :param asset_content_id: the ``Id`` of the ``AssetContent`` :type asset_content_id: ``osid.id.Id`` :raise: ``NotFound`` -- ``asset_content_id`` is not found :raise: ``NullArgument`` -- ``asset_content_id`` is ``null`` :raise: `...
def can_lookup_repositories(self): """Tests if this user can perform ``Repository`` lookups. A return of true does not guarantee successful authorization. A return of false indicates that it is known all methods in this session will result in a ``PermissionDenied``. This is intended as a hint to an application that may...
def get_repository(self, repository_id=None): """Gets the ``Repository`` specified by its ``Id``. In plenary mode, the exact ``Id`` is found or a ``NotFound`` results. Otherwise, the returned ``Repository`` may have a different ``Id`` than requested, such as the case where a duplicate ``Id`` was assigned to a ``Reposit...
def get_repositories_by_ids(self, repository_ids=None): """Gets a ``RepositoryList`` corresponding to the given ``IdList``. In plenary mode, the returned list contains all of the repositories specified in the ``Id`` list, in the order of the list, including duplicates, or an error results if an ``Id`` in the supplied l...
is None: raise NullArgument() repositories = [] for i in repository_ids: repository = None url_path = construct_url('objective_banks', bank_id=i) try: repository = self._get_request(url_path) except (NotFound, OperationFailed): if self._repository_view == PLENARY: raise else: pass if repository: if not (self._repositor...
def get_repositories_by_genus_type(self, repository_genus_type=None): """Gets a ``RepositoryList`` corresponding to the given repository genus ``Type`` which does not include repositories of types derived from the specified ``Type``. In plenary mode, the returned list contains all known repositories or an error results...
HERE? if repository['genusTypeId'] == repository_genus_type.get_identifier(): repositories_of_type.append[repository] return objects.RepositoryList(repositories_of_type)
def can_create_repositories(self): """Tests if this user can create ``Repositories``. A return of true does not guarantee successful authorization. A return of false indicates that it is known creating a ``Repository`` will result in a ``PermissionDenied``. This is intended as a hint to an application that may not wish...
def can_create_repository_with_record_types(self, repository_record_types=None): """Tests if this user can create a single ``Repository`` using the desired record types. While ``RepositoryManager.getRepositoryRecordTypes()`` can be used to examine which records are supported, this method tests which record(s) are requi...
def get_repository_form_for_create(self, repository_record_types=None): """Gets the repository form for creating new repositories. A new form should be requested for each create transaction. :param repository_record_types: array of repository record types :type repository_record_types: ``osid.type.Type[]`` :return: the...
def create_repository(self, repository_form=None): """Creates a new ``Repository``. :param repository_form: the form for this ``Repository`` :type repository_form: ``osid.repository.RepositoryForm`` :return: the new ``Repository`` :rtype: ``osid.repository.Repository`` :raise: ``IllegalState`` -- ``repository_form`` al...
from this session') if not repository_form.is_valid(): raise InvalidArgument('one or more of the form elements is invalid') url_path = construct_url('objective_banks') try: result = self._post_request(url_path, repository_form._my_map) except Exception: raise # OperationFailed self._forms[repository_form.get_id().get_i...
def can_update_repositories(self): """Tests if this user can update ``Repositories``. A return of true does not guarantee successful authorization. A return of false indicates that it is known updating a ``Repository`` will result in a ``PermissionDenied``. This is intended as a hint to an application that may not wish...
def get_repository_form_for_update(self, repository_id=None): """Gets the repository form for updating an existing repository. A new repository form should be requested for each update transaction. :param repository_id: the ``Id`` of the ``Repository`` :type repository_id: ``osid.id.Id`` :return: the repository form :r...
def update_repository(self, repository_form=None): """Updates an existing repository. :param repository_form: the form containing the elements to be updated :type repository_form: ``osid.repository.RepositoryForm`` :raise: ``IllegalState`` -- ``repository_form`` already used in an update transaction :raise: ``InvalidAr...
UPDATED: raise IllegalState('form already used in an update transaction') except KeyError: raise Unsupported('form did not originate from this session') if not repository_form.is_valid(): raise InvalidArgument('one or more of the form elements is invalid') url_path = construct_url('objective_banks') try: result = self....
def can_delete_repositories(self): """Tests if this user can delete ``Repositories``. A return of true does not guarantee successful authorization. A return of false indicates that it is known deleting a ``Repository`` will result in a ``PermissionDenied``. This is intended as a hint to an application that may not wish...
def delete_repository(self, repository_id=None): """Deletes a ``Repository``. :param repository_id: the ``Id`` of the ``Repository`` to remove :type repository_id: ``osid.id.Id`` :raise: ``NotFound`` -- ``repository_id`` not found :raise: ``NullArgument`` -- ``repository_id`` is ``null`` :raise: ``OperationFailed`` -- ...
def raise_if(self, exception, message, *args, **kwargs): """ If current exception has smaller priority than minimum, subclass of this class only warns user, otherwise normal exception will be raised. """ if issubclass(exception, self.minimum_defect): raise exception(*args, **kwargs) warn(message, SyntaxWarning, *args, ...
def signal(e): """ Some docstrings. """ callback = find_handler(e) if callback is None: if _activate_debugger: print 'Handler for error {0} not found'.format(type(e)) traceback.print_stack() set_trace() raise e else: return callback(e)
def get_answers(self): """ override this so only right answers are returned :return: """ all_answers = self.my_osid_object._my_map['answers'] right_answers = [a for a in all_answers if a['genusTypeId'] != str(WRONG_ANSWER_GENUS_TYPE)] return AnswerList(right_answers, runtime=self.my_osid_object._runtime, proxy=self.my_...
def get_answer_ids(self): """ override this so only right answer ids are returned :return: """ id_list = [] for answer in self.get_answers(): id_list.append(answer.get_id()) return IdList(id_list)
def get_wrong_answers(self): """ provide this method to return only wrong answers :return: """ all_answers = self.my_osid_object._my_map['answers'] wrong_answers = [a for a in all_answers if a['genusTypeId'] == str(WRONG_ANSWER_GENUS_TYPE)] return AnswerList(wrong_answers, runtime=self.my_osid_object._runtime, proxy=se...
def get_wrong_answer_ids(self): """provide this method to return only wrong answer ids""" id_list = [] for answer in self.get_wrong_answers(): id_list.append(answer.get_id()) return IdList(id_list)
def extra_prepare(self, configuration, args_dict): """ Called before the configuration.converters are activated Here we make sure that we have harpoon options from ``args_dict`` in the configuration. We then load all the harpoon modules as specified by the ``harpoon.addons`` setting. Finally we inject into the configur...
def find_harpoon_options(self, configuration, args_dict): """Return us all the harpoon options""" d = lambda r: {} if r in (None, "", NotSpecified) else r return MergedOptions.using( dict(d(configuration.get('harpoon')).items()) , dict(d(args_dict.get("harpoon")).items()) ).as_dict()
def setup_addon_register(self, harpoon): """Setup our addon register""" # Create the addon getter and register the crosshairs namespace self.addon_getter = AddonGetter() self.addon_getter.add_namespace("harpoon.crosshairs", Result.FieldSpec(), Addon.FieldSpec()) # Initiate the addons from our configuration register = R...
def extra_prepare_after_activation(self, configuration, args_dict): """ Called after the configuration.converters are activated Here we create our ``task_maker`` helper that we pass into ``post_register`` for our ``option_merge_addon_hook`` functions. We also create a ``task_finder`` for doing task finding related duti...
def add_configuration(self, configuration, collect_another_source, done, result, src): """ Used to add a file to the configuration, result here is the yaml.load of the src. If the configuration we're reading in has ``harpoon.extra_files`` then this is treated as a list of strings of other files to collect. We also take...
result and "__images_from__" in result["images"]: images_from_path = result["images"]["__images_from__"] if isinstance(images_from_path, six.string_types): images_from_path = [images_from_path] for ifp in images_from_path: if not ifp.startswith("/"): ifp = os.path.join(os.path.dirname(src), ifp) if not os.path.exists(i...
def extra_configuration_collection(self, configuration): """ Hook to do any extra configuration collection or converter registration """ harpoon_spec = HarpoonSpec() for image in configuration.get('images', {}).keys(): self.make_image_converters(image, configuration, harpoon_spec) self.register_converters( { (0, ("cont...
def make_image_converters(self, image, configuration, harpoon_spec): """Make converters for this image and add them to the configuration""" def convert_image(path, val): log.info("Converting %s", path) everything = path.configuration.root().wrapped() meta = Meta(everything, []) configuration.converters.started(path) ba...
def filter_arc(w, h, aspect): """Aspect ratio convertor. you must specify output size and source aspect ratio (as float)""" taspect = float(w)/h if abs(taspect - aspect) < 0.01: return "scale=%s:%s"%(w,h) if taspect > aspect: # pillarbox pt = 0 ph = h pw = int (h*aspect) pl = int((w - pw)/2.0) else: # letterbox pl = 0 ...
def get_asset(self, asset_id=None): """Gets the ``Asset`` specified by its ``Id``. In plenary mode, the exact ``Id`` is found or a ``NotFound`` results. Otherwise, the returned ``Asset`` may have a different ``Id`` than requested, such as the case where a duplicate ``Id`` was assigned to an ``Asset`` and retained for c...
def get_assets_by_ids(self, asset_ids=None): """Gets an ``AssetList`` corresponding to the given ``IdList``. In plenary mode, the returned list contains all of the assets specified in the ``Id`` list, in the order of the list, including duplicates, or an error results if an ``Id`` in the supplied list is not found or i...
def get_assets_by_genus_type(self, asset_genus_type=None): """Gets an ``AssetList`` corresponding to the given asset genus ``Type`` which does not include assets of types derived from the specified ``Type``. In plenary mode, the returned list contains all known assets or an error results. Otherwise, the returned list m...
def get_assets_by_parent_genus_type(self, asset_genus_type=None): """Gets an ``AssetList`` corresponding to the given asset genus ``Type`` and include any additional assets with genus types derived from the specified ``Type``. In plenary mode, the returned list contains all known assets or an error results. Otherwise, ...
def get_assets_by_record_type(self, asset_record_type=None): """Gets an ``AssetList`` containing the given asset record ``Type``. In plenary mode, the returned list contains all known assets or an error results. Otherwise, the returned list may contain only those assets that are accessible through this session. arg: as...
def get_assets_by_provider(self, resource_id=None): """Gets an ``AssetList`` from the given provider. In plenary mode, the returned list contains all known assets or an error results. Otherwise, the returned list may contain only those assets that are accessible through this session. arg: resource_id (osid.id.Id): a re...
def get_asset_content(self, asset_content_id): """Gets the ``AssetContent`` specified by its ``Id``. In plenary mode, the exact ``Id`` is found or a ``NotFound`` results. Otherwise, the returned ``AssetContent`` may have a different ``Id`` than requested, such as the case where a duplicate ``Id`` was assigned to an ``A...
def get_asset_contents_by_ids(self, asset_content_ids): """Gets an ``AssetList`` corresponding to the given ``IdList``. In plenary mode, the returned list contains all of the asset contents specified in the ``Id`` list, in the order of the list, including duplicates, or an error results if an ``Id`` in the supplied lis...
AssetContentList(self._provider_session.get_asset_contents_by_ids(asset_content_ids), self._config_map)
def get_asset_contents_by_genus_type(self, asset_content_genus_type): """Gets an ``AssetContentList`` corresponding to the given asset content genus ``Type`` which does not include asset contents of types derived from the specified ``Type``. In plenary mode, the returned list contains all known asset contents or an err...
def get_asset_contents_by_parent_genus_type(self, asset_content_genus_type): """Gets an ``AssetContentList`` corresponding to the given asset content genus ``Type`` and include any additional asset contents with genus types derived from the specified ``Type``. In plenary mode, the returned list contains all known asset...
def get_asset_contents_by_record_type(self, asset_content_record_type): """Gets an ``AssetContentList`` containing the given asset record ``Type``. In plenary mode, the returned list contains all known asset contents or an error results. Otherwise, the returned list may contain only those asset contents that are access...
def get_asset_contents_for_asset(self, asset_id): """Gets an ``AssetList`` from the given Asset. In plenary mode, the returned list contains all known asset contents or an error results. Otherwise, the returned list may contain only those asset contents that are accessible through this session. :param asset_id: an asse...
def get_asset_contents_by_genus_type_for_asset(self, asset_content_genus_type, asset_id): """Gets an ``AssetContentList`` from the given GenusType and Asset Id. In plenary mode, the returned list contains all known asset contents or an error results. Otherwise, the returned list may contain only those asset contents th...
def get_assets_by_query(self, asset_query=None): """Gets a list of ``Assets`` matching the given asset query. arg: asset_query (osid.repository.AssetQuery): the asset query return: (osid.repository.AssetList) - the returned ``AssetList`` raise: NullArgument - ``asset_query`` is ``null`` raise: OperationFailed - unable ...
def get_asset_contents_by_query(self, asset_content_query=None): """Gets a list of ``AssetContents`` matching the given asset content query. arg: asset_content_query (osid.repository.AssetContentQuery): the asset content query return: (osid.repository.AssetContentList) - the returned ``AssetContentList`` raise: NullArg...
def update_asset(self, asset_form=None): """Updates an existing asset. arg: asset_form (osid.repository.AssetForm): the form containing the elements to be updated raise: IllegalState - ``asset_form`` already used in anupdate transaction raise: InvalidArgument - the form contains an invalid value raise: NullArgument - `...
def delete_asset(self, asset_id=None): """Deletes an ``Asset``. arg: asset_id (osid.id.Id): the ``Id`` of the ``Asset`` to remove raise: NotFound - ``asset_id`` not found raise: NullArgument - ``asset_id`` is ``null`` raise: OperationFailed - unable to complete request raise: PermissionDenied - authorization failure *c...
def get_asset_content_form_for_create(self, asset_id=None, asset_content_record_types=None): """Gets an asset content form for creating new assets. arg: asset_id (osid.id.Id): the ``Id`` of an ``Asset`` arg: asset_content_record_types (osid.type.Type[]): array of asset content record types return: (osid.repository.Asse...
def create_asset_content(self, asset_content_form=None): """Creates new ``AssetContent`` for a given asset. arg: asset_content_form (osid.repository.AssetContentForm): the form for this ``AssetContent`` return: (osid.repository.AssetContent) - the new ``AssetContent`` raise: IllegalState - ``asset_content_form`` alread...
def get_asset_content_form_for_update(self, asset_content_id=None): """Gets the asset content form for updating an existing asset content. A new asset content form should be requested for each update transaction. arg: asset_content_id (osid.id.Id): the ``Id`` of the ``AssetContent`` return: (osid.repository.AssetConten...
def update_asset_content(self, asset_content_form=None): """Updates an existing asset content. arg: asset_content_form (osid.repository.AssetContentForm): the form containing the elements to be updated raise: IllegalState - ``asset_content_form`` already used in an update transaction raise: InvalidArgument - the form c...
def delete_asset_content(self, asset_content_id=None): """Deletes content from an ``Asset``. arg: asset_content_id (osid.id.Id): the ``Id`` of the ``AssetContent`` raise: NotFound - ``asset_content_id`` is not found raise: NullArgument - ``asset_content_id`` is ``null`` raise: OperationFailed - unable to complete reque...
def _get_asset_content(self, asset_content_id): """stub""" asset_content = None for asset in self._asset_lookup_session.get_assets(): for content in asset.get_asset_contents(): if content.get_id() == asset_content_id: asset_content = content break if asset_content is not None: break if asset_content is None: raise NotF...
def get_repository(self, repository_id=None): """Gets the ``Repository`` specified by its ``Id``. In plenary mode, the exact ``Id`` is found or a ``NotFound`` results. Otherwise, the returned ``Repository`` may have a different ``Id`` than requested, such as the case where a duplicate ``Id`` was assigned to a ``Reposit...
def get_repositories_by_ids(self, repository_ids=None): """Gets a ``RepositoryList`` corresponding to the given ``IdList``. In plenary mode, the returned list contains all of the repositories specified in the ``Id`` list, in the order of the list, including duplicates, or an error results if an ``Id`` in the supplied l...
template for - # osid.resource.BinLookupSession.get_bins_by_ids_template if not self._can('lookup'): raise PermissionDenied() else: return self._provider_session.get_repositories_by_ids(repository_ids)
def get_repository_form_for_create(self, repository_record_types=None): """Gets the repository form for creating new repositories. A new form should be requested for each create transaction. arg: repository_record_types (osid.type.Type[]): array of repository record types return: (osid.repository.RepositoryForm) - the ...
def get_repository_form_for_update(self, repository_id=None): """Gets the repository form for updating an existing repository. A new repository form should be requested for each update transaction. arg: repository_id (osid.id.Id): the ``Id`` of the ``Repository`` return: (osid.repository.RepositoryForm) - the repositor...
def update_repository(self, repository_form=None): """Updates an existing repository. arg: repository_form (osid.repository.RepositoryForm): the form containing the elements to be updated raise: IllegalState - ``repository_form`` already used in an update transaction raise: InvalidArgument - the form contains an invali...
def delete_repository(self, repository_id=None): """Deletes a ``Repository``. arg: repository_id (osid.id.Id): the ``Id`` of the ``Repository`` to remove raise: NotFound - ``repository_id`` not found raise: NullArgument - ``repository_id`` is ``null`` raise: OperationFailed - unable to complete request raise: Permissio...
def alias_repository(self, repository_id=None, alias_id=None): """Adds an ``Id`` to a ``Repository`` for the purpose of creating compatibility. The primary ``Id`` of the ``Repository`` is determined by the provider. The new ``Id`` is an alias to the primary ``Id``. If the alias is a pointer to another repository, it is...
else: return self._provider_session.alias_repository(repository_id)
def add_asset(self, asset_id, composition_id): """Appends an asset to a composition. arg: asset_id (osid.id.Id): ``Id`` of the ``Asset`` arg: composition_id (osid.id.Id): ``Id`` of the ``Composition`` raise: AlreadyExists - ``asset_id`` already part ``composition_id`` raise: NotFound - ``asset_id`` or ``composition_id`...
def move_asset_ahead(self, asset_id, composition_id, reference_id): """Reorders assets in a composition by moving the specified asset in front of a reference asset. arg: asset_id (osid.id.Id): ``Id`` of the ``Asset`` arg: composition_id (osid.id.Id): ``Id`` of the ``Composition`` arg: reference_id (osid.id.Id): ``Id`` ...
def move_asset_behind(self, asset_id, composition_id, reference_id): """Reorders assets in a composition by moving the specified asset behind of a reference asset. arg: asset_id (osid.id.Id): ``Id`` of the ``Asset`` arg: composition_id (osid.id.Id): ``Id`` of the ``Composition`` arg: reference_id (osid.id.Id): ``Id`` o...
def order_assets(self, asset_ids, composition_id): """Reorders a set of assets in a composition. arg: asset_ids (osid.id.Id[]): ``Ids`` for a set of ``Assets`` arg: composition_id (osid.id.Id): ``Id`` of the ``Composition`` raise: NotFound - ``composition_id`` not found or, an ``asset_id`` not related to ``composition_...
def remove_asset(self, asset_id, composition_id): """Removes an ``Asset`` from a ``Composition``. arg: asset_id (osid.id.Id): ``Id`` of the ``Asset`` arg: composition_id (osid.id.Id): ``Id`` of the ``Composition`` raise: NotFound - ``asset_id`` ``not found in composition_id`` raise: NullArgument - ``asset_id`` or ``com...
def docker_context(): """Make a docker context""" try: client = docker.from_env( version = "auto" , timeout = int(os.environ.get("DOCKER_CLIENT_TIMEOUT", 180)) , assert_hostname = False ) info = client.info() log.info("Connected to docker daemon\tdriver=%s\tkernel=%s", info["Driver"], info["KernelVersion"]) except (Doc...
def get_type_data(name): """Return dictionary representation of type. Can be used to initialize primordium.type.primitives.Type """ name = name.upper() try: return { 'authority': 'birdland.mit.edu', 'namespace': 'time format', 'identifier': name, 'domain': 'Time Format Types', 'display_name': JEFFS_TIME_FORMAT_TYPES[na...
def get_hierarchy_traversal_session(self, proxy): """Gets the ``OsidSession`` associated with the hierarchy traversal service. arg: proxy (osid.proxy.Proxy): a proxy return: (osid.hierarchy.HierarchyTraversalSession) - a ``HierarchyTraversalSession`` raise: NullArgument - ``proxy`` is ``null`` raise: OperationFailed - ...
def get_hierarchy_traversal_session_for_hierarchy(self, hierarchy_id, proxy): """Gets the ``OsidSession`` associated with the hierarchy traversal service for the given hierarchy. arg: hierarchy_id (osid.id.Id): the ``Id`` of the hierarchy arg: proxy (osid.proxy.Proxy): a proxy return: (osid.hierarchy.HierarchyTraversal...
def get_hierarchy_design_session(self, proxy): """Gets the ``OsidSession`` associated with the hierarchy design service. arg: proxy (osid.proxy.Proxy): a proxy return: (osid.hierarchy.HierarchyDesignSession) - a ``HierarchyDesignSession`` raise: NullArgument - ``proxy`` is ``null`` raise: OperationFailed - unable to co...
def get_hierarchy_design_session_for_hierarchy(self, hierarchy_id, proxy): """Gets the ``OsidSession`` associated with the topology design service using for the given hierarchy. arg: hierarchy_id (osid.id.Id): the ``Id`` of the hierarchy arg: proxy (osid.proxy.Proxy): a proxy return: (osid.hierarchy.HierarchyDesignSess...
def get_hierarchy_lookup_session(self, proxy): """Gets the ``OsidSession`` associated with the hierarchy lookup service. arg: proxy (osid.proxy.Proxy): a proxy return: (osid.hierarchy.HierarchyLookupSession) - a ``HierarchyLookupSession`` raise: NullArgument - ``proxy`` is ``null`` raise: OperationFailed - unable to co...
def get_hierarchy_admin_session(self, proxy): """Gets the hierarchy administrative session. arg: proxy (osid.proxy.Proxy): a proxy return: (osid.hierarchy.HierarchyAdminSession) - a ``HierarchyAdminSession`` raise: NullArgument - ``proxy`` is ``null`` raise: OperationFailed - unable to complete request raise: Unimpleme...
def ast_to_headings(node): """ Walks AST and returns a list of headings """ Heading = namedtuple('Heading', ['level', 'title']) level = None walker = node.walker() headings = [] event = walker.nxt() while event is not None: entering = event['entering'] node = event['node'] if node.t == 'Heading': if entering: level = n...
def copy(self): """Convert ``Dictator`` to standard ``dict`` object >>> dc = Dictator() >>> dc['l0'] = [1, 2] >>> dc['1'] = 'abc' >>> d = dc.copy() >>> type(d) dict >>> d {'l0': ['1', '2'], '1': 'abc'} >>> dc.clear() :return: Python's dict object :rtype: dict """ logger.debug('call to_dict') return {key: self.get(key) ...
def get(self, key, default=None): """Return the value at key ``key``, or default value ``default`` which is None by default. >>> dc = Dictator() >>> dc['l0'] = [1, 2, 3, 4] >>> dc.get('l0') ['1', '2', '3', '4'] >>> dc['l0'] ['1', '2', '3', '4'] >>> dc.clear() :param key: key of value to return :type key: str :param def...
def pop(self, key, default=None): """Remove and return the last item of the list ``key``. If key doesn't exists it return ``default``. >>> dc = Dictator() >>> dc['l0'] = [1, 2, 3, 4] >>> dc.pop('l0') ['1', '2', '3', '4'] >>> dc.pop('l1', 'empty') 'empty' :param key: key name to pop :type key: str :param default: defaul...
def keys(self, pattern=None): """Returns a list of keys matching ``pattern``. By default return all keys. >>> dc = Dictator() >>> dc['l0'] = [1, 2, 3, 4] >>> dc['s0'] = 'string value' >>> dc.keys() ['l0', 's0'] >>> dc.keys('h*') [] >>> dc.clear() :param pattern: key pattern :type pattern: str :return: list of keys in d...
def items(self): """Return list of tuples of keys and values in db >>> dc = Dictator() >>> dc['l0'] = [1, 2, 3, 4] >>> dc.items() [('l0', ['1', '2', '3', '4'])] >>> dc.clear() :return: list of (key, value) pairs :rtype: list of tuple """ logger.debug('call items') return [(key, self.get(key)) for key in self.keys()]
def values(self): """Return list of values in db >>> dc = Dictator() >>> dc['l0'] = [1, 2, 3, 4] >>> dc.items() [('l0', ['1', '2', '3', '4'])] >>> dc.clear() :return: list of tuple :rtype: list """ logger.debug('call values') return [self.get(key) for key in self.keys()]
def iterkeys(self, match=None, count=1): """Return an iterator over the db's keys. ``match`` allows for filtering the keys by pattern. ``count`` allows for hint the minimum number of returns. >>> dc = Dictator() >>> dc['1'] = 'abc' >>> dc['2'] = 'def' >>> dc['3'] = 'ghi' >>> itr = dc.iterkeys() >>> type(itr) <type 'gen...
def iteritems(self, match=None, count=1): """Return an iterator over the db's (key, value) pairs. ``match`` allows for filtering the keys by pattern. ``count`` allows for hint the minimum number of returns. >>> dc = Dictator() >>> dc['1'] = 'abc' >>> dc['2'] = 'def' >>> dc['3'] = 'ghi' >>> itr = dc.iteritems() >>> type...
def update(self, other=None, **kwargs): """D.update([other, ]**kwargs) -> None. Update D From dict/iterable ``other`` and ``kwargs``. If ``other`` present and has a .keys() method, does: for k in other: D[k] = other[k] If ``other`` present and lacks .keys() method, does: for (k, v) in other: D[k] = v In either case, th...