def _unfold_map(self, display_text_map): """Parses a display text dictionary map.""" from ..type.primitives import Type lt_identifier = Id(display_text_map['languageTypeId']).get_identifier() st_identifier = Id(display_text_map['scriptTypeId']).get_identifier() ft_identifier = Id(display_text_map['formatTypeId']).get_identifier() try: self._language_type = Type( **language_types.get_type_data(lt_identifier)) except AttributeError: raise NotFound('Language Type: ' + lt_identifier) # or move on to another source try: self._script_type = Type( **script_types.get_type_data(st_identifier)) except AttributeError: raise NotFound('Script Type: ' + st_identifier) # or move on to another source try: self._format_type = Type( **format_types.get_type_data(ft_identifier)) except AttributeError: raise NotFound('Format Type: ' + ft_identifier) # or move on to another source self._text = display_text_map['text']
def get_type_data(name): """Return dictionary representation of type. Can be used to initialize primordium.type.primitives.Type """ name = name.upper() if name in ISO_CURRENCY_TYPES: article = 'the ' type_name = ISO_CURRENCY_TYPES[name] elif name in ISO_CURRENCY_ELEMENT_TYPES: article = '' type_name = ISO_CURRENCY_ELEMENT_TYPES[name] else: raise NotFound('Currency Type: ' + name) return { 'authority': 'ISO', 'namespace': '4217', 'identifier': name, 'domain': 'ISO Currency Types', 'display_name': type_name + ' Currency Type', 'display_label': type_name, 'description': ('The ISO currency type for ' + article + type_name + '.') }
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': 'okapia.net', 'namespace': 'string match types', 'identifier': name, 'domain': 'String Match Types', 'display_name': STRING_MATCH_TYPES[name] + ' String Match Type', 'display_label': STRING_MATCH_TYPES[name], 'description': ('The string match type for the ' + STRING_MATCH_TYPES[name]) } except KeyError: raise NotFound('String Type: ' + name)
def get_type_data(name): """Return dictionary representation of type. Can be used to initialize primordium.type.primitives.Type """ name = name.upper() if name in CELESTIAL_TIME_TYPES: namespace = 'time' domain = 'Celestial Time Systems' time_name = CELESTIAL_TIME_TYPES[name] elif name in EARTH_TIME_TYPES: namespace = 'time' domain = 'Earth Time Systems' time_name = EARTH_TIME_TYPES[name] elif name in SUPER_FUN_TIME_TYPES: namespace = 'time' domain = 'Alternative Time Systems' time_name = SUPER_FUN_TIME_TYPES[name] else: raise NotFound('Time Type: ' + name) return { 'authority': 'okapia.net', 'namespace': namespace, 'identifier': name, 'domain': domain, 'display_name': time_name + ' Time Type', 'display_label': time_name, 'description': ('The time type for ' + time_name + ' time.') }
def get_type_data(name): """Return dictionary representation of type. Can be used to initialize primordium.type.primitives.Type """ name = name.upper() if name in CALENDAR_TYPES: domain = 'Calendar Types' calendar_name = CALENDAR_TYPES[name] elif name in ANCIENT_CALENDAR_TYPES: domain = 'Ancient Calendar Types' calendar_name = ANCIENT_CALENDAR_TYPES[name] elif name in ALTERNATE_CALENDAR_TYPES: domain = 'Alternative Calendar Types' calendar_name = ALTERNATE_CALENDAR_TYPES[name] else: raise NotFound('Calendar Type: ' + name) return { 'authority': 'okapia.net', 'namespace': 'calendar', 'identifier': name, 'domain': domain, 'display_name': calendar_name + ' Calendar Type', 'display_label': calendar_name, 'description': ('The time type for the ' + calendar_name + ' calendar.') }
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': 'okapia.net', 'namespace': 'TextFormats', 'identifier': name, 'domain': 'DisplayText Formats', 'display_name': FORMAT_TYPES[name] + ' Format Type', 'display_label': FORMAT_TYPES[name], 'description': ('The display text format type for the ' + FORMAT_TYPES[name] + ' format.') } except KeyError: raise NotFound('Format Type:' + name)
def get_type_data(name): """Return dictionary representation of type. Can be used to initialize primordium.type.primitives.Type """ name = name.upper() if name in ISO_LANGUAGE_CODES: name = ISO_LANGUAGE_CODES[name] if name in ISO_MAJOR_LANGUAGE_TYPES: namespace = '639-2' lang_name = ISO_MAJOR_LANGUAGE_TYPES[name] elif name in ISO_OTHER_LANGUAGE_TYPES: namespace = '639-3' lang_name = ISO_OTHER_LANGUAGE_TYPES[name] else: raise NotFound('Language Type: ' + name) return { 'authority': 'ISO', 'namespace': namespace, 'identifier': name, 'domain': 'DisplayText Languages', 'display_name': lang_name + ' Language Type', 'display_label': lang_name, 'description': ('The display text language type for the ' + lang_name + ' language.') }
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': 'unit system', 'identifier': name, 'domain': 'Unit System Types', 'display_name': JEFFS_UNIT_SYSTEM_TYPES[name] + ' Unit System Type', 'display_label': JEFFS_UNIT_SYSTEM_TYPES[name], 'description': ('The unit system type for the ' + JEFFS_UNIT_SYSTEM_TYPES[name] + ' System') } except KeyError: raise NotFound('Unit System Type: ' + name)
def get_type_data(name): """Return dictionary representation of type. Can be used to initialize primordium.type.primitives.Type """ name = name.upper() if name in CELESTIAL_COORDINATE_TYPES: domain = 'Celestial Coordinate Systems' coordinate_name = CELESTIAL_COORDINATE_TYPES[name] elif name in GEOGRAPHIC_COORDINATE_TYPES: domain = 'Geographic Coordinate Systems' coordinate_name = GEOGRAPHIC_COORDINATE_TYPES[name] else: raise NotFound('Coordinate Type' + name) return { 'authority': 'okapia.net', 'namespace': 'coordinate', 'identifier': name, 'domain': domain, 'display_name': coordinate_name + ' Type', 'display_label': coordinate_name, 'description': ('The type for the ' + coordinate_name + ' System.') }
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[name] + ' Time Format Type', 'display_label': JEFFS_TIME_FORMAT_TYPES[name], 'description': ('The time format type for ' + JEFFS_TIME_FORMAT_TYPES[name]) } except KeyError: raise NotFound('Time Format Type: ' + name)
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': 'ISO', 'namespace': '15924', 'identifier': name, 'domain': 'ISO Script Types', 'display_name': ISO_SCRIPT_TYPES[name] + ' Script Type', 'display_label': ISO_SCRIPT_TYPES[name], 'description': ('The display text script type for the ' + ISO_SCRIPT_TYPES[name] + ' script.') } except KeyError: raise NotFound('Script Type:' + name)
def get_answer_for_response(self, response): response_set = set([str(c) for c in response.get_choice_ids()]) for answer in self.my_osid_object.get_answers(): if response_set == set([str(c) for c in answer.get_choice_ids()]): return answer for answer in self.my_osid_object.get_wrong_answers(): if response_set == set([str(c) for c in answer.get_choice_ids()]): return answer raise NotFound('no matching answer found for response')
def order_ids(new_id_list, old_idstr_list): compare = (lambda new_id_list, old_idstr_list: collections.Counter( new_id_list) == collections.Counter(old_idstr_list)) new_idstr_list = [] for id_ in new_id_list: new_idstr_list.append(str(id_)) if compare(new_idstr_list, old_idstr_list): return new_idstr_list else: raise NotFound()
def get_type_data(self, name): """Return dictionary representation of type.""" try: return { 'authority': 'DLKIT', 'namespace': 'relationship.Relationship', 'identifier': name.lower(), 'domain': 'Generic Types', 'display_name': name.title() + ' Type', 'display_label': name.title(), 'description': ('The ' + name.title() + ' Type.') } except IndexError: raise NotFound('RelationshipType: ' + name.title())
def get_type_data(self, name): """Return dictionary representation of type.""" try: return { 'authority': 'DLKIT.MIT.EDU', 'namespace': 'NoneType', 'identifier': name, 'domain': 'Generic Types', 'display_name': self.none_types[name] + ' Type', 'display_label': self.none_types[name], 'description': ('The ' + self.none_types[name] + ' Type. This type indicates that no type is specified.') } except IndexError: raise NotFound('NoneType: ' + name)
def get_type_data(self, name): """Return dictionary representation of type.""" try: return { 'authority': 'DLKIT.MIT.EDU', 'namespace': 'GenusType', 'identifier': name, 'domain': 'Generic Types', 'display_name': self.generic_types[name] + ' Generic Type', 'display_label': self.generic_types[name], 'description': ('The ' + self.generic_types[name] + ' Type. This type has no symantic meaning.') } except IndexError: raise NotFound('GenusType: ' + name)
def get_type_data(name): """Return dictionary representation of type. Can be used to initialize primordium.type.primitives.Type """ try: return { 'authority': 'birdland.mit.edu', 'namespace': 'Genus Types', 'identifier': name, 'domain': 'Generic Types', 'display_name': OBJECTIVE_TYPES[name] + ' Genus Type', 'display_label': OBJECTIVE_TYPES[name], 'description': ('The ' + OBJECTIVE_TYPES[name] + ' Genus Type.') } except IndexError: raise NotFound('Objective Genus Type: ' + name)
def clear_preview(self): """stub""" try: rm = self.my_osid_object._get_provider_manager('REPOSITORY') except AttributeError: rm = self.my_osid_object_form._get_provider_manager('REPOSITORY') try: aas = rm.get_asset_admin_session_for_repository( Id(self.my_osid_object._my_map['assignedBankIds'][0])) except AttributeError: # for update forms aas = rm.get_asset_admin_session_for_repository( Id(self.my_osid_object_form._my_map['assignedBankIds'][0])) if 'preview' not in self.my_osid_object_form._my_map['fileIds']: raise NotFound() aas.delete_asset( Id(self.my_osid_object_form._my_map['fileIds']['preview'] ['assetId'])) del self.my_osid_object_form._my_map['fileIds']['preview']
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': 'okapia.net', 'namespace': 'heading', 'identifier': name, 'domain': 'Headings', 'display_name': HEADING_TYPES[name] + ' Heading Type', 'display_label': HEADING_TYPES[name], 'description': ('The heading type for the ' + HEADING_TYPES[name] + ' heading.') } except KeyError: raise NotFound('Heading Type:' + name)
def get_answer_for_response(self, response): for answer in self.my_osid_object.get_answers(): if self._is_match(response, answer): return answer wrong_answers = None try: wrong_answers = list(self.my_osid_object.get_wrong_answers()) except AttributeError: pass else: for answer in wrong_answers: if self._is_match(response, answer): return answer # also look for generic incorrect answer if wrong_answers is not None: for answer in wrong_answers: if len(list(answer.get_inline_choice_ids().keys())) == 0: return answer raise NotFound('no matching answer found for response')
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': 'gnu.org', 'namespace': 'Basic Numeric Formats', 'identifier': name, 'domain': 'Numeric Format Types', 'display_name': GNU_BASIC_NUMERIC_FORMAT_TYPES[name] + ' Numeric Format Type', 'display_label': GNU_BASIC_NUMERIC_FORMAT_TYPES[name], 'description': ('The type for the ' + GNU_BASIC_NUMERIC_FORMAT_TYPES[name] + ' numeric format.') } except KeyError: raise NotFound('NumericFormat Type: ' + name)
def get_answer_for_response(self, response): for answer in self.my_osid_object.get_answers(): if self._is_match(response, answer): return answer wrong_answers = None try: wrong_answers = list(self.my_osid_object.get_wrong_answers()) except AttributeError: pass else: for answer in wrong_answers: if self._is_match(response, answer): return answer # also look for generic incorrect answer if wrong_answers is not None: for answer in wrong_answers: if not answer.has_decimal_value(): return answer raise NotFound('no matching answer found for response')
def get_type_data(self, name): """gets language type default data dictionary""" if name == 'DEFAULT': return LANGUAGETYPE else: raise NotFound(name + 'Language Type')
def get_type_data(self, name): """gets script type default data dictionary""" if name == 'DEFAULT': return SCRIPTTYPE else: raise NotFound(name + 'Script Type')
def get_type_data(self, name): """Return dictionary representation of type.""" if name == 'DEFAULT': return FORMATTYPE else: raise NotFound('DEFAULT Format Type')
def get_type_data(self, name): """Return dictionary representation of type.""" if name == 'DEFAULT': return SCRIPTTYPE else: raise NotFound('DEFAULT Script Type')
def get_type_data(self, name): """Return dictionary representation of type.""" if name == 'DEFAULT': return LANGUAGETYPE else: raise NotFound('DEFAULT Language Type')
def get_type_data(self, name): """gets format type default data dictionary""" if name == 'DEFAULT': return FORMATTYPE else: raise NotFound(name + 'Format Type')
def clear_solution(self): """stub""" if 'solution' not in self.my_osid_object_form._my_map: raise NotFound() self.my_osid_object_form._my_map['solution'] = \ dict(self._solution_metadata['default_string_values'][0])