Skip to content

Commit

Permalink
writing error messages instead of raising assert errors
Browse files Browse the repository at this point in the history
  • Loading branch information
traut committed Sep 21, 2015
1 parent d164112 commit 533d1b7
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions cabby/entities.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

import logging

from libtaxii import constants as const


log = logging.getLogger(__name__)

SERVICE_TYPES = set(const.SVC_TYPES_11 + const.SVC_TYPES_10)


Expand Down Expand Up @@ -57,7 +60,8 @@ def __init__(self, name, description, type=TYPE_FEED, available=None,
polling_services=None, subscription_methods=None,
receiving_inboxes=None, volume=None):

assert type in [self.TYPE_FEED, self.TYPE_SET]
if type not in [self.TYPE_FEED, self.TYPE_SET]:
log.error("Unknown collection type: %s", type)

self.name = name
self.description = description
Expand Down Expand Up @@ -153,7 +157,8 @@ class SubscriptionParameters(Entity):
TYPE_COUNT = const.RT_COUNT_ONLY

def __init__(self, response_type, content_bindings=None):
assert response_type in [self.TYPE_FULL, self.TYPE_COUNT]
if response_type not in [self.TYPE_FULL, self.TYPE_COUNT]:
log.error("Unknown response type: %s", response_type)
self.response_type = response_type
self.content_bindings = content_bindings or []

Expand Down Expand Up @@ -181,8 +186,10 @@ class DetailedServiceInstance(Entity):
def __init__(self, type, version, protocol, address, message_bindings,
available=None, message=None):

assert version in [self.VERSION_10, self.VERSION_11]
assert protocol in [self.PROTOCOL_HTTP, self.PROTOCOL_HTTPS]
if version not in [self.VERSION_10, self.VERSION_11]:
log.error("Unknown service version: %s", version)
if protocol not in [self.PROTOCOL_HTTP, self.PROTOCOL_HTTPS]:
log.error("Unknown service protocol: %s", protocol)

self.type = type
self.version = version
Expand Down

0 comments on commit 533d1b7

Please sign in to comment.