summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erikj@jki.re>2018-10-17 17:07:19 +0100
committerGitHub <noreply@github.com>2018-10-17 17:07:19 +0100
commit4e726783eae04365dbfb355bb334c1661cb391cb (patch)
treefc788a43d1e0f436cdd450eced6de1e2f87ba8fb
parentFix roomlist since tokens on Python 3 (#4046) (diff)
parentNewsfile (diff)
downloadsynapse-4e726783eae04365dbfb355bb334c1661cb391cb.tar.xz
Merge pull request #4050 from matrix-org/erikj/fix_py37_iteration
Fix bug where we raised StopIteration in a generator
-rw-r--r--changelog.d/4050.bugfix1
-rw-r--r--synapse/rest/media/v1/preview_url_resource.py7
2 files changed, 6 insertions, 2 deletions
diff --git a/changelog.d/4050.bugfix b/changelog.d/4050.bugfix
new file mode 100644
index 0000000000..3d1f6af847
--- /dev/null
+++ b/changelog.d/4050.bugfix
@@ -0,0 +1 @@
+Fix URL priewing to work in Python 3.7
diff --git a/synapse/rest/media/v1/preview_url_resource.py b/synapse/rest/media/v1/preview_url_resource.py
index af01040a38..8c892ff187 100644
--- a/synapse/rest/media/v1/preview_url_resource.py
+++ b/synapse/rest/media/v1/preview_url_resource.py
@@ -596,10 +596,13 @@ def _iterate_over_text(tree, *tags_to_ignore):
     # to be returned.
     elements = iter([tree])
     while True:
-        el = next(elements)
+        el = next(elements, None)
+        if el is None:
+            return
+
         if isinstance(el, string_types):
             yield el
-        elif el is not None and el.tag not in tags_to_ignore:
+        elif el.tag not in tags_to_ignore:
             # el.text is the text before the first child, so we can immediately
             # return it if the text exists.
             if el.text: