← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~mzibricky/openlp/bug-1046587 into lp:openlp

 

matysek has proposed merging lp:~mzibricky/openlp/bug-1046587 into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)
Related bugs:
  Bug #1046587 in OpenLP: "Non-ASCII characters in default service name cause error"
  https://bugs.launchpad.net/openlp/+bug/1046587

For more details, see:
https://code.launchpad.net/~mzibricky/openlp/bug-1046587/+merge/124539

I implemented fix by passing individual % placeholders to time.strftime().  I put new function format_time() to openlp.core.utils.
-- 
https://code.launchpad.net/~mzibricky/openlp/bug-1046587/+merge/124539
Your team OpenLP Core is requested to review the proposed merge of lp:~mzibricky/openlp/bug-1046587 into lp:openlp.
=== modified file 'openlp/core/ui/advancedtab.py'
--- openlp/core/ui/advancedtab.py	2012-09-06 13:49:47 +0000
+++ openlp/core/ui/advancedtab.py	2012-09-15 00:02:20 +0000
@@ -38,7 +38,7 @@
 from openlp.core.lib import SettingsTab, translate, build_icon,  Receiver
 from openlp.core.lib.settings import Settings
 from openlp.core.lib.ui import UiStrings
-from openlp.core.utils import get_images_filter, AppLocation
+from openlp.core.utils import get_images_filter, AppLocation, format_time
 from openlp.core.lib import SlideLimits
 
 log = logging.getLogger(__name__)
@@ -622,7 +622,7 @@
             time = time.replace(hour = self.serviceNameTime.time().hour(),
                 minute = self.serviceNameTime.time().minute())
         try:
-            service_name_example = time.strftime(unicode(
+            service_name_example = format_time(unicode(
                 self.serviceNameEdit.text()))
         except ValueError:
             preset_is_valid = False

=== modified file 'openlp/core/ui/servicemanager.py'
--- openlp/core/ui/servicemanager.py	2012-09-06 13:49:47 +0000
+++ openlp/core/ui/servicemanager.py	2012-09-15 00:02:20 +0000
@@ -47,7 +47,8 @@
     create_widget_action, find_and_set_in_combo_box
 from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm, StartTimeForm
 from openlp.core.ui.printserviceform import PrintServiceForm
-from openlp.core.utils import AppLocation, delete_file, split_filename
+from openlp.core.utils import AppLocation, delete_file, split_filename, \
+    format_time
 from openlp.core.utils.actions import ActionList, CategoryOrder
 
 class ServiceManagerList(QtGui.QTreeWidget):
@@ -621,7 +622,7 @@
                     '/\\?*|<>\[\]":+\nSee http://docs.python.org/library/'
                     'datetime.html#strftime-strptime-behavior for more '
                     'information.')).toString())
-            default_filename = time.strftime(default_pattern)
+            default_filename = format_time(default_pattern)
         else:
             default_filename = u''
         directory = unicode(SettingsManager.get_last_dir(

=== modified file 'openlp/core/utils/__init__.py'
--- openlp/core/utils/__init__.py	2012-07-08 19:27:43 +0000
+++ openlp/core/utils/__init__.py	2012-09-15 00:02:20 +0000
@@ -35,6 +35,7 @@
 import re
 from subprocess import Popen, PIPE
 import sys
+import time
 import urllib2
 
 from openlp.core.lib.settings import Settings
@@ -469,10 +470,24 @@
         return resolver.resolve(u'uno:socket,host=localhost,port=2002;' \
             + u'urp;StarOffice.ComponentContext')
 
+
+def format_time(text):
+    """
+    Workaround for Python built-in time formatting fuction time.strftime().
+
+    time.strftime() accepts only ascii characters. This function accepts
+    unicode string and passes individual % placeholders to time.strftime().
+    This ensures only ascii characters are passed to time.strftime().
+    """
+    def match_formatting(match):
+        return time.strftime(match.group())
+    return re.sub('\%[a-zA-Z]', match_formatting, text)
+
+
 from languagemanager import LanguageManager
 from actions import ActionList
 
 __all__ = [u'AppLocation', u'get_application_version', u'check_latest_version',
     u'add_actions', u'get_filesystem_encoding', u'LanguageManager',
     u'ActionList', u'get_web_page', u'get_uno_command', u'get_uno_instance',
-    u'delete_file', u'clean_filename']
+    u'delete_file', u'clean_filename', u'format_time']


Follow ups