예제 #1
0
    def test_get_translation_object_copy(self):
        '''Test get_translation_object shallow copies the message catalog'''
        translations = i18n.get_translation_object('test', [
            '%s/data/locale' % os.path.dirname(__file__),
            '%s/data/locale-old' % os.path.dirname(__file__)
        ],
                                                   codeset='utf-8')
        translations.input_charset = 'utf-8'
        translations2 = i18n.get_translation_object('test', [
            '%s/data/locale' % os.path.dirname(__file__),
            '%s/data/locale-old' % os.path.dirname(__file__)
        ],
                                                    codeset='latin-1')
        translations2.input_charset = 'latin-1'

        # Test that portions of the translation objects are the same and other
        # portions are different (which is a space optimization so that the
        # translation data isn't in memory multiple times)
        tools.assert_not_equal(id(translations._fallback),
                               id(translations2._fallback))
        tools.assert_not_equal(id(translations.output_charset()),
                               id(translations2.output_charset()))
        tools.assert_not_equal(id(translations.input_charset),
                               id(translations2.input_charset))
        tools.assert_not_equal(id(translations.input_charset),
                               id(translations2.input_charset))
        tools.eq_(id(translations._catalog), id(translations2._catalog))
예제 #2
0
    def test_get_translation_object(self):
        '''Test that the get_translation_object function works
        '''
        translations = i18n.get_translation_object('foo', ['%s/data/locale/' % os.path.dirname(__file__)])
        tools.ok_(translations.__class__==i18n.DummyTranslations)
        tools.assert_raises(IOError, i18n.get_translation_object, 'foo', ['%s/data/locale/' % os.path.dirname(__file__)], fallback=False)

        translations = i18n.get_translation_object('test', ['%s/data/locale/' % os.path.dirname(__file__)])
        tools.ok_(translations.__class__==i18n.NewGNUTranslations)
예제 #3
0
 def setUp(self):
     self.old_LC_ALL = os.environ.get('LC_ALL', None)
     os.environ['LC_ALL'] = 'pt_BR.ISO8859-1'
     self.gtranslations = i18n.get_translation_object('test',
             ['%s/data/locale/' % os.path.dirname(__file__),
                 '%s/data/locale-old' % os.path.dirname(__file__)])
     self.gtranslations.add_fallback(object())
     self.dtranslations = i18n.get_translation_object('nonexistent',
             ['%s/data/locale/' % os.path.dirname(__file__),
                 '%s/data/locale-old' % os.path.dirname(__file__)])
     self.dtranslations.add_fallback(object())
예제 #4
0
    def test_get_translation_object(self):
        '''Test that the get_translation_object function works
        '''
        translations = i18n.get_translation_object(
            'foo', ['%s/data/locale/' % os.path.dirname(__file__)])
        tools.eq_(translations.__class__, i18n.DummyTranslations)
        tools.assert_raises(IOError,
                            i18n.get_translation_object,
                            'foo',
                            ['%s/data/locale/' % os.path.dirname(__file__)],
                            fallback=False)

        translations = i18n.get_translation_object(
            'test', ['%s/data/locale/' % os.path.dirname(__file__)])
        tools.eq_(translations.__class__, i18n.NewGNUTranslations)
예제 #5
0
 def setUp(self):
     self.old_LC_ALL = os.environ.get('LC_ALL', None)
     os.environ['LC_ALL'] = 'pt_BR.iso88591'
     self.gtranslations = i18n.get_translation_object(
         'test', [
             '%s/data/locale/' % os.path.dirname(__file__),
             '%s/data/locale-old' % os.path.dirname(__file__)
         ])
     self.gtranslations.add_fallback(object())
     self.dtranslations = i18n.get_translation_object(
         'nonexistent', [
             '%s/data/locale/' % os.path.dirname(__file__),
             '%s/data/locale-old' % os.path.dirname(__file__)
         ])
     self.dtranslations.add_fallback(object())
예제 #6
0
 def test_get_translation_object_create_fallback(self):
     '''Test get_translation_object creates fallbacks for additional catalogs'''
     translations = i18n.get_translation_object('test',
             ['%s/data/locale' % os.path.dirname(__file__),
                 '%s/data/locale-old' % os.path.dirname(__file__)])
     tools.ok_(translations.__class__==i18n.NewGNUTranslations)
     tools.ok_(translations._fallback.__class__==i18n.NewGNUTranslations)
예제 #7
0
    def setUp(self):
        self.old_LC_ALL = os.environ.get('LC_ALL', None)
        os.environ['LC_ALL'] = 'pt_BR.iso88591'

        self.old_LANGUAGE = os.environ.pop('LANGUAGE', None)

        self.translations = i18n.get_translation_object('test', ['%s/data/locale/' % os.path.dirname(__file__)])
예제 #8
0
 def setUp(self):
     self.old_LC_ALL = os.environ.get('LC_ALL', None)
     os.environ['LC_ALL'] = 'pt_BR.utf8'
     self.translations = i18n.get_translation_object(
         'test', [
             '%s/data/locale/' % os.path.dirname(__file__),
             '%s/data/locale-old' % os.path.dirname(__file__)
         ])
