Skip to content

Commit

Permalink
Merge pull request #17 from AspenWeb/exceptions-cleanup
Browse files Browse the repository at this point in the history
Clean up exceptions
  • Loading branch information
chadwhitacre authored Jul 28, 2016
2 parents 7ea69c1 + 5ba32d2 commit 0d06227
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
13 changes: 1 addition & 12 deletions aspen/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,10 @@

import os

from ..exceptions import ConfigurationError
from ..utils import ascii_dammit


class ConfigurationError(StandardError):
"""This is an error in any part of our configuration.
"""

def __init__(self, msg):
StandardError.__init__(self)
self.msg = msg

def __str__(self):
return self.msg


def configure(knobs, d, env_prefix, kwargs):
for name, (default, func) in sorted(knobs.items()):

Expand Down
19 changes: 19 additions & 0 deletions aspen/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
from __future__ import unicode_literals


class ConfigurationError(Exception):
"""This is an error in any part of our configuration.
"""

def __init__(self, msg):
Exception.__init__(self)
self.msg = msg

def __str__(self):
return self.msg


class LoadError(Exception):
"""Represent a problem loading a resource.
"""
Expand All @@ -19,3 +31,10 @@ def __init__(self, accept, available_types):

def __str__(self):
return self.message


class TypecastError(Exception):

def __init__(self, extension):
self.msg = "Failure to typecast extension '{0}'".format(extension)
Exception.__init__(self)
5 changes: 1 addition & 4 deletions aspen/request_processor/typecasting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
from __future__ import print_function
from __future__ import unicode_literals

from ..exceptions import TypecastError

class TypecastError(Exception):
def __init__(self, extension):
self.msg = "Failure to typecast extension '{0}'".format(extension)
Exception.__init__(self)

"""
A typecast dict (like 'defaults' below) is a map of
Expand Down
6 changes: 1 addition & 5 deletions aspen/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@
import sys
import traceback

from .exceptions import LoadError
from .http.resource import Dynamic, Static


__cache__ = dict() # cache, keyed to filesystem path


class LoadError(Exception):
"""Represent a problem loading a resource.
"""


class Entry:
"""An entry in the global resource cache.
"""
Expand Down
5 changes: 3 additions & 2 deletions tests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import os
from pytest import raises

from aspen.request_processor import dispatcher, typecasting
from aspen.exceptions import TypecastError
from aspen.request_processor import dispatcher


# Helpers
Expand Down Expand Up @@ -205,7 +206,7 @@ def test_virtual_path_typecasts_to_int(harness):

def test_virtual_path_raises_on_bad_typecast(harness):
harness.fs.www.mk(('%year.int/foo.html', "Greetings, program!"),)
raises(typecasting.TypecastError, assert_fs, harness, '/I am not a year./foo.html', '')
raises(TypecastError, assert_fs, harness, '/I am not a year./foo.html', '')

def test_virtual_path_raises_on_direct_access(harness):
assert_raises_NotFound(harness, '/%name/foo.html', '')
Expand Down

0 comments on commit 0d06227

Please sign in to comment.