diff --git a/nautilus/flask_ext.py b/nautilus/flask_ext.py index bf10594..e85fc70 100644 --- a/nautilus/flask_ext.py +++ b/nautilus/flask_ext.py @@ -147,7 +147,7 @@ def _r_GetCapabilities(self, urn, inv): :param urn: :return: """ - return self.endpoint.getCapabilities(inventory=inv, urn=urn).strip(), 200, {"content-type": "text/xml"} + return self.endpoint.getCapabilities(inventory=inv, urn=urn).strip(), 200, {"content-type": "application/xml"} def _r_GetPassage(self, urn, inv): """ @@ -155,7 +155,7 @@ def _r_GetPassage(self, urn, inv): :param urn: :return: """ - return self.endpoint.getPassage(inventory=inv, urn=urn).strip(), 200, {"content-type": "text/xml"} + return self.endpoint.getPassage(inventory=inv, urn=urn).strip(), 200, {"content-type": "application/xml"} def _r_GetPassagePlus(self, urn, inv): """ @@ -163,7 +163,7 @@ def _r_GetPassagePlus(self, urn, inv): :param urn: :return: """ - return self.endpoint.getPassagePlus(inventory=inv, urn=urn).strip(), 200, {"content-type": "text/xml"} + return self.endpoint.getPassagePlus(inventory=inv, urn=urn).strip(), 200, {"content-type": "application/xml"} def _r_GetValidReff(self, urn, inv, level): """ @@ -171,7 +171,7 @@ def _r_GetValidReff(self, urn, inv, level): :param urn: :return: """ - return self.endpoint.getValidReff(inventory=inv, urn=urn, level=level).strip(), 200, {"content-type": "text/xml"} + return self.endpoint.getValidReff(inventory=inv, urn=urn, level=level).strip(), 200, {"content-type": "application/xml"} def _r_GetPrevNext(self, urn, inv): """ @@ -179,7 +179,7 @@ def _r_GetPrevNext(self, urn, inv): :param urn: :return: """ - return self.endpoint.getPrevNextUrn(inventory=inv, urn=urn).strip(), 200, {"content-type": "text/xml"} + return self.endpoint.getPrevNextUrn(inventory=inv, urn=urn).strip(), 200, {"content-type": "application/xml"} def _r_GetFirstUrn(self, urn, inv): """ @@ -187,7 +187,7 @@ def _r_GetFirstUrn(self, urn, inv): :param urn: :return: """ - return self.endpoint.getFirstUrn(inventory=inv, urn=urn).strip(), 200, {"content-type": "text/xml"} + return self.endpoint.getFirstUrn(inventory=inv, urn=urn).strip(), 200, {"content-type": "application/xml"} def _r_GetLabel(self, urn, inv): """ @@ -195,4 +195,4 @@ def _r_GetLabel(self, urn, inv): :param urn: :return: """ - return self.endpoint.getLabel(inventory=inv, urn=urn).strip(), 200, {"content-type": "text/xml"} + return self.endpoint.getLabel(inventory=inv, urn=urn).strip(), 200, {"content-type": "application/xml"} diff --git a/nautilus/inventory/local.py b/nautilus/inventory/local.py index baa9547..b8be41b 100644 --- a/nautilus/inventory/local.py +++ b/nautilus/inventory/local.py @@ -61,50 +61,54 @@ def __parseDirectories(self, resource): for folder in resource: textgroups = glob("{base_folder}/data/*/__cts__.xml".format(base_folder=folder)) for __cts__ in textgroups: - with open(__cts__) as __xml__: - textgroup = TextGroup(resource=__xml__) - textgroup.urn = URN(textgroup.xml.get("urn")) - self.resource.textgroups[str(textgroup.urn)] = textgroup - - for __subcts__ in glob("{parent}/*/__cts__.xml".format(parent=os.path.dirname(__cts__))): - with open(__subcts__) as __xml__: - work = Work( - resource=__xml__, - parents=[self.resource.textgroups[str(textgroup.urn)]] - ) - work.urn = URN(work.xml.get("urn")) - self.resource.textgroups[str(textgroup.urn)].works[str(work.urn)] = work - - for __text__ in self.resource.textgroups[str(textgroup.urn)].works[str(work.urn)].texts.values(): - __text__.path = "{directory}/{textgroup}.{work}.{version}.xml".format( - directory=os.path.dirname(__subcts__), - textgroup=__text__.urn[3], - work=__text__.urn[4], - version=__text__.urn[5] - ) - if os.path.isfile(__text__.path): - try: - with open(__text__.path) as f: - t = Text(resource=f) - cites = list() - for cite in [c for c in t.citation][::-1]: - if len(cites) >= 1: - cites.append(Citation( - xpath=cite.xpath.replace("'", '"'), - scope=cite.scope.replace("'", '"'), - name=cite.name, - child=cites[-1] - )) - else: - cites.append(Citation( - xpath=cite.xpath.replace("'", '"'), - scope=cite.scope.replace("'", '"'), - name=cite.name - )) - __text__.citation = cites[-1] - except Exception: - print(__text__.path + " does not accept parsing at some level (most probably citation) ") - self.__texts__.append(__text__) + try: + with open(__cts__) as __xml__: + textgroup = TextGroup(resource=__xml__) + textgroup.urn = URN(textgroup.xml.get("urn")) + self.resource.textgroups[str(textgroup.urn)] = textgroup + + for __subcts__ in glob("{parent}/*/__cts__.xml".format(parent=os.path.dirname(__cts__))): + with open(__subcts__) as __xml__: + work = Work( + resource=__xml__, + parents=[self.resource.textgroups[str(textgroup.urn)]] + ) + work.urn = URN(work.xml.get("urn")) + + self.resource.textgroups[str(textgroup.urn)].works[str(work.urn)] = work + + for __text__ in self.resource.textgroups[str(textgroup.urn)].works[str(work.urn)].texts.values(): + __text__.path = "{directory}/{textgroup}.{work}.{version}.xml".format( + directory=os.path.dirname(__subcts__), + textgroup=__text__.urn[3], + work=__text__.urn[4], + version=__text__.urn[5] + ) + if os.path.isfile(__text__.path): + try: + with open(__text__.path) as f: + t = Text(resource=f) + cites = list() + for cite in [c for c in t.citation][::-1]: + if len(cites) >= 1: + cites.append(Citation( + xpath=cite.xpath.replace("'", '"'), + scope=cite.scope.replace("'", '"'), + name=cite.name, + child=cites[-1] + )) + else: + cites.append(Citation( + xpath=cite.xpath.replace("'", '"'), + scope=cite.scope.replace("'", '"'), + name=cite.name + )) + __text__.citation = cites[-1] + except Exception: + print(__text__.path + " does not accept parsing at some level (most probably citation) ") + self.__texts__.append(__text__) + except Exception: + print("Error parsing " + __cts__) return self.resource, self.__texts__