Commits

David Larlet  committed f24fd00

With recent versions of Python (2.5?), logging now handle unicode the right way

  • Participants
  • Parent commits 8683503

Comments (0)

Files changed (3)

File examples/django_roa_client/tests.py

 handle very well projects inside projects.
 """
 from datetime import time, date, datetime
+from decimal import Decimal
 
 from django.test import TestCase
 from django.conf import settings
 from django.test.client import Client
-from django.utils._decimal import Decimal
 from django.core.serializers import register_serializer
 from django.contrib.contenttypes.models import ContentType
 
         page = RemotePageWithManyFields.objects.create(decimal_field=1.55)
         self.assertEqual(page.decimal_field, 1.55)
         page = RemotePageWithManyFields.objects.get(id=page.id)
-        self.assertEqual(repr(page.decimal_field), 'Decimal("1.55")')
+        self.assertEqual(repr(page.decimal_field), "Decimal('1.55')")
         page.decimal_field = 20.09
         page.save()
         page = RemotePageWithManyFields.objects.get(id=page.id)
-        self.assertEqual(repr(page.decimal_field), 'Decimal("20.09")')
+        self.assertEqual(repr(page.decimal_field), "Decimal('20.09')")
         page.delete()
 
     def test_email_field(self):

File examples/django_roa_server/emitters.py

     """
     def render(self, request):
         response = super(ROADjangoEmitter, self).render(request, 'xml')
-        logger.debug("Response:\n%s" % str(response).decode(settings.DEFAULT_CHARSET))
+        logger.debug(u"Response:\n%s" % str(response).decode(settings.DEFAULT_CHARSET))
         return response
     
 Emitter.register('django', ROADjangoEmitter, 'application/xml; charset=utf-8')
     """
     def render(self, request):
         response = super(CustomDjangoEmitter, self).render(request, 'custom')
-        logger.debug("Response:\n%s" % response.decode(settings.DEFAULT_CHARSET))
+        logger.debug(u"Response:\n%s" % response.decode(settings.DEFAULT_CHARSET))
         return response
     
 Emitter.register('custom', CustomDjangoEmitter, 'application/xml; charset=utf-8')

File examples/django_roa_server/handlers.py

         obj_list = list(queryset)
         if not obj_list:
             raise Http404('No %s matches the given query.' % queryset.model._meta.object_name)
-        logger.debug('Objects: %s retrieved' % [unicode(obj).encode(settings.DEFAULT_CHARSET) for obj in obj_list])
+        logger.debug(u'Objects: %s retrieved' % [unicode(obj) for obj in obj_list])
         return queryset
         
     def create(self, request, *args, **kwargs):
         
         response = [self.model.objects.get(id=object.id)]
         #response = [object]
-        logger.debug('Object "%s" created' % unicode(object).encode(settings.DEFAULT_CHARSET))
+        logger.debug(u'Object "%s" created' % unicode(object))
         return response
 
     def update(self, request, *args, **kwargs):
             return rc.NOT_IMPLEMENTED
         
         data = request.PUT.copy()
-        logger.debug('Received: %s as PUT data' % data)
+        logger.debug(u'Received: %s as PUT data' % data)
         object = self._get_object(self.model, *args, **kwargs)
         
         for field in self.model._meta.local_fields:
         
         response = [self.model.objects.get(id=object.id)]
         #response = [object]
-        logger.debug('Object "%s" modified with %s' % (
-            unicode(object).encode(settings.DEFAULT_CHARSET), 
-            unicode(data.items()).encode(settings.DEFAULT_CHARSET)))
+        logger.debug(u'Object "%s" modified with %s' % (
+            unicode(object), unicode(data.items())))
         return response
 
     def delete(self, request, *args, **kwargs):
         try:
             object = self._get_object(self.model, *args, **kwargs)
             object.delete()
-            logger.debug('Object "%s" deleted, remains %s' % (
-                unicode(object).encode(settings.DEFAULT_CHARSET), 
-                [unicode(object).encode(settings.DEFAULT_CHARSET) for object in self.model.objects.all()]))
+            logger.debug(u'Object "%s" deleted, remains %s' % (
+                unicode(object), 
+                [unicode(object) for object in self.model.objects.all()]))
 
             return rc.DELETED
         except self.model.MultipleObjectsReturned:
         
         # Counting
         counter = queryset.count()
-        logger.debug('Count: %s objects' % counter)
+        logger.debug(u'Count: %s objects' % counter)
         return counter