##// END OF EJS Templates
Moved exception texts to constants for sync
neko259 -
r1539:5b492628 decentral
parent child Browse files
Show More
@@ -5,6 +5,11 b' from boards.utils import get_file_mimety'
5 5 from django.db import transaction
6 6 from boards.models import KeyPair, GlobalId, Signature, Post, Tag
7 7
8 EXCEPTION_NODE = 'Sync node returned an error: {}'
9 EXCEPTION_OP = 'Load the OP first'
10 EXCEPTION_DOWNLOAD = 'File was not downloaded'
11 EXCEPTION_HASH = 'File hash does not match attachment hash'
12 EXCEPTION_SIGNATURE = 'Invalid model signature for {}'
8 13 ENCODING_UNICODE = 'unicode'
9 14
10 15 TAG_MODEL = 'model'
@@ -176,7 +181,7 b' class SyncManager:'
176 181 if exists:
177 182 opening_post = Post.objects.get(global_id=op_global_id)
178 183 else:
179 raise SyncException('Load the OP first')
184 raise SyncException(EXCEPTION_OP)
180 185 else:
181 186 opening_post = None
182 187 tag_tags = tag_content.find(TAG_TAGS)
@@ -197,11 +202,11 b' class SyncManager:'
197 202 url = tag_ref.get(ATTR_URL)
198 203 attached_file = download(hostname + url)
199 204 if attached_file is None:
200 raise SyncException('File was not dowloaded')
205 raise SyncException(EXCEPTION_DOWNLOAD)
201 206
202 207 hash = get_file_hash(attached_file)
203 208 if hash != attachment.text:
204 raise SyncException('File hash does not match attachment hash')
209 raise SyncException(EXCEPTION_HASH)
205 210
206 211 files.append(attached_file)
207 212
@@ -210,8 +215,7 b' class SyncManager:'
210 215 opening_post=opening_post, tags=tags,
211 216 global_id=global_id, files=files)
212 217 else:
213 raise SyncException('Sync node returned an error: {}'.format(
214 tag_status.text))
218 raise SyncException(EXCEPTION_NODE.format(tag_status.text))
215 219
216 220 @staticmethod
217 221 def generate_response_pull():
@@ -247,7 +251,7 b' class SyncManager:'
247 251 signature=signature_value)
248 252
249 253 if not KeyPair.objects.verify(signature, content_str):
250 raise SyncException('Invalid model signature for {}'.format(content_str))
254 raise SyncException(EXCEPTION_SIGNATURE.format(content_str))
251 255
252 256 signatures.append(signature)
253 257
General Comments 0
You need to be logged in to leave comments. Login now