Skip to content
Snippets Groups Projects
Commit 54fe99cd authored by ptangu01's avatar ptangu01
Browse files

add test on valid addr and target

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/trunk@1369 b32b6428-25c9-4566-ad07-03861ab6144f
parent da25cd07
No related branches found
No related tags found
No related merge requests found
......@@ -131,6 +131,8 @@ class Device(object):
# Address
def set_address(self, value):
if not tools.valid_addr(value):
raise DeviceError("This address is not valid")
if value == config.XAAL_BCAST_ADDR:
raise DeviceError("This address is reserved")
self.__address = value
......
......@@ -26,6 +26,7 @@ except ImportError:
import json
from . import config
from . import tools
import datetime
import pysodium
import base64
......@@ -241,6 +242,15 @@ class MessageFactory():
return message
class MessageError(Exception):
def __init__(self, value):
self.message = value
def __str__(self):
return repr(self.message)
class Message():
def __init__(self):
......@@ -266,6 +276,9 @@ class Message():
raise TypeError(
"Expected a list for targetsList, got %s" %
(type(values),))
for val in values:
if not tools.valid_addr(val):
raise MessageError("Bad target addr: %s" % val)
self._targets = values
def get_targets(self):
......
......@@ -22,6 +22,7 @@
import os
import uuid
import re
import pysodium
......@@ -37,6 +38,9 @@ else:
from ConfigParser import RawConfigParser as ConfigParser
XAAL_ADDR_PATTERN = '^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$'
def get_cfg_file(name, cfg_dir=config.CONF_DIR):
filename = '%s.conf' % name
if os.path.isdir(cfg_dir):
......@@ -87,6 +91,13 @@ def get_random_uuid():
return uuid.uuid1().__str__()
def valid_addr(val):
result = False
if re.match(XAAL_ADDR_PATTERN,val):
result = True
return result
def get_logger(name, level, filename=None):
"""
It creates logger if doesn't exist.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment