# HG changeset patch # User neko259 # Date 2016-05-09 15:42:30 # Node ID 5b4926289e425aa37b076a72cfa91a6277c8539f # Parent 8b37a0720ae9c5b636fcc36e9ada5400f8b952e4 Moved exception texts to constants for sync diff --git a/boards/models/post/sync.py b/boards/models/post/sync.py --- a/boards/models/post/sync.py +++ b/boards/models/post/sync.py @@ -5,6 +5,11 @@ from boards.utils import get_file_mimety from django.db import transaction from boards.models import KeyPair, GlobalId, Signature, Post, Tag +EXCEPTION_NODE = 'Sync node returned an error: {}' +EXCEPTION_OP = 'Load the OP first' +EXCEPTION_DOWNLOAD = 'File was not downloaded' +EXCEPTION_HASH = 'File hash does not match attachment hash' +EXCEPTION_SIGNATURE = 'Invalid model signature for {}' ENCODING_UNICODE = 'unicode' TAG_MODEL = 'model' @@ -176,7 +181,7 @@ class SyncManager: if exists: opening_post = Post.objects.get(global_id=op_global_id) else: - raise SyncException('Load the OP first') + raise SyncException(EXCEPTION_OP) else: opening_post = None tag_tags = tag_content.find(TAG_TAGS) @@ -197,11 +202,11 @@ class SyncManager: url = tag_ref.get(ATTR_URL) attached_file = download(hostname + url) if attached_file is None: - raise SyncException('File was not dowloaded') + raise SyncException(EXCEPTION_DOWNLOAD) hash = get_file_hash(attached_file) if hash != attachment.text: - raise SyncException('File hash does not match attachment hash') + raise SyncException(EXCEPTION_HASH) files.append(attached_file) @@ -210,8 +215,7 @@ class SyncManager: opening_post=opening_post, tags=tags, global_id=global_id, files=files) else: - raise SyncException('Sync node returned an error: {}'.format( - tag_status.text)) + raise SyncException(EXCEPTION_NODE.format(tag_status.text)) @staticmethod def generate_response_pull(): @@ -247,7 +251,7 @@ class SyncManager: signature=signature_value) if not KeyPair.objects.verify(signature, content_str): - raise SyncException('Invalid model signature for {}'.format(content_str)) + raise SyncException(EXCEPTION_SIGNATURE.format(content_str)) signatures.append(signature)