david / django-roa (http://welldev.org/)

Turn your models into remote resources that you can access through Django's ORM. ROA stands for Resource Oriented Architecture.

Clone this repository (size: 560.7 KB): HTTPS / SSH
$ hg clone http://code.welldev.org/django-roa

Changed (Δ527 bytes):

raw changeset »

piston/emitters.py (12 lines added, 2 lines removed)

piston/utils.py (16 lines added, 13 lines removed)

Up to file-list piston/emitters.py:

@@ -402,7 +402,7 @@ class YAMLEmitter(Emitter):
402
402
403
403
if yaml:  # Only register yaml if it was import successfully.
404
404
    Emitter.register('yaml', YAMLEmitter, 'application/x-yaml; charset=utf-8')
405
    Mimer.register(yaml.load, ('application/x-yaml',))
405
    Mimer.register(lambda s: dict(yaml.load(s)), ('application/x-yaml',))
406
406
407
407
class PickleEmitter(Emitter):
408
408
    """
@@ -412,7 +412,17 @@ class PickleEmitter(Emitter):
412
412
        return pickle.dumps(self.construct())
413
413
        
414
414
Emitter.register('pickle', PickleEmitter, 'application/python-pickle')
415
Mimer.register(pickle.loads, ('application/python-pickle',))
415
416
"""
417
WARNING: Accepting arbitrary pickled data is a huge security concern.
418
The unpickler has been disabled by default now, and if you want to use
419
it, please be aware of what implications it will have.
420
421
Read more: http://nadiana.com/python-pickle-insecure
422
423
Uncomment the line below to enable it. You're doing so at your own risk.
424
"""
425
# Mimer.register(pickle.loads, ('application/python-pickle',))
416
426
417
427
class DjangoEmitter(Emitter):
418
428
    """

Up to file-list piston/utils.py:

@@ -179,7 +179,7 @@ class Mimer(object):
179
179
            for mime in mimes:
180
180
                if ctype.startswith(mime):
181
181
                    return loadee
182
182
                    
183
183
    def content_type(self):
184
184
        """
185
185
        Returns the content type of the request in all cases where it is
@@ -193,7 +193,6 @@ class Mimer(object):
193
193
            return None
194
194
        
195
195
        return ctype
196
        
197
196
198
197
    def translate(self):
199
198
        """
@@ -214,15 +213,18 @@ class Mimer(object):
214
213
        if not self.is_multipart() and ctype:
215
214
            loadee = self.loader_for_type(ctype)
216
215
            
217
            try:
218
                self.request.data = loadee(self.request.raw_post_data)
219
                    
220
                # Reset both POST and PUT from request, as its
221
                # misleading having their presence around.
222
                self.request.POST = self.request.PUT = dict()
223
            except (TypeError, ValueError):
224
                # This also catches if loadee is None.
225
                raise MimerDataException
216
            if loadee:
217
                try:
218
                    self.request.data = loadee(self.request.raw_post_data)
219
                        
220
                    # Reset both POST and PUT from request, as its
221
                    # misleading having their presence around.
222
                    self.request.POST = self.request.PUT = dict()
223
                except (TypeError, ValueError):
224
                    # This also catches if loadee is None.
225
                    raise MimerDataException
226
            else:
227
                self.request.data = None
226
228
227
229
        return self.request
228
230
                
@@ -298,12 +300,13 @@ def send_consumer_mail(consumer):
298
300
    except AttributeError:
299
301
        sender = settings.DEFAULT_FROM_EMAIL
300
302
301
    send_mail(_(subject), body, sender, [consumer.user.email], fail_silently=True)
303
    if consumer.user:
304
        send_mail(_(subject), body, sender, [consumer.user.email], fail_silently=True)
302
305
303
306
    if consumer.status == 'pending' and len(settings.ADMINS):
304
307
        mail_admins(_(subject), body, fail_silently=True)
305
308
306
    if settings.DEBUG:
309
    if settings.DEBUG and consumer.user:
307
310
        print "Mail being sent, to=%s" % consumer.user.email
308
311
        print "Subject: %s" % _(subject)
309
312
        print body