From 579f77ceaa03a216a7a635c3d3a4d83b0e5868f8 Mon Sep 17 00:00:00 2001 From: Ryan Kaskel Date: Sat, 18 May 2013 17:04:17 +0100 Subject: [PATCH] Move function to compat. --- rest_framework/compat.py | 13 +++++++++++++ rest_framework/fields.py | 13 +------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index cd39f5445..76dc00526 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -495,3 +495,16 @@ except ImportError: oauth2_provider_forms = None oauth2_provider_scope = None oauth2_constants = None + +# Handle lazy strings +from django.utils.functional import Promise + +if six.PY3: + def is_non_str_iterable(obj): + if (isinstance(obj, str) or + (isinstance(obj, Promise) and obj._delegate_text)): + return False + return hasattr(obj, '__iter__') +else: + def is_non_str_iterable(obj): + return hasattr(obj, '__iter__') diff --git a/rest_framework/fields.py b/rest_framework/fields.py index d5cf30e43..b5f99823a 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -19,7 +19,6 @@ from django.db.models.fields import BLANK_CHOICE_DASH from django import forms from django.forms import widgets from django.utils.encoding import is_protected_type -from django.utils.functional import Promise from django.utils.translation import ugettext_lazy as _ from django.utils.datastructures import SortedDict @@ -27,7 +26,7 @@ from rest_framework import ISO_8601 from rest_framework.compat import timezone, parse_date, parse_datetime, parse_time from rest_framework.compat import BytesIO from rest_framework.compat import six -from rest_framework.compat import smart_text, force_text +from rest_framework.compat import smart_text, force_text, is_non_str_iterable from rest_framework.settings import api_settings @@ -46,16 +45,6 @@ def is_simple_callable(obj): len_defaults = len(defaults) if defaults else 0 return len_args <= len_defaults -if six.PY3: - def is_non_str_iterable(obj): - if (isinstance(obj, str) or - (isinstance(obj, Promise) and obj._delegate_text)): - return False - return hasattr(obj, '__iter__') -else: - def is_non_str_iterable(obj): - return hasattr(obj, '__iter__') - def get_component(obj, attr_name): """ Given an object, and an attribute name,