예제 #9
0
    def setUp(self):
        self.old_LC_ALL = os.environ.get('LC_ALL', None)
        os.environ['LC_ALL'] = 'pt_BR.iso88591'

        self.old_LANGUAGE = os.environ.pop('LANGUAGE', None)

        self.translations = i18n.get_translation_object(
            'test', ['%s/data/locale/' % os.path.dirname(__file__)])
예제 #10
0
 def test_get_translation_object_create_fallback(self):
     '''Test get_translation_object creates fallbacks for additional catalogs'''
     translations = i18n.get_translation_object('test', [
         '%s/data/locale' % os.path.dirname(__file__),
         '%s/data/locale-old' % os.path.dirname(__file__)
     ])
     tools.eq_(translations.__class__, i18n.NewGNUTranslations)
     tools.eq_(translations._fallback.__class__, i18n.NewGNUTranslations)
예제 #11
0
    def setUp(self):
        self.old_LC_ALL = os.environ.get('LC_ALL', None)
        os.environ['LC_ALL'] = 'pt_BR.utf8'

        self.old_LANGUAGE = os.environ.pop('LANGUAGE', None)

        self.old_DEFAULT_LOCALEDIRS = i18n._DEFAULT_LOCALEDIR
        i18n._DEFAULT_LOCALEDIR = '%s/data/locale/' % os.path.dirname(__file__)

        self.translations = i18n.get_translation_object('test')
예제 #12
0
    def test_get_translation_object_copy(self):
        '''Test get_translation_object shallow copies the message catalog'''
        translations = i18n.get_translation_object('test',
                ['%s/data/locale' % os.path.dirname(__file__),
                    '%s/data/locale-old' % os.path.dirname(__file__)], codeset='utf-8')
        translations.input_charset = 'utf-8'
        translations2 = i18n.get_translation_object('test',
                ['%s/data/locale' % os.path.dirname(__file__),
                    '%s/data/locale-old' % os.path.dirname(__file__)], codeset='latin-1')
        translations2.input_charset = 'latin-1'

        # Test that portions of the translation objects are the same and other
        # portions are different (which is a space optimization so that the
        # translation data isn't in memory multiple times)
        tools.ok_(id(translations._fallback) != id(translations2._fallback))
        tools.ok_(id(translations.output_charset()) != id(translations2.output_charset()))
        tools.ok_(id(translations.input_charset) != id(translations2.input_charset))
        tools.ok_(id(translations.input_charset) != id(translations2.input_charset))
        tools.eq_(id(translations._catalog), id(translations2._catalog))
예제 #13
0
    def setUp(self):
        self.old_LC_ALL = os.environ.get('LC_ALL', None)
        os.environ['LC_ALL'] = 'pt_BR.utf8'

        self.old_LANGUAGE = os.environ.pop('LANGUAGE', None)

        self.old_DEFAULT_LOCALEDIRS = i18n._DEFAULT_LOCALEDIR
        i18n._DEFAULT_LOCALEDIR = '%s/data/locale/' % os.path.dirname(__file__)

        self.translations = i18n.get_translation_object('test')
예제 #14
0
 def test_get_translation_object_python2_api_default(self):
     '''Smoketest that python2_api default value yields the python2 functions'''
     # Default
     translations = i18n.get_translation_object('test',
             ['%s/data/locale' % os.path.dirname(__file__),
                 '%s/data/locale-old' % os.path.dirname(__file__)], codeset='utf-8')
     translations.input_charset = 'utf-8'
     tools.eq_(translations.gettext.__name__, '_gettext')
     tools.eq_(translations.lgettext.__name__, '_lgettext')
     tools.eq_(translations.ugettext.__name__, '_ugettext')
     tools.eq_(translations.ngettext.__name__, '_ngettext')
     tools.eq_(translations.lngettext.__name__, '_lngettext')
     tools.eq_(translations.ungettext.__name__, '_ungettext')
예제 #15
0
 def test_get_translation_object_python2_api_default(self):
     '''Smoketest that python2_api default value yields the python2 functions'''
     # Default
     translations = i18n.get_translation_object('test', [
         '%s/data/locale' % os.path.dirname(__file__),
         '%s/data/locale-old' % os.path.dirname(__file__)
     ],
                                                codeset='utf-8')
     translations.input_charset = 'utf-8'
     tools.eq_(translations.gettext.__name__, '_gettext')
     tools.eq_(translations.lgettext.__name__, '_lgettext')
     tools.eq_(translations.ugettext.__name__, '_ugettext')
     tools.eq_(translations.ngettext.__name__, '_ngettext')
     tools.eq_(translations.lngettext.__name__, '_lngettext')
     tools.eq_(translations.ungettext.__name__, '_ungettext')
