From 544bb2f64d41cdcfaf6ef7bc4713c647465015d5 Mon Sep 17 00:00:00 2001 From: raffazizzi Date: Tue, 16 Aug 2016 16:27:29 -0400 Subject: [PATCH 01/13] Added basic support for highlight option (API v1.0.1 --- Omas/omas/meislicer.py | 338 +++++++++++++++++++++++------------------ 1 file changed, 188 insertions(+), 150 deletions(-) diff --git a/Omas/omas/meislicer.py b/Omas/omas/meislicer.py index 9a75497..8732279 100644 --- a/Omas/omas/meislicer.py +++ b/Omas/omas/meislicer.py @@ -31,6 +31,18 @@ def slice(self): """ Return a modified MEI doc containing the selected notation provided a EMA expression of measures, staves, and beats.""" + # if highlighting, create annot + print self.ema_exp.completenessOptions + if "highlight" in self.ema_exp.completenessOptions: + # create annotation element for highlights + last_score_el = self.doc.getElementsByName("score")[-1] + annot = MeiElement("annot") + annot.addAttribute("type", "ema_highlight") + annot.addAttribute("plist", "") + last_score_el.addChild(annot) + + self.highlight_el = annot; + # parse general beats information self.beatsInfo = self.docInfo["beats"] self.timeChanges = self.beatsInfo.keys() @@ -46,24 +58,25 @@ def slice(self): # Recursively remove remaining data in between # measure ranges before returning modified doc - # First remove measures in between - to_remove = [] - middle_boundaries = boundary_mm[1:-1] - for bm in middle_boundaries[::2]: - i = middle_boundaries.index(bm) - try: - start_m = self.measures[bm.idx-1] - start_m_pos = start_m.getPositionInDocument() - end_m = self.measures[middle_boundaries[i+1].idx-1] - end_m_pos = end_m.getPositionInDocument() - for el in self.flat_doc[start_m_pos+1:end_m_pos]: - if el.hasAncestor("measure"): - if el.getAncestor("measure").getId() != start_m.getId(): + if "highlight" not in self.ema_exp.completenessOptions: + # First remove measures in between + to_remove = [] + middle_boundaries = boundary_mm[1:-1] + for bm in middle_boundaries[::2]: + i = middle_boundaries.index(bm) + try: + start_m = self.measures[bm.idx-1] + start_m_pos = start_m.getPositionInDocument() + end_m = self.measures[middle_boundaries[i+1].idx-1] + end_m_pos = end_m.getPositionInDocument() + for el in self.flat_doc[start_m_pos+1:end_m_pos]: + if el.hasAncestor("measure"): + if el.getAncestor("measure").getId() != start_m.getId(): + to_remove.append(el) + else: to_remove.append(el) - else: - to_remove.append(el) - except IndexError: - pass + except IndexError: + pass m_first = self.measures[boundary_mm[0].idx-1] m_final = self.measures[boundary_mm[-1].idx-1] @@ -132,40 +145,41 @@ def _removeUnusedStaffDefs(scoredef, start_ema_m): break # Recursively remove elements before and after selected measures - _removeBefore(m_first) - _removeAfter(m_final) - - # Compute closest score definition to start measure of each range - b_scoreDef = first_scoreDef - for i, bm in enumerate(boundary_mm[::2]): # list comprehension get only start mm - b_measure = self.measures[bm.idx-1] - preceding = self.flat_doc_static[:b_measure.getPositionInDocument()] - - for el in reversed(preceding): - if el.getName() == "scoreDef": - try: - s_id = b_scoreDef.getId() - if not s_id == el.getId(): + if "highlight" not in self.ema_exp.completenessOptions: + _removeBefore(m_first) + _removeAfter(m_final) + + # Compute closest score definition to start measure of each range + b_scoreDef = first_scoreDef + for i, bm in enumerate(boundary_mm[::2]): # list comprehension get only start mm + b_measure = self.measures[bm.idx-1] + preceding = self.flat_doc_static[:b_measure.getPositionInDocument()] + + for el in reversed(preceding): + if el.getName() == "scoreDef": + try: + s_id = b_scoreDef.getId() + if not s_id == el.getId(): + b_scoreDef = el + # Re-attach computed score definition + sd_copy = MeiElement(b_scoreDef) + _removeUnusedStaffDefs(sd_copy, bm) + b_measure.getParent().addChildBefore(b_measure, sd_copy) + except AttributeError: b_scoreDef = el - # Re-attach computed score definition - sd_copy = MeiElement(b_scoreDef) - _removeUnusedStaffDefs(sd_copy, bm) - b_measure.getParent().addChildBefore(b_measure, sd_copy) - except AttributeError: - b_scoreDef = el - break + break - for el in to_remove: - el.getParent().removeChild(el) + for el in to_remove: + el.getParent().removeChild(el) - if "raw" in self.ema_exp.completenessOptions: - lca = _findLowestCommonAncestor(m_first, m_final) - self.doc.setRootElement(lca) + if "raw" in self.ema_exp.completenessOptions: + lca = _findLowestCommonAncestor(m_first, m_final) + self.doc.setRootElement(lca) - # re-attach computed score definition if required by - # completeness = signature - if "signature" in self.ema_exp.completenessOptions: - m_first.getParent().addChildBefore(m_first, first_scoreDef) + # re-attach computed score definition if required by + # completeness = signature + if "signature" in self.ema_exp.completenessOptions: + m_first.getParent().addChildBefore(m_first, first_scoreDef) return self.doc @@ -399,116 +413,140 @@ def _remove(el): break # Remove elements marked for removal - for el in marked_for_removal: - el.getParent().removeChild(el) - - # Replace elements marked as spaces with actual spaces, - # unless completion = nospace, then remove the elements. - for el in marked_as_space: - parent = el.getParent() - if "nospace" not in self.ema_exp.completenessOptions: - space = MeiElement("space") - space.setId(el.id) - space.addAttribute(el.getAttribute("dur")) - if el.getAttribute("dots"): - space.addAttribute(el.getAttribute("dots")) - elif el.getChildrenByName("dot"): - dots = str(len(el.getChildrenByName("dot"))) - space.addAttribute(MeiAttribute("dots", dots)) - parent.addChildBefore(el, space) - el.getParent().removeChild(el) + if "highlight" not in self.ema_exp.completenessOptions: + for el in marked_for_removal: + el.getParent().removeChild(el) + + # Replace elements marked as spaces with actual spaces, + # unless completion = nospace, then remove the elements. + for el in marked_as_space: + parent = el.getParent() + if "nospace" not in self.ema_exp.completenessOptions: + space = MeiElement("space") + space.setId(el.id) + space.addAttribute(el.getAttribute("dur")) + if el.getAttribute("dots"): + space.addAttribute(el.getAttribute("dots")) + elif el.getChildrenByName("dot"): + dots = str(len(el.getChildrenByName("dot"))) + space.addAttribute(MeiAttribute("dots", dots)) + parent.addChildBefore(el, space) + el.getParent().removeChild(el) + else: + for el in marked_as_selected: + # add to list + if self.highlight_el: + cur_plist = self.highlight_el.getAttribute("plist").getValue() + space = "" + if len(cur_plist) > 0: + space = " " + val = cur_plist + space + "#" + el.getId() + self.highlight_el.addAttribute("plist", val) else: - # Remove this staff and its attached events - staff.getParent().removeChild(staff) + if "highlight" not in self.ema_exp.completenessOptions: + # Remove this staff and its attached events + staff.getParent().removeChild(staff) - for el in list(events): - if self._isInStaff(el, s_no): - el.getParent().removeChild(el) + for el in list(events): + if self._isInStaff(el, s_no): + el.getParent().removeChild(el) # At the first measure, also add relevant multi-measure spanners # for each selected staff if is_first_m: - for evs in spanners.values(): - for event_id in evs: - ev = self.doc.getElementById(event_id) - # Spanners starting outside of beat ranges - # may be already gone - if ev: - # Determine staff of event for id changes - for ema_s in ema_m.staves: - staff_no = self._isInStaff(ev, ema_s.number) - - if staff_no and staff_no in s_nos: - # If the event is attached to more than one staff, just - # consider it attached to the its first one - staff_no = staff_no[0] - - staff = None - for staff_candidate in measure.getDescendantsByName("staff"): - if staff_candidate.hasAttribute("n"): - n = int(staff_candidate.getAttribute("n").getValue()) - if n == staff_no: - staff = staff_candidate - - # Truncate event to start at the beginning of the beat range - if ev.hasAttribute("startid"): - # Set startid to the first event still on staff, - # at the first available layer - try: - layer = ( - staff.getChildrenByName("layer") - ) - first_id = layer[0].getChildren()[0].getId() - ev.getAttribute("startid").setValue("#"+first_id) - except IndexError: - msg = """ - Unsupported encoding. Omas attempted to adjust the - starting point of a selected multi-measure element - that starts before the selection, but the staff or - layer could not be located. - """ - msg = re.sub(r'\s+', ' ', msg.strip()) - raise UnsupportedEncoding(msg) - - if ev.hasAttribute("tstamp"): - # Set tstamp to first in beat selection - tstamp_first = 0 - for e_s in ema_m.staves: - if e_s.number == staff_no: - tstamp_first = e_s.beat_ranges[0].tstamp_first - ev.getAttribute("tstamp").setValue(str(tstamp_first)) - - # Truncate to end of range if completeness = cut - # (actual beat cutting will happen when beat ranges are procesed) - if "cut" in self.ema_exp.completenessOptions: - if ev.hasAttribute("tstamp2"): - att = ev.getAttribute("tstamp2") - t2 = att.getValue() - p = re.compile(r"([1-9]+)(?=m\+)") - multimeasure = p.match(t2) - if multimeasure: - new_val = len(mm) - 1 - att.setValue(p.sub(str(new_val), t2)) - - # Otherwise adjust tspan2 value to correct distance. - # E.g. given 4 measures with a spanner originating - # in 1 and ending in 4 and a selection of measures 2 and 3, - # change @tspan2 from 3m+X to 2m+X - else: - if ev.hasAttribute("tstamp2"): - att = ev.getAttribute("tstamp2") - t2 = att.getValue() - p = re.compile(r"([1-9]+)(?=m\+)") - multimeasure = p.match(t2) - if multimeasure: - dis = evs[event_id]["distance"] - new_val = int(multimeasure.group(1)) - dis - att.setValue(p.sub(str(new_val), t2)) - - # move element to first measure and add it to selected - # events "around" the staff. - ev.moveTo(measure) + if "highlight" not in self.ema_exp.completenessOptions: + for evs in spanners.values(): + for event_id in evs: + ev = self.doc.getElementById(event_id) + # Spanners starting outside of beat ranges + # may be already gone + if ev: + # Determine staff of event for id changes + for ema_s in ema_m.staves: + staff_no = self._isInStaff(ev, ema_s.number) + + if staff_no and staff_no in s_nos: + # If the event is attached to more than one staff, just + # consider it attached to the its first one + staff_no = staff_no[0] + + staff = None + for staff_candidate in measure.getDescendantsByName("staff"): + if staff_candidate.hasAttribute("n"): + n = int(staff_candidate.getAttribute("n").getValue()) + if n == staff_no: + staff = staff_candidate + + # Truncate event to start at the beginning of the beat range + if ev.hasAttribute("startid"): + # Set startid to the first event still on staff, + # at the first available layer + try: + layer = ( + staff.getChildrenByName("layer") + ) + first_id = layer[0].getChildren()[0].getId() + ev.getAttribute("startid").setValue("#"+first_id) + except IndexError: + msg = """ + Unsupported encoding. Omas attempted to adjust the + starting point of a selected multi-measure element + that starts before the selection, but the staff or + layer could not be located. + """ + msg = re.sub(r'\s+', ' ', msg.strip()) + raise UnsupportedEncoding(msg) + + if ev.hasAttribute("tstamp"): + # Set tstamp to first in beat selection + tstamp_first = 0 + for e_s in ema_m.staves: + if e_s.number == staff_no: + tstamp_first = e_s.beat_ranges[0].tstamp_first + ev.getAttribute("tstamp").setValue(str(tstamp_first)) + + # Truncate to end of range if completeness = cut + # (actual beat cutting will happen when beat ranges are procesed) + if "cut" in self.ema_exp.completenessOptions: + if ev.hasAttribute("tstamp2"): + att = ev.getAttribute("tstamp2") + t2 = att.getValue() + p = re.compile(r"([1-9]+)(?=m\+)") + multimeasure = p.match(t2) + if multimeasure: + new_val = len(mm) - 1 + att.setValue(p.sub(str(new_val), t2)) + + # Otherwise adjust tspan2 value to correct distance. + # E.g. given 4 measures with a spanner originating + # in 1 and ending in 4 and a selection of measures 2 and 3, + # change @tspan2 from 3m+X to 2m+X + else: + if ev.hasAttribute("tstamp2"): + att = ev.getAttribute("tstamp2") + t2 = att.getValue() + p = re.compile(r"([1-9]+)(?=m\+)") + multimeasure = p.match(t2) + if multimeasure: + dis = evs[event_id]["distance"] + new_val = int(multimeasure.group(1)) - dis + att.setValue(p.sub(str(new_val), t2)) + + # move element to first measure and add it to selected + # events "around" the staff. + ev.moveTo(measure) + else: + # Add spanners to annotated selection + for evs in spanners.values(): + for event_id in evs: + if self.highlight_el: + cur_plist = self.highlight_el.getAttribute("plist").getValue() + space = "" + if len(cur_plist) > 0: + space = " " + val = cur_plist + space + "#" + event_id + self.highlight_el.addAttribute("plist", val) return self.doc From 7a60b5f3e96882fd54805010a4d277d96c2fb3a8 Mon Sep 17 00:00:00 2001 From: Micah Walter Date: Thu, 29 Nov 2018 13:07:23 -0500 Subject: [PATCH 02/13] Correct requirements and import paths --- Omas/api.py | 14 +++++++------- Omas/omas/meislicer.py | 15 ++++++++------- Omas/requirements.txt | 1 + 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Omas/api.py b/Omas/api.py index 5a4360c..5fc1b09 100644 --- a/Omas/api.py +++ b/Omas/api.py @@ -1,11 +1,11 @@ import requests -from urllib import unquote +from urllib.parse import unquote import re import tempfile import os -from flask.ext.api import FlaskAPI -from flask.ext.api import status +from flask_api import FlaskAPI +from flask_api import status from werkzeug.routing import BaseConverter from werkzeug.routing import ValidationError from flask import send_file @@ -19,19 +19,19 @@ from omas.exceptions import UnknownMEIReadException from omas.exceptions import UnsupportedEncoding -from flask.ext.cors import CORS +from flask_cors import CORS app = FlaskAPI(__name__) CORS(app) app.config['DEFAULT_RENDERERS'] = [ - 'flask.ext.api.renderers.JSONRenderer', - 'flask.ext.api.renderers.BrowsableAPIRenderer', + 'flask_api.renderers.JSONRenderer', + 'flask_api.renderers.BrowsableAPIRenderer', ] app.config['DEFAULT_PARSERS'] = [ - 'flask.ext.api.parsers.JSONParser', + 'flask_api.parsers.JSONParser', ] diff --git a/Omas/omas/meislicer.py b/Omas/omas/meislicer.py index 9a75497..71a9b7c 100644 --- a/Omas/omas/meislicer.py +++ b/Omas/omas/meislicer.py @@ -1,12 +1,13 @@ -from meiinfo import MusDocInfo -from emaexpression import EmaExpression -from omas.exceptions import BadApiRequest -from omas.exceptions import UnsupportedEncoding -from meielementset import MeiElementSet - import re + from pymei import MeiElement, MeiAttribute -from pymeiext import getClosestStaffDefs, moveTo + +from omas.emaexpression import EmaExpression +from omas.exceptions import BadApiRequest +from omas.exceptions import UnsupportedEncoding +from omas.meielementset import MeiElementSet +from omas.meiinfo import MusDocInfo +from omas.pymeiext import getClosestStaffDefs, moveTo class MeiSlicer(object): diff --git a/Omas/requirements.txt b/Omas/requirements.txt index 826b267..040abf7 100644 --- a/Omas/requirements.txt +++ b/Omas/requirements.txt @@ -1,5 +1,6 @@ Flask==0.10.1 Flask-API==0.6.2 +Flask-CORS==3.0.7 Flask-RESTful==0.2.12 Jinja2==2.7.3 MarkupSafe==0.23 From 81eef40efa6a6129cdf4d9b262ad0bd90fec064e Mon Sep 17 00:00:00 2001 From: Micah Walter Date: Thu, 29 Nov 2018 13:07:36 -0500 Subject: [PATCH 03/13] Change file writing to binary for Python 3 --- Omas/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Omas/api.py b/Omas/api.py index 5fc1b09..3909870 100644 --- a/Omas/api.py +++ b/Omas/api.py @@ -127,7 +127,7 @@ def address(meipath, measures, staves, beats, completeness=None): fname = "full.mei" filename = os.path.join(tdir, fname) try: - file = open(filename, 'w') + file = open(filename, 'wb') file.write(mei_as_text) file.close() except CannotWriteMEIException as ex: From ad7cb011c5684733543afaaee694abe16405658a Mon Sep 17 00:00:00 2001 From: Micah Walter Date: Wed, 5 Dec 2018 17:07:05 -0500 Subject: [PATCH 04/13] Recreate the schema http:// when making GET request for mei file --- Omas/api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Omas/api.py b/Omas/api.py index 3909870..999a727 100644 --- a/Omas/api.py +++ b/Omas/api.py @@ -91,8 +91,10 @@ def to_url(self, value): app.url_map.converters['beats'] = BeatsConverter -def get_external_mei(meiaddr): - r = requests.get(unquote(meiaddr), timeout=15) +def get_external_mei(meipath): + pattern_to_strip = r'^/?http(%3A|%3a|:)(%2F|%2f|/)(%2F|%2f|/)?' + meipath_stripped = re.sub(pattern_to_strip, '', meipath, count=1) + r = requests.get('http://' + unquote(meipath_stripped), timeout=15) # Exeunt stage left if something went wrong. if r.status_code != requests.codes.ok: if r.status_code == 404: From c933ce124d3f9077123f821e3fae18fab1fdb24f Mon Sep 17 00:00:00 2001 From: Micah Walter Date: Thu, 6 Dec 2018 13:02:43 -0500 Subject: [PATCH 05/13] Change .sort() to sorted() for Python 3 --- Omas/omas/meislicer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Omas/omas/meislicer.py b/Omas/omas/meislicer.py index 71a9b7c..be419dd 100644 --- a/Omas/omas/meislicer.py +++ b/Omas/omas/meislicer.py @@ -35,7 +35,7 @@ def slice(self): # parse general beats information self.beatsInfo = self.docInfo["beats"] self.timeChanges = self.beatsInfo.keys() - self.timeChanges.sort(key=int) + self.timeChanges = sorted(self.timeChanges, key=int) # Process measure ranges and store boundary measures boundary_mm = [] From ab87c9bdf9683db9feb9b81c5cd2798a33472821 Mon Sep 17 00:00:00 2001 From: Micah Walter Date: Fri, 7 Dec 2018 13:37:04 -0500 Subject: [PATCH 06/13] more tweaks to python 2 vs 3 --- Omas/api.py | 11 ++++++----- Omas/omas/meislicer.py | 3 +-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Omas/api.py b/Omas/api.py index 999a727..9ccb692 100644 --- a/Omas/api.py +++ b/Omas/api.py @@ -39,7 +39,7 @@ class MeasuresConverter(BaseConverter): def __init__(self, url_map): - super(MeasuresConverter, self).__init__(url_map) + super().__init__(url_map) def to_python(self, value): exp = r'(?:^((all|((start|end|\d+)(-(start|end|\d+))?))+(,|$))+)' @@ -55,7 +55,7 @@ def to_url(self, value): class StavesConverter(BaseConverter): def __init__(self, url_map): - super(StavesConverter, self).__init__(url_map) + super().__init__(url_map) def to_python(self, value): # Testing the regular expression here because @@ -73,7 +73,7 @@ def to_url(self, value): class BeatsConverter(BaseConverter): def __init__(self, url_map): - super(BeatsConverter, self).__init__(url_map) + super().__init__(url_map) def to_python(self, value): exp = r"""(?:^((@(all\+?|((start|end|\d+(\.\d+)?) @@ -86,6 +86,7 @@ def to_python(self, value): def to_url(self, value): return value + app.url_map.converters['staves'] = StavesConverter app.url_map.converters['measures'] = MeasuresConverter app.url_map.converters['beats'] = BeatsConverter @@ -105,7 +106,7 @@ def get_external_mei(meipath): r.status_code) raise UnknownMEIReadException(msg) - return r.content + return r.text @app.route('/', methods=['GET']) @@ -129,7 +130,7 @@ def address(meipath, measures, staves, beats, completeness=None): fname = "full.mei" filename = os.path.join(tdir, fname) try: - file = open(filename, 'wb') + file = open(filename, 'w') file.write(mei_as_text) file.close() except CannotWriteMEIException as ex: diff --git a/Omas/omas/meislicer.py b/Omas/omas/meislicer.py index be419dd..46a578f 100644 --- a/Omas/omas/meislicer.py +++ b/Omas/omas/meislicer.py @@ -34,8 +34,7 @@ def slice(self): # parse general beats information self.beatsInfo = self.docInfo["beats"] - self.timeChanges = self.beatsInfo.keys() - self.timeChanges = sorted(self.timeChanges, key=int) + self.timeChanges = sorted(self.beatsInfo.keys(), key=int) # Process measure ranges and store boundary measures boundary_mm = [] From 15167c4db3af05680ff8b129ff4a50b771c91d41 Mon Sep 17 00:00:00 2001 From: Micah Walter Date: Fri, 7 Dec 2018 13:49:39 -0500 Subject: [PATCH 07/13] parentheses needed around print function parameters --- Omas/omas/meislicer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Omas/omas/meislicer.py b/Omas/omas/meislicer.py index 06e98c1..4bd2894 100644 --- a/Omas/omas/meislicer.py +++ b/Omas/omas/meislicer.py @@ -33,7 +33,7 @@ def slice(self): provided a EMA expression of measures, staves, and beats.""" # if highlighting, create annot - print self.ema_exp.completenessOptions + print(self.ema_exp.completenessOptions) if "highlight" in self.ema_exp.completenessOptions: # create annotation element for highlights last_score_el = self.doc.getElementsByName("score")[-1] From f9b409728f557300915aa9c7b4890b37daeacd3a Mon Sep 17 00:00:00 2001 From: Micah Walter Date: Tue, 11 Dec 2018 15:41:38 -0500 Subject: [PATCH 08/13] Use https with Omas server --- Omas/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Omas/api.py b/Omas/api.py index 9ccb692..b1a3ad1 100644 --- a/Omas/api.py +++ b/Omas/api.py @@ -95,7 +95,7 @@ def to_url(self, value): def get_external_mei(meipath): pattern_to_strip = r'^/?http(%3A|%3a|:)(%2F|%2f|/)(%2F|%2f|/)?' meipath_stripped = re.sub(pattern_to_strip, '', meipath, count=1) - r = requests.get('http://' + unquote(meipath_stripped), timeout=15) + r = requests.get('https://' + unquote(meipath_stripped), timeout=15) # Exeunt stage left if something went wrong. if r.status_code != requests.codes.ok: if r.status_code == 404: From e22e8e7a64dd2662b3ac90269e8bb8084718d1bc Mon Sep 17 00:00:00 2001 From: Micah Walter Date: Tue, 11 Dec 2018 16:02:29 -0500 Subject: [PATCH 09/13] Reverse change from http to https unconditionally --- Omas/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Omas/api.py b/Omas/api.py index b1a3ad1..9ccb692 100644 --- a/Omas/api.py +++ b/Omas/api.py @@ -95,7 +95,7 @@ def to_url(self, value): def get_external_mei(meipath): pattern_to_strip = r'^/?http(%3A|%3a|:)(%2F|%2f|/)(%2F|%2f|/)?' meipath_stripped = re.sub(pattern_to_strip, '', meipath, count=1) - r = requests.get('https://' + unquote(meipath_stripped), timeout=15) + r = requests.get('http://' + unquote(meipath_stripped), timeout=15) # Exeunt stage left if something went wrong. if r.status_code != requests.codes.ok: if r.status_code == 404: From e327ba36131176ba55e772802b1aaa3fea33cdc7 Mon Sep 17 00:00:00 2001 From: Micah Walter Date: Mon, 18 Feb 2019 23:33:01 -0500 Subject: [PATCH 10/13] https for omas server; better strip pattern --- Omas/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Omas/api.py b/Omas/api.py index 9ccb692..5892c1d 100644 --- a/Omas/api.py +++ b/Omas/api.py @@ -93,7 +93,7 @@ def to_url(self, value): def get_external_mei(meipath): - pattern_to_strip = r'^/?http(%3A|%3a|:)(%2F|%2f|/)(%2F|%2f|/)?' + pattern_to_strip = r'^/?http(%3A|%3a|:)(%2F|%2f|/)*' meipath_stripped = re.sub(pattern_to_strip, '', meipath, count=1) r = requests.get('http://' + unquote(meipath_stripped), timeout=15) # Exeunt stage left if something went wrong. From c1411773844e48de1cfdea1d8986888ab86f8f36 Mon Sep 17 00:00:00 2001 From: Micah Walter Date: Mon, 18 Feb 2019 23:37:06 -0500 Subject: [PATCH 11/13] Use https with stripped URL --- Omas/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Omas/api.py b/Omas/api.py index 5892c1d..9781e2d 100644 --- a/Omas/api.py +++ b/Omas/api.py @@ -95,7 +95,7 @@ def to_url(self, value): def get_external_mei(meipath): pattern_to_strip = r'^/?http(%3A|%3a|:)(%2F|%2f|/)*' meipath_stripped = re.sub(pattern_to_strip, '', meipath, count=1) - r = requests.get('http://' + unquote(meipath_stripped), timeout=15) + r = requests.get('https://' + unquote(meipath_stripped), timeout=15) # Exeunt stage left if something went wrong. if r.status_code != requests.codes.ok: if r.status_code == 404: From 877910612f52edb72a0681d52550f09e32491331 Mon Sep 17 00:00:00 2001 From: Ian Fisher Date: Fri, 22 Feb 2019 14:16:52 +0000 Subject: [PATCH 12/13] Accept HTTPS urls, and update gitignore --- .gitignore | 3 +++ Omas/api.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e595949..a227c88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ *.pyc Omas/Omas.egg-info +*~ +/Omas/uwsgi_params +*.save diff --git a/Omas/api.py b/Omas/api.py index 9781e2d..52ce6ef 100644 --- a/Omas/api.py +++ b/Omas/api.py @@ -93,7 +93,7 @@ def to_url(self, value): def get_external_mei(meipath): - pattern_to_strip = r'^/?http(%3A|%3a|:)(%2F|%2f|/)*' + pattern_to_strip = r'^/?https?(%3A|%3a|:)(%2F|%2f|/)*' meipath_stripped = re.sub(pattern_to_strip, '', meipath, count=1) r = requests.get('https://' + unquote(meipath_stripped), timeout=15) # Exeunt stage left if something went wrong. From f16cdd2eba645a0ac1b9ad0771dc8b485253f8f9 Mon Sep 17 00:00:00 2001 From: Micah Walter Date: Mon, 20 Jan 2020 00:38:23 -0500 Subject: [PATCH 13/13] This is now built into python3 --- Omas/requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/Omas/requirements.txt b/Omas/requirements.txt index 040abf7..fd5c614 100644 --- a/Omas/requirements.txt +++ b/Omas/requirements.txt @@ -14,4 +14,3 @@ nose==1.3.4 pytz==2014.9 requests==2.4.3 six==1.8.0 -wsgiref==0.1.2