← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~googol-hush/openlp/trivial into lp:openlp

 

Andreas Preikschat has proposed merging lp:~googol-hush/openlp/trivial into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~googol-hush/openlp/trivial/+merge/61420

Hello,

Improved regex usage.

In the ThemeXML class I introduced them as class variables because there are many instances (each theme create its own at start up, each service item created/added creates one).
-- 
https://code.launchpad.net/~googol-hush/openlp/trivial/+merge/61420
Your team OpenLP Core is requested to review the proposed merge of lp:~googol-hush/openlp/trivial into lp:openlp.
=== modified file 'openlp/core/lib/theme.py'
--- openlp/core/lib/theme.py	2011-04-25 07:06:35 +0000
+++ openlp/core/lib/theme.py	2011-05-18 14:46:07 +0000
@@ -207,6 +207,8 @@
     """
     A class to encapsulate the Theme XML.
     """
+    FIRST_CAMEL_REGEX = re.compile(u'(.)([A-Z][a-z]+)')
+    SECOND_CAMEL_REGEX = re.compile(u'([a-z0-9])([A-Z])')
     def __init__(self):
         """
         Initialise the theme object.
@@ -581,8 +583,8 @@
         """
         Change Camel Case string to python string
         """
-        sub_name = re.sub(u'(.)([A-Z][a-z]+)', r'\1_\2', name)
-        return re.sub(u'([a-z0-9])([A-Z])', r'\1_\2', sub_name).lower()
+        sub_name = ThemeXML.FIRST_CAMEL_REGEX.sub(r'\1_\2', name)
+        return ThemeXML.SECOND_CAMEL_REGEX.sub(r'\1_\2', sub_name).lower()
 
     def _build_xml_from_attrs(self):
         """

=== modified file 'openlp/plugins/songs/lib/xml.py'
--- openlp/plugins/songs/lib/xml.py	2011-04-29 07:22:18 +0000
+++ openlp/plugins/songs/lib/xml.py	2011-05-18 14:46:07 +0000
@@ -233,6 +233,7 @@
     IMPLEMENTED_VERSION = u'0.7'
     def __init__(self, manager):
         self.manager = manager
+        self.chord_regex = re.compile(u'<chord name=".*?"/>')
 
     def song_to_xml(self, song):
         """
@@ -317,7 +318,7 @@
         if xml[:5] == u'<?xml':
             xml = xml[38:]
         # Remove chords from xml.
-        xml = re.compile(u'<chord name=".*?"/>').sub(u'', xml)
+        xml = self.chord_regex.sub(u'', xml)
         song_xml = objectify.fromstring(xml)
         if hasattr(song_xml, u'properties'):
             properties = song_xml.properties


Follow ups