Changeset 12231
- Timestamp:
- 14 Dec 2014, 16:01:35 (10 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/utils
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/utils/helpers.py
r11824 r12231 39 39 from zope.security.management import getInteraction 40 40 from zope.pluggableauth.interfaces import IAuthenticatorPlugin 41 from zope.formlib.widget import renderElement 41 42 42 43 BUFSIZE = 8 * 1024 … … 804 805 result[key] = value 805 806 return result 807 808 def html2dict(value=None,portal_language='en'): 809 """Transforms a localized HTML text string into a dictionary. 810 811 Different languages must be separated by `>>xy<<` whereas 812 xy is the language code. Text parts without correct leading 813 language separator - usually the first part has no language 814 descriptor - are interpreted as texts in the portal's language. 815 The latter can be configured in waeup.srp.utils.utils.IkobaUtils. 816 """ 817 try: 818 parts = value.split('>>') 819 except: 820 return {} 821 elements = {} 822 lang = portal_language 823 for part in parts: 824 if part[2:4] == u'<<': 825 lang = part[0:2].lower() 826 text = part[4:] 827 elements[lang] = renderElement(u'div id="html"', 828 contents=text) 829 else: 830 text = part 831 elements[lang] = renderElement(u'div id="html"', 832 contents=text) 833 return elements -
main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_helpers.py
r11824 r12231 582 582 info = helpers.get_meminfo(src="nOt-ExIsTiNg-FiLe") 583 583 assert info is None 584 585 586 class Html2dictTestCase(unittest.TestCase): 587 588 def test_html2dict(self): 589 assert helpers.html2dict(None) == {} 590 assert helpers.html2dict() == {} 591 assert helpers.html2dict(9) == {} 592 assert helpers.html2dict('Hello world') == { 593 'en': u'<div id="html">Hello world</div id="html">'} 594 assert helpers.html2dict('Hello world>>de<<Hallo Welt') == { 595 'de': u'<div id="html">Hallo Welt</div id="html">', 596 'en': u'<div id="html">Hello world</div id="html">'} 584 597 585 598 … … 603 616 MemInfoTestCase, 604 617 GetMemInfoTestCase, 618 Html2dictTestCase, 605 619 ]: 606 620 suite.addTests(
Note: See TracChangeset for help on using the changeset viewer.