From b358fbdbe9cbd4ce644c4b2c7b9b4cec0811e14e Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 29 Apr 2011 14:32:56 +0100 Subject: More refactoring - move various less core stuff into utils etc --- djangorestframework/compat.py | 66 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 7 deletions(-) (limited to 'djangorestframework/compat.py') diff --git a/djangorestframework/compat.py b/djangorestframework/compat.py index 22b57186..98fbbb62 100644 --- a/djangorestframework/compat.py +++ b/djangorestframework/compat.py @@ -1,9 +1,24 @@ """Compatability module to provide support for backwards compatability with older versions of django/python""" +# cStringIO only if it's available +try: + import cStringIO as StringIO +except ImportError: + import StringIO + + +# parse_qs +try: + # python >= ? + from urlparse import parse_qs +except ImportError: + # python <= ? + from cgi import parse_qs + + # django.test.client.RequestFactory (Django >= 1.3) try: from django.test.client import RequestFactory - except ImportError: from django.test import Client from django.core.handlers.wsgi import WSGIRequest @@ -49,7 +64,7 @@ except ImportError: # django.views.generic.View (Django >= 1.3) try: from django.views.generic import View -except: +except ImportError: from django import http from django.utils.functional import update_wrapper # from django.utils.log import getLogger @@ -127,10 +142,47 @@ except: #) return http.HttpResponseNotAllowed(allowed_methods) -# parse_qs + try: - # python >= ? - from urlparse import parse_qs + import markdown + import re + + class CustomSetextHeaderProcessor(markdown.blockprocessors.BlockProcessor): + """Override markdown's SetextHeaderProcessor, so that ==== headers are