code stringlengths 1 18.2k |
|---|
def get_compositions_by_asset(self, asset_id): """Gets a list of compositions including the given asset. arg: asset_id (osid.id.Id): ``Id`` of the ``Asset`` return: (osid.repository.CompositionList) - the returned ``Composition list`` raise: NotFound - ``asset_id`` is not found raise: NullArgument - ``asset_id`` is ``n... |
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`... |
asset_id.get_authority() != self._authority: raise errors.InvalidArgument() else: mgr = self._get_provider_manager('REPOSITORY') admin_session = mgr.get_asset_admin_session_for_repository(self._catalog_id, proxy=self._proxy) asset_id = admin_session._get_asset_id_with_enclosure(asset_id) collection = JSONClientValidate... |
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 _get_composition_collection(self, composition_id): """Returns a Mongo Collection and Composition given a Composition Id""" collection = JSONClientValidated('repository', collection='Composition', runtime=self._runtime) composition_map = collection.find_one({'_id': ObjectId(composition_id.get_identifier())}) if 'ass... |
def get_composition(self, composition_id): """Gets the ``Composition`` specified by its ``Id``. arg: composition_id (osid.id.Id): ``Id`` of the ``Composiiton`` return: (osid.repository.Composition) - the composition raise: NotFound - ``composition_id`` not found raise: NullArgument - ``composition_id`` is ``null`` rais... |
def get_compositions_by_ids(self, composition_ids): """Gets a ``CompositionList`` corresponding to the given ``IdList``. arg: composition_ids (osid.id.IdList): the list of ``Ids`` to retrieve return: (osid.repository.CompositionList) - the returned ``Composition list`` raise: NotFound - an ``Id`` was not found raise: N... |
def get_compositions_by_genus_type(self, composition_genus_type): """Gets a ``CompositionList`` corresponding to the given composition genus ``Type`` which does not include compositions of types derived from the specified ``Type``. arg: composition_genus_type (osid.type.Type): a composition genus type return: (osid.rep... |
def get_compositions(self): """Gets all ``Compositions``. return: (osid.repository.CompositionList) - a list of ``Compositions`` raise: OperationFailed - unable to complete request raise: PermissionDenied - authorization failure *compliance: mandatory -- This method must be implemented.* """ # Implemented from template... |
def get_compositions_by_query(self, composition_query): """Gets a list of ``Compositions`` matching the given composition query. arg: composition_query (osid.repository.CompositionQuery): the composition query return: (osid.repository.CompositionList) - the returned ``CompositionList`` raise: NullArgument - ``compositi... |
else: result = [] return objects.CompositionList(result, runtime=self._runtime, proxy=self._proxy) |
def get_compositions_by_search(self, composition_query, composition_search): """Gets the search results matching the given search query using the given search. arg: composition_query (osid.repository.CompositionQuery): the composition query arg: composition_search (osid.repository.CompositionSearch): the composition se... |
view_filter: and_list.append(view_filter) if and_list: query_terms = {'$and': and_list} collection = JSONClientValidated('repository', collection='Composition', runtime=self._runtime) if composition_search.start is not None and composition_search.end is not None: result = collection.find(query_terms)[composition_search... |
def get_composition_form_for_create(self, composition_record_types): """Gets the composition form for creating new compositions. A new form should be requested for each create transaction. arg: composition_record_types (osid.type.Type[]): array of composition record types return: (osid.repository.CompositionForm) - the... |
def create_composition(self, composiiton_form): """Creates a new ``Composition``. arg: composiiton_form (osid.repository.CompositionForm): the form for this ``Composition`` return: (osid.repository.Composition) - the new ``Composition`` raise: IllegalState - ``composition_form`` already used in a create transaction rai... |
raise errors.Unsupported('composiiton_form did not originate from this session') if not composiiton_form.is_valid(): raise errors.InvalidArgument('one or more of the form elements is invalid') insert_result = collection.insert_one(composiiton_form._my_map) self._forms[composiiton_form.get_id().get_identifier()] = CREAT... |
def update_composition(self, composiiton_form): """Updates an existing composition. arg: composiiton_form (osid.repository.CompositionForm): the form containing the elements to be updated raise: IllegalState - ``composition_form`` already used in an update transaction raise: InvalidArgument - the form contains an inval... |
from this session') if not composiiton_form.is_valid(): raise errors.InvalidArgument('one or more of the form elements is invalid') collection.save(composiiton_form._my_map) self._forms[composiiton_form.get_id().get_identifier()] = UPDATED # Note: this is out of spec. The OSIDs don't require an object to be returned: r... |
def delete_composition(self, composition_id): """Deletes a ``Composition``. arg: composition_id (osid.id.Id): the ``Id`` of the ``Composition`` to remove raise: NotFound - ``composition_id`` not found raise: NullArgument - ``composition_id`` is ``null`` raise: OperationFailed - unable to complete request raise: Permiss... |
def alias_composition(self, composition_id, alias_id): """Adds an ``Id`` to a ``Composition`` for the purpose of creating compatibility. The primary ``Id`` of the ``Composition`` is determined by the provider. The new ``Id`` is an alias to the primary ``Id``. If the alias is a pointer to another composition, it is reas... |
def get_composition_ids_by_repository(self, repository_id): """Gets the list of ``Composition`` ``Ids`` associated with a ``Repository``. arg: repository_id (osid.id.Id): ``Id`` of the ``Repository`` return: (osid.id.IdList) - list of related composition ``Ids`` raise: NotFound - ``repository_id`` is not found raise: N... |
def get_compositions_by_repository(self, repository_id): """Gets the list of ``Compositions`` associated with a ``Repository``. arg: repository_id (osid.id.Id): ``Id`` of the ``Repository`` return: (osid.repository.CompositionList) - list of related compositions raise: NotFound - ``repository_id`` is not found raise: N... |
def get_composition_ids_by_repositories(self, repository_ids): """Gets the list of ``Composition`` ``Ids`` corresponding to a list of ``Repository`` objects. arg: repository_ids (osid.id.IdList): list of repository ``Ids`` return: (osid.id.IdList) - list of composition ``Ids`` raise: NullArgument - ``repository_ids`` i... |
def get_compositions_by_repositories(self, repository_ids): """Gets the list of ``Compositions`` corresponding to a list of ``Repository`` objects. arg: repository_ids (osid.id.IdList): list of repository ``Ids`` return: (osid.repository.CompositionList) - list of Compositions raise: NullArgument - ``repository_ids`` i... |
def get_repository_ids_by_composition(self, composition_id): """Gets the ``Repository`` ``Ids`` mapped to a ``Composition``. arg: composition_id (osid.id.Id): ``Id`` of a ``Composition`` return: (osid.id.IdList) - list of repository ``Ids`` raise: NotFound - ``composition_id`` is not found raise: NullArgument - ``compo... |
def get_repositories_by_composition(self, composition_id): """Gets the ``Repository`` objects mapped to a ``Composition``. arg: composition_id (osid.id.Id): ``Id`` of a ``Composition`` return: (osid.repository.RepositoryList) - list of repositories raise: NotFound - ``composition_id`` is not found raise: NullArgument -... |
def assign_composition_to_repository(self, composition_id, repository_id): """Adds an existing ``Composition`` to a ``Repository``. arg: composition_id (osid.id.Id): the ``Id`` of the ``Composition`` arg: repository_id (osid.id.Id): the ``Id`` of the ``Repository`` raise: AlreadyExists - ``composition_id`` already assi... |
def unassign_composition_from_repository(self, composition_id, repository_id): """Removes ``Composition`` from a ``Repository``. arg: composition_id (osid.id.Id): the ``Id`` of the ``Composition`` arg: repository_id (osid.id.Id): the ``Id`` of the ``Repository`` raise: NotFound - ``composition_id`` or ``repository_id``... |
def get_repository(self, repository_id): """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 ``Repository``... |
issue if repository_id.get_identifier() == PHANTOM_ROOT_IDENTIFIER: return self._get_phantom_root_catalog(cat_class=objects.Repository, cat_name='Repository') try: result = collection.find_one({'_id': ObjectId(self._get_id(repository_id, 'repository').get_identifier())}) except errors.NotFound: # Try creating an orches... |
def get_repositories_by_ids(self, repository_ids): """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 list i... |
for # osid.resource.BinLookupSession.get_bins_by_ids_template # NOTE: This implementation currently ignores plenary view # Also, this should be implemented to use get_Repository() instead of direct to database if self._catalog_session is not None: return self._catalog_session.get_catalogs_by_ids(catalog_ids=repository_... |
def get_repositories_by_genus_type(self, repository_genus_type): """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. Oth... |
objects.RepositoryList(result, runtime=self._runtime, proxy=self._proxy) |
def get_repositories_by_query(self, repository_query): """Gets a list of ``Repositories`` matching the given repository query. arg: repository_query (osid.repository.RepositoryQuery): the repository query return: (osid.repository.RepositoryList) - the returned ``RepositoryList`` raise: NullArgument - ``repository_query... |
def can_create_repository_with_record_types(self, repository_record_types): """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 required f... |
return self._catalog_session.can_create_catalog_with_record_types(catalog_record_types=repository_record_types) return True |
def update_repository(self, repository_form): """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 invalid val... |
except KeyError: raise errors.Unsupported('repository_form did not originate from this session') if not repository_form.is_valid(): raise errors.InvalidArgument('one or more of the form elements is invalid') collection.save(repository_form._my_map) # save is deprecated - change to replace_one self._forms[repository_for... |
def alias_repository(self, repository_id, alias_id): """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 reassigne... |
alias_id=alias_id) self._alias_id(primary_id=repository_id, equivalent_id=alias_id) |
def get_root_repositories(self): """Gets the root repositories in the repository hierarchy. A node with no parents is an orphan. While all repository ``Ids`` are known to the hierarchy, an orphan does not appear in the hierarchy unless explicitly added as a root node or child of another node. return: (osid.repository.R... |
def has_parent_repositories(self, repository_id): """Tests if the ``Repository`` has any parents. arg: repository_id (osid.id.Id): a repository ``Id`` return: (boolean) - ``true`` if the repository has parents, ``false`` otherwise raise: NotFound - ``repository_id`` is not found raise: NullArgument - ``repository_id`` ... |
def is_parent_of_repository(self, id_, repository_id): """Tests if an ``Id`` is a direct parent of a repository. arg: id (osid.id.Id): an ``Id`` arg: repository_id (osid.id.Id): the ``Id`` of a repository return: (boolean) - ``true`` if this ``id`` is a parent of ``repository_id,`` ``false`` otherwise raise: NotFound -... |
def get_parent_repository_ids(self, repository_id): """Gets the parent ``Ids`` of the given repository. arg: repository_id (osid.id.Id): a repository ``Id`` return: (osid.id.IdList) - the parent ``Ids`` of the repository raise: NotFound - ``repository_id`` is not found raise: NullArgument - ``repository_id`` is ``null`... |
def get_parent_repositories(self, repository_id): """Gets the parents of the given repository. arg: repository_id (osid.id.Id): the ``Id`` to query return: (osid.repository.RepositoryList) - the parents of the repository raise: NotFound - ``repository_id`` not found raise: NullArgument - ``repository_id`` is ``null`` r... |
def is_ancestor_of_repository(self, id_, repository_id): """Tests if an ``Id`` is an ancestor of a repository. arg: id (osid.id.Id): an ``Id`` arg: repository_id (osid.id.Id): the Id of a repository return: (boolean) - ``true`` if this ``id`` is an ancestor of ``repository_id,`` ``false`` otherwise raise: NotFound - ``... |
def has_child_repositories(self, repository_id): """Tests if a repository has any children. arg: repository_id (osid.id.Id): a repository ``Id`` return: (boolean) - ``true`` if the ``repository_id`` has children, ``false`` otherwise raise: NotFound - ``repository_id`` not found raise: NullArgument - ``repository_id`` i... |
def is_child_of_repository(self, id_, repository_id): """Tests if a node is a direct child of another. arg: id (osid.id.Id): an ``Id`` arg: repository_id (osid.id.Id): the ``Id`` of a repository return: (boolean) - ``true`` if the ``id`` is a child of ``repository_id,`` ``false`` otherwise raise: NotFound - ``repositor... |
def get_child_repository_ids(self, repository_id): """Gets the ``Ids`` of the children of the given repository. arg: repository_id (osid.id.Id): the ``Id`` to query return: (osid.id.IdList) - the children of the repository raise: NotFound - ``repository_id`` not found raise: NullArgument - ``repository_id`` is ``null``... |
def get_child_repositories(self, repository_id): """Gets the children of the given repository. arg: repository_id (osid.id.Id): the ``Id`` to query return: (osid.repository.RepositoryList) - the children of the repository raise: NotFound - ``repository_id`` not found raise: NullArgument - ``repository_id`` is ``null`` ... |
def is_descendant_of_repository(self, id_, repository_id): """Tests if an ``Id`` is a descendant of a repository. arg: id (osid.id.Id): an ``Id`` arg: repository_id (osid.id.Id): the ``Id`` of a repository return: (boolean) - ``true`` if the ``id`` is a descendant of the ``repository_id,`` ``false`` otherwise raise: No... |
def get_repository_node_ids(self, repository_id, ancestor_levels, descendant_levels, include_siblings): """Gets a portion of the hierarchy for the given repository. arg: repository_id (osid.id.Id): the ``Id`` to query arg: ancestor_levels (cardinal): the maximum number of ancestor levels to include. A value of 0 return... |
osid.resource.BinHierarchySession.get_bin_node_ids if self._catalog_session is not None: return self._catalog_session.get_catalog_node_ids( catalog_id=repository_id, ancestor_levels=ancestor_levels, descendant_levels=descendant_levels, include_siblings=include_siblings) return self._hierarchy_session.get_nodes( id_=rep... |
def get_repository_nodes(self, repository_id, ancestor_levels, descendant_levels, include_siblings): """Gets a portion of the hierarchy for the given repository. arg: repository_id (osid.id.Id): the ``Id`` to query arg: ancestor_levels (cardinal): the maximum number of ancestor levels to include. A value of 0 returns n... |
osid.resource.BinHierarchySession.get_bin_nodes return objects.RepositoryNode(self.get_repository_node_ids( repository_id=repository_id, ancestor_levels=ancestor_levels, descendant_levels=descendant_levels, include_siblings=include_siblings)._my_map, runtime=self._runtime, proxy=self._proxy) |
def add_root_repository(self, repository_id): """Adds a root repository. arg: repository_id (osid.id.Id): the ``Id`` of a repository raise: AlreadyExists - ``repository_id`` is already in hierarchy raise: NotFound - ``repository_id`` not found raise: NullArgument - ``repository_id`` is ``null`` raise: OperationFailed -... |
def remove_root_repository(self, repository_id): """Removes a root repository. arg: repository_id (osid.id.Id): the ``Id`` of a repository raise: NotFound - ``repository_id`` not a root raise: NullArgument - ``repository_id`` is ``null`` raise: OperationFailed - unable to complete request raise: PermissionDenied - auth... |
def add_child_repository(self, repository_id, child_id): """Adds a child to a repository. arg: repository_id (osid.id.Id): the ``Id`` of a repository arg: child_id (osid.id.Id): the ``Id`` of the new child raise: AlreadyExists - ``repository_id`` is already a parent of ``child_id`` raise: NotFound - ``repository_id`` o... |
def remove_child_repository(self, repository_id, child_id): """Removes a child from a repository. arg: repository_id (osid.id.Id): the ``Id`` of a repository arg: child_id (osid.id.Id): the ``Id`` of the new child raise: NotFound - ``repository_id`` not a parent of ``child_id`` raise: NullArgument - ``repository_id`` o... |
def remove_child_repositories(self, repository_id): """Removes all children from a repository. arg: repository_id (osid.id.Id): the ``Id`` of a repository raise: NotFound - ``repository_id`` not in hierarchy raise: NullArgument - ``repository_id`` is ``null`` raise: OperationFailed - unable to complete request raise: P... |
def add_cron(self, client, event, seconds="*", minutes="*", hours="*"): """Add a cron entry. The arguments for this event are: 1. The name of the event to dispatch when the cron fires. 2. What seconds to trigger on, as a timespec (default "*") 3. What minutes to trigger on, as a timespec (default "*") 4. What hours to ... |
for the unit. "?" - specifies a random value from 0 to the unit max. "?/X" - specifies all multiples of X for this unit, randomly offset by a fixed amount (e.g. ?/15 might become 4,19,34,49). "*" - specifies all values for the unix from 0 to max. "*/X" - specifies all multiples of X for the unit. Any number of these ca... |
def remove_cron(self, client, event): """Remove a cron entry by event name.""" for index, cron in enumerate(self.crons): if cron.event == event: _log.info("De-registering cron '%s'.", event) # Yes, we're modifying the list we're iterating over, but # we immediate stop iterating so it's okay. self.crons.pop(index) break... |
def exception_handler(exctype, value, traceback): """ This exception handler catches KeyboardInterrupt to cancel the Runner and also stops the Runner in case of an error. """ if exctype == KeyboardInterrupt: pypro.console.out('') # Adds a new line after Ctrl+C character pypro.console.err('Canceled') elif exctype == Pyp... |
def run(self): """ Starts recipes execution. """ self._prepare() for recipe in self._recipes: run_recipe = True # Ask user whether to run current recipe if -y argument is not specified if not self.arguments.yes: run_recipe = pypro.console.ask_bool('Run %s.%s' % (recipe.module, recipe.name), "yes") if run_recipe: recipe... |
def name(self): """ Returns the recipe name which is its class name without package. """ if not hasattr(self, '_name'): self._name = re.search('[a-z]+\.([a-z]+)\.([a-z]+)', str(self.__class__), re.IGNORECASE).group(2) return self._name |
def module(self): """ Returns the module name of Recipe. This actually represents the file basename of a recipe. """ if not hasattr(self, '_module'): self._module = re.search('[a-z]+\.([a-z]+)\.([a-z]+)', str(self.__class__), re.IGNORECASE).group(1) return self._module |
def settings(self): """ Loads the recipe settings file which is locate in: ./settings/{recipe_package}.ini """ settings_file = os.path.join(os.getcwd(), 'settings', self.module.lower() + '.ini') # Loads the settings file once. if (not hasattr(self, '_settings') or self._settings is None) and os.path.isfile(settings_fil... |
def _reverse_rounding_method(method): """ Reverse meaning of ``method`` between positive and negative. """ if method is RoundingMethods.ROUND_UP: return RoundingMethods.ROUND_DOWN if method is RoundingMethods.ROUND_DOWN: return RoundingMethods.ROUND_UP if method is RoundingMethods.ROUND_HALF_UP: return RoundingMethods.... |
def from_rational( cls, value, to_base, precision=None, method=RoundingMethods.ROUND_DOWN ): """ Convert rational value to a base. :param Rational value: the value to convert :param int to_base: base of result, must be at least 2 :param precision: number of digits in total or None :type precision: int or NoneType :para... |
return (Radix(0, [], non_repeating_part, [], to_base), 0) if value < 0: sign = -1 else: sign = 1 div_method = method if sign == -1: value = abs(value) div_method = cls._reverse_rounding_method(method) numerator = Nats.convert_from_int(value.numerator, to_base) denominator = Nats.convert_from_int(value.denominator, to_b... |
def round_to_int(value, method): """ Round ``value`` to an int according to ``method``. :param Rational value: the value to round :param method: the rounding method (of RoundingMethods.METHODS()) :returns: rounded value and relation of rounded value to actual value. :rtype: (int * int) Complexity: O(1) """ # pylint: di... |
return (lower, -1) if delta <= Fraction(1, 2) else (upper, 1) if method is RoundingMethods.ROUND_HALF_ZERO: if lower < 0: return (upper, 1) if delta >= Fraction(1, 2) else (lower, -1) return (lower, -1) if delta <= Fraction(1, 2) else (upper, 1) raise BasesValueError(method, "method") |
def _validate( # pylint: disable=too-many-arguments cls, sign, integer_part, non_repeating_part, repeating_part, base ): """ Check if radix is valid. :param int sign: -1, 0, or 1 as appropriate :param integer_part: the part on the left side of the radix :type integer_part: list of int :param non_repeating_part: non rep... |
x in non_repeating_part): return BasesValueError( non_repeating_part, "non_repeating_part", "values must be between 0 and %s" % base ) if any(x < 0 or x >= base for x in repeating_part): return BasesValueError( repeating_part, "repeating_part", "values must be between 0 and %s" % base ) if base < 2: return BasesValueEr... |
def _repeat_length(cls, part): """ The length of the repeated portions of ``part``. :param part: a number :type part: list of int :returns: the first index at which part repeats :rtype: int If part does not repeat, result is the length of part. Complexity: O(len(part)^2) """ repeat_len = len(part) if repeat_len == 0: r... |
def _canonicalize_fraction(cls, non_repeating, repeating): """ If the same fractional value can be represented by stripping repeating part from ``non_repeating``, do it. :param non_repeating: non repeating part of fraction :type non_repeating: list of int :param repeating: repeating part of fraction :type repeating: li... |
indices if non_repeating[(i - repeat_len):i] != repeating ) # for remaining, find partial match and shift repeating # * for [6, 2, 1, 2], [1, 2] initial end is 2, result is [6], [2, 1] indices = range(min(repeat_len - 1, end), 0, -1) index = next( (i for i in indices \ if repeating[-i:] == non_repeating[(end-i):end]), ... |
def getString(self, config, relation=0): """ Return a representation of a Radix according to config. :param DisplayConfig config: configuration :param int relation: the relation of this value to actual value """ return String(config, self.base).xform(self, relation) |
def as_rational(self): """ Return this value as a Rational. :returns: this radix as a rational :rtype: Rational """ (denominator, numerator) = \ NatDivision.undivision( self.integer_part, self.non_repeating_part, self.repeating_part, self.base ) result = Fraction( Nats.convert_to_int(numerator, self.base), Nats.convert... |
def as_int(self, method): """ This value as an int, rounded according to ``method``. :param method: rounding method :raises BasesValueError: on bad parameters :returns: corresponding int value :rtype: int """ (new_radix, relation) = self.rounded(0, method) value = Nats.convert_to_int(new_radix.integer_part, new_radix.b... |
def in_base(self, base): """ Return value in ``base``. :returns: Radix in ``base`` :rtype: Radix :raises ConvertError: if ``base`` is less than 2 """ if base == self.base: return copy.deepcopy(self) (result, _) = Radices.from_rational(self.as_rational(), base) return result |
def _conditional_toward_zero(method, sign): """ Whether to round toward zero. :param method: rounding method :type method: element of RoundingMethods.METHODS() :param int sign: -1, 0, or 1 as appropriate Complexity: O(1) """ return method is RoundingMethods.ROUND_HALF_ZERO or \ (method is RoundingMethods.ROUND_HALF_DOW... |
def _increment(sign, integer_part, non_repeating_part, base): """ Return an increment radix. :param int sign: -1, 0, or 1 as appropriate :param integer_part: the integer part :type integer_part: list of int :param non_repeating_part: the fractional part :type non_repeating_part: list of int :param int base: the base :r... |
def roundFractional(cls, value, precision, method): """ Round to precision as number of digits after radix. :param Radix value: value to round :param int precision: number of digits in total :param method: rounding method :raises BasesValueError: on bad parameters Precondition: Radix is valid and canonical Complexity: ... |
value.sign, value.integer_part, non_repeating_part, value.base ) if all(x == 0 for x in value.non_repeating_part[precision:]) and \ value.repeating_part == []: return (truncated(), 0) if method is RoundingMethods.ROUND_TO_ZERO: return (truncated(), -1 * value.sign) if method is RoundingMethods.ROUND_DOWN: return (trunc... |
def get_next_property(self): """Gets the next ``Property`` in this list. :return: the next ``Property`` in this list. The ``has_next()`` method should be used to test that a next ``Property`` is available before calling this method. :rtype: ``osid.Property`` :raise: ``IllegalState`` -- no more elements available in thi... |
def load_edgegrid_client_settings(): '''Load Akamai EdgeGrid configuration returns a (hostname, EdgeGridAuth) tuple from the following locations: 1. Values specified directly in the Django settings:: AKAMAI_CCU_CLIENT_SECRET AKAMAI_CCU_HOST AKAMAI_CCU_ACCESS_TOKEN AKAMAI_CCU_CLIENT_TOKEN 2. An edgerc file specified in ... |
= EdgeGridAuth.from_edgerc(edgerc, section=edgerc_section) return host, auth raise InvalidAkamaiConfiguration('Cannot find Akamai client configuration!') |
def add(self, urls): """ Add the provided urls to this purge request The urls argument can be a single string, a list of strings, a queryset or model instance. Models must implement `get_absolute_url()`. """ if isinstance(urls, (list, tuple)): self.urls.extend(urls) elif isinstance(urls, basestring): self.urls.append(u... |
def purge(self): """Submit purge request(s) to the CCU API Since a purge call may require multiple API requests and may trigger rate-limiting this method uses a generator to provide the results of each request, allowing you to communicate request progress or implement a custom rate-limiting response:: for url_batch, re... |
if not isinstance(next_url, bytes): next_url = next_url.encode('utf-8') batch.append(next_url) batch_size += len(next_url) if batch: data = {'objects': batch} logger.debug('Requesting Akamai purge %d URLs', len(batch)) response = requests.post(url=purge_url, auth=self.auth, data=json.dumps(data), headers={'Content-Type... |
def purge_all(self, rate_limit_delay=60): '''Purge all pending URLs, waiting for API rate-limits if necessary!''' for batch, response in self.purge(): if response.status_code == 507: details = response.json().get('detail', '<response did not contain "detail">') logger.info('Will retry request in %d seconds due to API r... |
def _init_metadata(self): """stub""" self._objective_bank_id_metadata = { 'element_id': Id(self.my_osid_object_form._authority, self.my_osid_object_form._namespace, 'objective_bank_id'), 'element_label': 'Objective Bank Id', 'instructions': 'accepts a valid OSID Id string', 'required': False, 'read_only': False, 'linke... |
def clear_objective_bank_id(self): """stub""" if (self.get_objective_bank_id_metadata().is_read_only() or self.get_objective_bank_id_metadata().is_required()): raise NoAccess() self.my_osid_object_form._my_map['objectiveBankId'] = '' |
def get_item(self, item_id): """ see if this is a magic item id (i.e. questionId). If so, grab the item and set the params. If not, just pass through to the original Mongo ItemLookupSession :param item_id: :return: """ authority = item_id.authority mgr = self._get_provider_manager('ASSESSMENT', local=True) if self._pro... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.