Permalink
Browse files

Fixed #20841 -- Added messages to NotImplementedErrors

Thanks joseph at vertstudios.com for the suggestion.
  • Loading branch information...
1 parent d59f199 commit b2b763448f726ee952743596e9a34fcb154bdb12 @Cheekio Cheekio committed with timgraham Sep 6, 2013
@@ -33,26 +33,26 @@ def has_output(self):
"""
Returns True if some choices would be output for this filter.
"""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of ListFilter must provide a has_output() method')
def choices(self, cl):
"""
Returns choices ready to be output in the template.
"""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of ListFilter must provide a choices() method')
def queryset(self, request, queryset):
"""
Returns the filtered queryset.
"""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of ListFilter must provide a queryset() method')
def expected_parameters(self):
"""
Returns the list of parameter names that are expected from the
request's query string and that will be used by this filter.
"""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of ListFilter must provide an expected_parameters() method')
class SimpleListFilter(ListFilter):
@@ -89,7 +89,9 @@ def lookups(self, request, model_admin):
"""
Must be overridden to return a list of tuples (value, verbose value)
"""
- raise NotImplementedError
+ raise NotImplementedError(
+ 'The SimpleListFilter.lookups() method must be overridden to '
+ 'return a list of tuples (value, verbose value)')
def expected_parameters(self):
return [self.parameter_name]
@@ -192,7 +192,7 @@ def verify(self, password, encoded):
"""
Checks if the given password is correct
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of BasePasswordHasher must provide a verify() method')
def encode(self, password, salt):
"""
@@ -201,7 +201,7 @@ def encode(self, password, salt):
The result is normally formatted as "algorithm$salt$hash" and
must be fewer than 128 characters.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of BasePasswordHasher must provide an encode() method')
def safe_summary(self, encoded):
"""
@@ -210,7 +210,7 @@ def safe_summary(self, encoded):
The result is a dictionary and will be used where the password field
must be displayed to construct a safe representation of the password.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of BasePasswordHasher must provide a safe_summary() method')
class PBKDF2PasswordHasher(BasePasswordHasher):
@@ -245,10 +245,10 @@ def has_usable_password(self):
return is_password_usable(self.password)
def get_full_name(self):
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of AbstractBaseUser must provide a get_full_name() method')
def get_short_name(self):
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of AbstractBaseUser must provide a get_short_name() method.')
# A few helper functions for common logic between User and AnonymousUser.
@@ -441,16 +441,16 @@ def __hash__(self):
return 1 # instances always return the same hash value
def save(self):
- raise NotImplementedError
+ raise NotImplementedError("Django doesn't provide a DB representation for AnonymousUser.")
def delete(self):
- raise NotImplementedError
+ raise NotImplementedError("Django doesn't provide a DB representation for AnonymousUser.")
def set_password(self, raw_password):
- raise NotImplementedError
+ raise NotImplementedError("Django doesn't provide a DB representation for AnonymousUser.")
def check_password(self, raw_password):
- raise NotImplementedError
+ raise NotImplementedError("Django doesn't provide a DB representation for AnonymousUser.")
def _get_groups(self):
return self._groups
@@ -112,7 +112,7 @@ def get_target_ctype_pk(self, context):
def get_context_value_from_queryset(self, context, qs):
"""Subclasses should override this."""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of BaseCommentNode must provide a get_context_value_from_queryset() method')
class CommentListNode(BaseCommentNode):
"""Insert a list of comments into the context."""
@@ -338,4 +338,3 @@ def get_comment_permalink(comment, anchor_pattern=None):
if anchor_pattern:
return comment.get_absolute_url(anchor_pattern)
return comment.get_absolute_url()
-
@@ -101,7 +101,7 @@ def geo_db_type(self, f):
Returns the database column type for the geometry field on
the spatial backend.
"""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of BaseSpatialOperations must provide a geo_db_type() method')
def get_distance(self, f, value, lookup_type):
"""
@@ -117,7 +117,7 @@ def get_geom_placeholder(self, f, value):
stored procedure call to the transformation function of the spatial
backend.
"""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of BaseSpatialOperations must provide a geo_db_placeholder() method')
def get_expression_column(self, evaluator):
"""
@@ -134,14 +134,14 @@ def spatial_aggregate_sql(self, agg):
raise NotImplementedError('Aggregate support not implemented for this spatial backend.')
def spatial_lookup_sql(self, lvalue, lookup_type, value, field):
- raise NotImplementedError
+ raise NotImplementedError('subclasses of BaseSpatialOperations must a provide spatial_lookup_sql() method')
# Routines for getting the OGC-compliant models.
def geometry_columns(self):
- raise NotImplementedError
+ raise NotImplementedError('subclasses of BaseSpatialOperations must a provide geometry_columns() method')
def spatial_ref_sys(self):
- raise NotImplementedError
+ raise NotImplementedError('subclasses of BaseSpatialOperations must a provide spatial_ref_sys() method')
@python_2_unicode_compatible
class SpatialRefSysMixin(object):
@@ -105,7 +105,7 @@ def _get(self, *args, **kwargs):
just containing no messages) then ``None`` should be returned in
place of ``messages``.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of BaseStorage must provide a _get() method')
def _store(self, messages, response, *args, **kwargs):
"""
@@ -116,7 +116,7 @@ def _store(self, messages, response, *args, **kwargs):
**This method must be implemented by a subclass.**
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of BaseStorage must provide a _store() method')
def _prepare_messages(self, messages):
"""
@@ -284,36 +284,36 @@ def exists(self, session_key):
"""
Returns True if the given session_key already exists.
"""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of SessionBase must provide an exists() method')
def create(self):
"""
Creates a new session instance. Guaranteed to create a new object with
a unique key and will have saved the result once (with empty data)
before the method returns.
"""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of SessionBase must provide a create() method')
def save(self, must_create=False):
"""
Saves the session data. If 'must_create' is True, a new session object
is created (otherwise a CreateError exception is raised). Otherwise,
save() can update an existing object with the same key.
"""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of SessionBase must provide a save() method')
def delete(self, session_key=None):
"""
Deletes the session data under this key. If the key is None, the
current session key value is used.
"""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of SessionBase must provide a delete() method')
def load(self):
"""
Loads the session data and returns a dictionary.
"""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of SessionBase must provide a load() method')
@classmethod
def clear_expired(cls):
@@ -324,4 +324,4 @@ def clear_expired(cls):
NotImplementedError. If it isn't necessary, because the backend has
a built-in expiration mechanism, it should be a no-op.
"""
- raise NotImplementedError
+ raise NotImplementedError('This backend does not support clear_expired().')
@@ -28,15 +28,15 @@ def find(self, path, all=False):
the first found file path will be returned; if set
to ``True`` a list of all found files paths is returned.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of BaseFinder must provide a find() method')
def list(self, ignore_patterns):
"""
Given an optional list of paths to ignore, this should return
a two item iterable consisting of the relative path and storage
instance.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of BaseFinder must provide a list() method')
class FileSystemFinder(BaseFinder):
@@ -96,27 +96,27 @@ def add(self, key, value, timeout=DEFAULT_TIMEOUT, version=None):
Returns True if the value was stored, False otherwise.
"""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of BaseCache must provide an add() method')
def get(self, key, default=None, version=None):
"""
Fetch a given key from the cache. If the key does not exist, return
default, which itself defaults to None.
"""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of BaseCache must provide a get() method')
def set(self, key, value, timeout=DEFAULT_TIMEOUT, version=None):
"""
Set a value in the cache. If timeout is given, that timeout will be
used for the key; otherwise the default cache timeout will be used.
"""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of BaseCache must provide a set() method')
def delete(self, key, version=None):
"""
Delete a key from the cache, failing silently.
"""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of BaseCache must provide a delete() method')
def get_many(self, keys, version=None):
"""
@@ -190,7 +190,7 @@ def delete_many(self, keys, version=None):
def clear(self):
"""Remove *all* values from the cache at once."""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of BaseCache must provide a clear() method')
def validate_key(self, key):
"""
@@ -92,55 +92,55 @@ def delete(self, name):
"""
Deletes the specified file from the storage system.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of Storage must provide a delete() method')
def exists(self, name):
"""
Returns True if a file referened by the given name already exists in the
storage system, or False if the name is available for a new file.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of Storage must provide a exists() method')
def listdir(self, path):
"""
Lists the contents of the specified path, returning a 2-tuple of lists;
the first item being directories, the second item being files.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of Storage must provide a listdir() method')
def size(self, name):
"""
Returns the total size, in bytes, of the file specified by name.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of Storage must provide a size() method')
def url(self, name):
"""
Returns an absolute URL where the file's contents can be accessed
directly by a Web browser.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of Storage must provide a url() method')
def accessed_time(self, name):
"""
Returns the last accessed time (as datetime object) of the file
specified by name.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of Storage must provide an accessed_time() method')
def created_time(self, name):
"""
Returns the creation time (as datetime object) of the file
specified by name.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of Storage must provide a created_time() method')
def modified_time(self, name):
"""
Returns the last modified time (as datetime object) of the file
specified by name.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of Storage must provide a modified_time() method')
class FileSystemStorage(Storage):
"""
@@ -104,7 +104,7 @@ def receive_data_chunk(self, raw_data, start):
Receive data from the streamed upload parser. ``start`` is the position
in the file of the chunk.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of FileUploadHandler must provide a recieve_data_chunk() method')
def file_complete(self, file_size):
"""
@@ -113,7 +113,7 @@ def file_complete(self, file_size):
Subclasses should return a valid ``UploadedFile`` object.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of FileUploadHandler must provide a file_complete() method')
def upload_complete(self):
"""
@@ -36,4 +36,4 @@ def send_messages(self, email_messages):
Sends one or more EmailMessage objects and returns the number of email
messages sent.
"""
- raise NotImplementedError
+ raise NotImplementedError('subclasses of BaseEmailBackend must override send_messages() method')
@@ -325,7 +325,7 @@ def handle(self, *args, **options):
this method.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of BaseCommand must provide a handle() method')
class AppCommand(BaseCommand):
@@ -361,7 +361,7 @@ def handle_app(self, app, **options):
the command line.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of AppCommand must provide a handle_app() method')
class LabelCommand(BaseCommand):
@@ -397,7 +397,7 @@ def handle_label(self, label, **options):
string as given on the command line.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of LabelCommand must provide a handle_label() method')
class NoArgsCommand(BaseCommand):
@@ -423,4 +423,4 @@ def handle_noargs(self, **options):
Perform this command's actions.
"""
- raise NotImplementedError()
+ raise NotImplementedError('subclasses of NoArgsCommand must provide a handle_noargs() method')
Oops, something went wrong.

0 comments on commit b2b7634

Please sign in to comment.