예제 #16
0
    def test_get_translation_object_python2_api_false(self):
        '''Smoketest that setting python2_api false yields the python3 functions'''
        # Default
        translations = i18n.get_translation_object('test',
                ['%s/data/locale' % os.path.dirname(__file__),
                    '%s/data/locale-old' % os.path.dirname(__file__)], codeset='utf-8',
                python2_api=False)
        translations.input_charset = 'utf-8'
        tools.eq_(translations.gettext.__name__, '_ugettext')
        tools.eq_(translations.lgettext.__name__, '_lgettext')
        tools.eq_(translations.ngettext.__name__, '_ungettext')
        tools.eq_(translations.lngettext.__name__, '_lngettext')

        tools.assert_raises(AttributeError, translations.ugettext, 'message')
        tools.assert_raises(AttributeError, translations.ungettext, 'message1', 'message2')
예제 #17
0
    def test_get_translation_object_python2_api_false(self):
        '''Smoketest that setting python2_api false yields the python3 functions'''
        # Default
        translations = i18n.get_translation_object('test', [
            '%s/data/locale' % os.path.dirname(__file__),
            '%s/data/locale-old' % os.path.dirname(__file__)
        ],
                                                   codeset='utf-8',
                                                   python2_api=False)
        translations.input_charset = 'utf-8'
        tools.eq_(translations.gettext.__name__, '_ugettext')
        tools.eq_(translations.lgettext.__name__, '_lgettext')
        tools.eq_(translations.ngettext.__name__, '_ungettext')
        tools.eq_(translations.lngettext.__name__, '_lngettext')

        tools.assert_raises(AttributeError, translations.ugettext, 'message')
        tools.assert_raises(AttributeError, translations.ungettext, 'message1',
                            'message2')
예제 #18
0
contactinfo = itchat.search_friends(name='E.Hulun(8.21)')
print(contactinfo)
itchat.send(u'',contactinfo[0]['UserName'])
contactinfo = itchat.search_friends(name='Anir Zaamed')
print(contactinfo)
itchat.send(u'Anir,結婚おめでとうございます。おふたりで掴んだ幸せの種をこれから大きく育てていってください、おふたりの更なるご活躍をお祈りいたします。',contactinfo[0]['UserName'])
'''

#2
#error!
#@itchat.msg_register(isGroupChat=True)

# Setup gettext driven translations but use the kitchen functions so
# we don't have the mismatched bytes-unicode issues.
translations = get_translation_object('example')
# We use _() for marking strings that we operate on as unicode
# This is pretty much everything
_ = translations.ugettext

'''
chatrooms = itchat.get_chatrooms(update=True)
for chatroom in chatrooms:
#    print _(u'{}\n'.format(to_unicode(chatroom)))
#    print '{}\n'.format(repr(chatroom).encode('utf-8'))
#    print '{}\n'.format(str(chatroom).encode('utf-8'))
    if chatroom.IsOwner == 1 and chatroom.NickName == 'nominnandin':
        itchat.send(u'了解,公园中间的大桥北端,你们看时间决定吧,到达35分钟前在这儿发个消息,我就出门过去',chatroom['UserName'])
        #print '{}\n'.format(repr(chatroom).decode('unicode-escape'))
        #print '{}\n'.format(repr(chatroom).encode('utf-8'))
'''
예제 #19
0
파일: ex6.py 프로젝트: juxicn/leetcode
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import locale
import os
import sys
import unicodedata

from kitchen.text.converters import getwriter, to_bytes, to_unicode
from kitchen.i18n import get_translation_object

if __name__ == "__main__":
    # Setup gettext driven translations but use the kitchen functions so
    # we don't have the mismatched bytes-unicode issues.
    translations = get_translation_object('example')
    # We use _() for marking strings that we operate on as unicode
    # This is pretty much everything
    _ = translations.ugettext
    # And b_() for marking strings that we operate on as bytes.
    # This is limited to exceptions
    b_ = translations.lgettext

    # Setup stdout
    encoding = locale.getpreferredencoding()
    Writer = getwriter(encoding)
    sys.stdout = Writer(sys.stdout)

    # Load data.  Format is filename\0description
    # description should be utf-8 but filename can be any legal filename
    # on the filesystem
    # Sample datafile.txt:
예제 #20
0
 def setUp(self):
     self.old_LC_ALL = os.environ.get('LC_ALL', None)
     os.environ['LC_ALL'] = 'pt_BR.UTF8'
     self.translations = i18n.get_translation_object('test',
             ['%s/data/locale/' % os.path.dirname(__file__),
                 '%s/data/locale-old' % os.path.dirname(__file__)])
예제 #21
0
 def test_get_translation_object_optional_params(self):
     '''Smoketest leaving out optional parameters'''
     translations = i18n.get_translation_object('test')
     tools.assert_true(translations.__class__ in (i18n.NewGNUTranslations,
                                                  i18n.DummyTranslations))
예제 #22
0
 def test_get_translation_object_optional_params(self):
     '''Smoketest leaving out optional parameters'''
     translations = i18n.get_translation_object('test')
     tools.ok_(translations.__class__ in (i18n.NewGNUTranslations, i18n.DummyTranslations))