コード例 #1
0
ファイル: activity.py プロジェクト: ustbgaofan/beaker
 def __init__(self, user=None, service=None, action=None,
              field_name=None, old_value=None, new_value=None, **kw):
     """
     The *service* argument should be a string such as 'Scheduler' or 
     'XMLRPC', describing the means by which the change has been made. This 
     constructor will override it with something more specific (such as the 
     name of an external service) if appropriate.
     """
     super(Activity, self).__init__(**kw)
     self.user = user
     self.service = service
     try:
         if identity.current.proxied_by_user is not None:
             self.service = identity.current.proxied_by_user.user_name
     except identity.RequestRequiredException:
         pass
     self.field_name = field_name
     self.action = action
     # These values are likely to be truncated by MySQL, so let's make sure 
     # we don't end up with invalid UTF-8 chars at the end
     if old_value and isinstance(old_value, unicode):
         old_value = unicode_truncate(old_value,
             bytes_length=object_mapper(self).c.old_value.type.length)
     if new_value and isinstance(new_value, unicode):
         new_value = unicode_truncate(new_value,
             bytes_length=object_mapper(self).c.new_value.type.length)
     self.old_value = old_value
     self.new_value = new_value
コード例 #2
0
 def __init__(self,
              user=None,
              service=None,
              action=None,
              field_name=None,
              old_value=None,
              new_value=None,
              **kw):
     """
     The *service* argument should be a string such as 'Scheduler' or 
     'XMLRPC', describing the means by which the change has been made. This 
     constructor will override it with something more specific (such as the 
     name of an external service) if appropriate.
     """
     super(Activity, self).__init__(**kw)
     self.user = user
     self.service = service
     try:
         if identity.current.proxied_by_user is not None:
             self.service = identity.current.proxied_by_user.user_name
     except identity.RequestRequiredException:
         pass
     field_name_value_max_length = object_mapper(
         self).c.field_name.type.length
     self.field_name = field_name[:field_name_value_max_length]
     self.action = action
     # These values are likely to be truncated by MySQL, so let's make sure
     # we don't end up with invalid UTF-8 chars at the end
     if old_value and isinstance(old_value, unicode):
         old_value = unicode_truncate(
             old_value,
             bytes_length=object_mapper(self).c.old_value.type.length)
     if new_value and isinstance(new_value, unicode):
         new_value = unicode_truncate(
             new_value,
             bytes_length=object_mapper(self).c.new_value.type.length)
     self.old_value = old_value
     self.new_value = new_value
コード例 #3
0
 def test_truncates_on_character_boundaries(self):
     s = u'a\u044f\u044f\u044f\u044f'
     self.assertEqual(unicode_truncate(s, bytes_length=4), u'a\u044f')
コード例 #4
0
 def test_doesnt_mangle_short_values(self):
     s = u'a\u044f\u044f\u044f\u044f'
     self.assertEqual(unicode_truncate(s, bytes_length=100), s)
コード例 #5
0
ファイル: test_util.py プロジェクト: pombredanne/beaker-2
 def test_truncates_on_character_boundaries(self):
     s = u'a\u044f\u044f\u044f\u044f'
     self.assertEqual(unicode_truncate(s, bytes_length=4), u'a\u044f')
コード例 #6
0
ファイル: test_util.py プロジェクト: pombredanne/beaker-2
 def test_doesnt_mangle_short_values(self):
     s = u'a\u044f\u044f\u044f\u044f'
     self.assertEqual(unicode_truncate(s, bytes_length=100), s)