From 78078fb2ed0812ffa56015b8dcc13c487b3b7f03 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 21 Nov 2015 08:31:17 +0000 Subject: [PATCH] catchup late fixes from 2.2.1 --- openlp/core/ui/media/vendor/vlc.py | 1 + openlp/plugins/bibles/lib/http.py | 5 ++- openlp/plugins/songs/lib/songselect.py | 35 ++++++++++++++----- .../openlp_core_ui_media/test_vlcplayer.py | 22 +++++++++--- 4 files changed, 47 insertions(+), 16 deletions(-) diff --git a/openlp/core/ui/media/vendor/vlc.py b/openlp/core/ui/media/vendor/vlc.py index f56d3ef56..102af034f 100644 --- a/openlp/core/ui/media/vendor/vlc.py +++ b/openlp/core/ui/media/vendor/vlc.py @@ -107,6 +107,7 @@ def find_lib(): except OSError: # may fail dll = ctypes.CDLL('libvlc.so.5') elif sys.platform.startswith('win'): + ctypes.windll.kernel32.SetDllDirectoryW(None) p = find_library('libvlc.dll') if p is None: try: # some registry settings diff --git a/openlp/plugins/bibles/lib/http.py b/openlp/plugins/bibles/lib/http.py index 9d7ad916d..fcf4b049d 100644 --- a/openlp/plugins/bibles/lib/http.py +++ b/openlp/plugins/bibles/lib/http.py @@ -27,7 +27,6 @@ import re import socket import urllib.parse import urllib.error -from html.parser import HTMLParseError from bs4 import BeautifulSoup, NavigableString, Tag @@ -290,7 +289,7 @@ class BGExtract(RegistryProperties): page_source = str(page_source, 'cp1251') try: soup = BeautifulSoup(page_source) - except HTMLParseError: + except Exception: log.error('BeautifulSoup could not parse the Bible page.') send_error_message('parse') return None @@ -762,7 +761,7 @@ def get_soup_for_bible_ref(reference_url, header=None, pre_parse_regex=None, pre try: soup = BeautifulSoup(page_source) CLEANER_REGEX.sub('', str(soup)) - except HTMLParseError: + except Exception: log.exception('BeautifulSoup could not parse the bible page.') if not soup: send_error_message('parse') diff --git a/openlp/plugins/songs/lib/songselect.py b/openlp/plugins/songs/lib/songselect.py index c09be65c0..e1641ae0c 100644 --- a/openlp/plugins/songs/lib/songselect.py +++ b/openlp/plugins/songs/lib/songselect.py @@ -23,10 +23,13 @@ The :mod:`~openlp.plugins.songs.lib.songselect` module contains the SongSelect importer itself. """ import logging +import sys from http.cookiejar import CookieJar from urllib.parse import urlencode from urllib.request import HTTPCookieProcessor, URLError, build_opener from html.parser import HTMLParser +if sys.version_info > (3, 4): + from html import unescape from bs4 import BeautifulSoup, NavigableString @@ -129,11 +132,18 @@ class SongSelectImport(object): if not search_results: break for result in search_results: - song = { - 'title': self.html_parser.unescape(result.find('h3').string), - 'authors': [self.html_parser.unescape(author.string) for author in result.find_all('li')], - 'link': BASE_URL + result.find('a')['href'] - } + if sys.version_info > (3, 4): + song = { + 'title': unescape(result.find('h3').string), + 'authors': [unescape(author.string) for author in result.find_all('li')], + 'link': BASE_URL + result.find('a')['href'] + } + else: + song = { + 'title': self.html_parser.unescape(result.find('h3').string), + 'authors': [self.html_parser.unescape(author.string) for author in result.find_all('li')], + 'link': BASE_URL + result.find('a')['href'] + } if callback: callback(song) songs.append(song) @@ -167,7 +177,10 @@ class SongSelectImport(object): if callback: callback() song['copyright'] = '/'.join([li.string for li in song_page.find('ul', 'copyright').find_all('li')]) - song['copyright'] = self.html_parser.unescape(song['copyright']) + if sys.version_info > (3, 4): + song['copyright'] = unescape(song['copyright']) + else: + song['copyright'] = self.html_parser.unescape(song['copyright']) song['ccli_number'] = song_page.find('ul', 'info').find('li').string.split(':')[1].strip() song['verses'] = [] verses = lyrics_page.find('section', 'lyrics').find_all('p') @@ -180,9 +193,15 @@ class SongSelectImport(object): else: verse['lyrics'] += '\n' verse['lyrics'] = verse['lyrics'].strip(' \n\r\t') - song['verses'].append(self.html_parser.unescape(verse)) + if sys.version_info > (3, 4): + song['verses'].append(unescape(verse)) + else: + song['verses'].append(self.html_parser.unescape(verse)) for counter, author in enumerate(song['authors']): - song['authors'][counter] = self.html_parser.unescape(author) + if sys.version_info > (3, 4): + song['authors'][counter] = unescape(author) + else: + song['authors'][counter] = self.html_parser.unescape(author) return song def save_song(self, song): diff --git a/tests/functional/openlp_core_ui_media/test_vlcplayer.py b/tests/functional/openlp_core_ui_media/test_vlcplayer.py index eccac6893..a8d3fd52b 100644 --- a/tests/functional/openlp_core_ui_media/test_vlcplayer.py +++ b/tests/functional/openlp_core_ui_media/test_vlcplayer.py @@ -25,7 +25,7 @@ Package to test the openlp.core.ui.media.vlcplayer package. import os import sys from datetime import datetime, timedelta -from unittest import TestCase +from unittest import TestCase, skip from openlp.core.common import Registry from openlp.core.ui.media import MediaState, MediaType @@ -50,6 +50,22 @@ class TestVLCPlayer(TestCase, TestMixin): del sys.modules['openlp.core.ui.media.vendor.vlc'] MockDateTime.revert() + @skip('No way to test this') + @patch('openlp.core.ui.media.vlcplayer.vlc') + def get_vlc_fails_and_removes_module_test(self, mocked_vlc): + """ + Test that when the VLC import fails, it removes the module from sys.modules + """ + # GIVEN: We're on OS X and we don't have the VLC plugin path set + mocked_vlc.Instance.side_effect = NameError + mocked_vlc.libvlc_get_version.return_value = b'0.0.0' + + # WHEN: An checking if the player is available + get_vlc() + + # THEN: The extra environment variable should be there + self.assertNotIn('openlp.core.ui.media.vendor.vlc', sys.modules) + @patch('openlp.core.ui.media.vlcplayer.is_macosx') def fix_vlc_22_plugin_path_test(self, mocked_is_macosx): """ @@ -74,10 +90,6 @@ class TestVLCPlayer(TestCase, TestMixin): """ # GIVEN: We're not on OS X and we don't have the VLC plugin path set mocked_is_macosx.return_value = False - if 'VLC_PLUGIN_PATH' in os.environ: - del os.environ['VLC_PLUGIN_PATH'] - if 'openlp.core.ui.media.vendor.vlc' in sys.modules: - del sys.modules['openlp.core.ui.media.vendor.vlc'] # WHEN: An checking if the player is available get_vlc()