Revision | 6717844e7eb543c1fa2beda1765cb5e47758fa45 (tree) |
---|---|
Zeit | 2022-01-11 20:18:05 |
Autor | Sergey Gusarov <laborer2008@gmai...> |
Commiter | Sergey Gusarov |
Added user keyword module
@@ -19,6 +19,7 @@ | ||
19 | 19 | from card import Card |
20 | 20 | from comment import Comment |
21 | 21 | from contract import Contract |
22 | +from key_word import KeyWord | |
22 | 23 | |
23 | 24 | |
24 | 25 | class Description: |
@@ -142,6 +143,7 @@ | ||
142 | 143 | self._cards = [] |
143 | 144 | self._contracts = [] |
144 | 145 | self._comment = None |
146 | + self._keyWord = None | |
145 | 147 | |
146 | 148 | if bodyLen > 0: |
147 | 149 | lines = body.splitlines() |
@@ -222,7 +224,11 @@ | ||
222 | 224 | else: |
223 | 225 | logger.error('Multiple comments found in the account \'' + accountName + '\'') |
224 | 226 | elif keyWord.startswith(Description.KeyWord.KEYWORD): |
225 | - pass | |
227 | + userKeyWord = KeyWord(lineItems[1]) | |
228 | + if self._keyWord is None: | |
229 | + self._keyWord = userKeyWord | |
230 | + else: | |
231 | + logger.error('Multiple keywords found in the account \'' + accountName + '\'') | |
226 | 232 | elif keyWord.startswith(Description.KeyWord.EXCESS): |
227 | 233 | pass |
228 | 234 | else: |
@@ -248,6 +254,10 @@ | ||
248 | 254 | return self._comment |
249 | 255 | |
250 | 256 | @property |
257 | + def keyWord(self): | |
258 | + return self._keyWord | |
259 | + | |
260 | + @property | |
251 | 261 | def contracts(self): |
252 | 262 | return self.contracts |
253 | 263 |
@@ -0,0 +1,22 @@ | ||
1 | +#!/usr/bin/env python3 | |
2 | +# -*- coding: utf-8 -*- | |
3 | + | |
4 | +""" | |
5 | +Some text associated with card or account | |
6 | + | |
7 | +""" | |
8 | + | |
9 | + | |
10 | +class KeyWord(str): | |
11 | + # Just to restrict stack overflow | |
12 | + MAX_LENGTH = 40 | |
13 | + | |
14 | + def __new__(cls, content): | |
15 | + if not ((type(content) is str) or (type(content) is KeyWord)): | |
16 | + raise TypeError('Invalid keyword type: \'' + type(content).__name__ + '\'') | |
17 | + | |
18 | + lenContent = len(content) | |
19 | + if (lenContent == 0) or (lenContent > KeyWord.MAX_LENGTH): | |
20 | + raise ValueError('Invalid keyword length: ' + str(lenContent)) | |
21 | + | |
22 | + return super().__new__(cls, content) |