| 1 |
# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil -*- |
| 2 |
# |
| 3 |
# This program is free software; you can redistribute it and/or modify it under |
| 4 |
# the terms of the GNU Lesser General Public License as published by the Free |
| 5 |
# Software Foundation; either version 2 of the License, or (at your option) any |
| 6 |
# later version. |
| 7 |
# |
| 8 |
# This program is distributed in the hope that it will be useful, but WITHOUT |
| 9 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 10 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 11 |
# details. |
| 12 |
# |
| 13 |
# You should have received a copy of the GNU Lesser General Public License along |
| 14 |
# with this program; if not, write to the Free Software Foundation, Inc., 51 |
| 15 |
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 |
# |
| 17 |
# Copyright (C) 2012 Lanedo GmbH |
| 18 |
# Copyright (C) 2012-2022 Aleksander Morgado <[email protected]> |
| 19 |
# |
| 20 |
|
| 21 |
import utils |
| 22 |
from VariableInteger import VariableInteger |
| 23 |
from VariableString import VariableString |
| 24 |
from VariableStruct import VariableStruct |
| 25 |
from VariableSequence import VariableSequence |
| 26 |
from VariableArray import VariableArray |
| 27 |
|
| 28 |
|
| 29 |
""" |
| 30 |
Helps in the creation of Variable objects based on the specific 'format' found |
| 31 |
in the given dictionary |
| 32 |
""" |
| 33 |
def create_variable(service, dictionary, new_type_name, container_type): |
| 34 |
if utils.format_is_integer(dictionary['format']): |
| 35 |
return VariableInteger(service, dictionary) |
| 36 |
elif utils.format_is_float(dictionary['format']): |
| 37 |
return VariableInteger(service, dictionary) |
| 38 |
elif dictionary['format'] == 'string': |
| 39 |
return VariableString(service, dictionary) |
| 40 |
elif dictionary['format'] == 'struct': |
| 41 |
return VariableStruct(service, dictionary, new_type_name, container_type) |
| 42 |
elif dictionary['format'] == 'sequence': |
| 43 |
return VariableSequence(service, dictionary, new_type_name, container_type) |
| 44 |
elif dictionary['format'] == 'array': |
| 45 |
return VariableArray(service, dictionary, new_type_name, container_type) |
| 46 |
else: |
| 47 |
raise RuntimeError('Unexpected field format \'%s\'' % dictionary['format']) |