blob: 9cb7b4d5e9ecf3bff39b962d4054f64b7aafd3ad [file] [log] [blame]
piotr437f5462014-02-04 17:57:25 +01001#
2# Copyright 2010 Free Software Foundation, Inc.
3#
Vasil Velichkov1789ae22019-08-13 20:32:05 +00004# This file was generated by gr_modtool, a tool from the GNU Radio framework
5# This file is a part of gr-gsm
piotr437f5462014-02-04 17:57:25 +01006#
7# GNU Radio is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 3, or (at your option)
10# any later version.
11#
12# GNU Radio is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with GNU Radio; see the file COPYING. If not, write to
19# the Free Software Foundation, Inc., 51 Franklin Street,
20# Boston, MA 02110-1301, USA.
21#
22"""
23Utilities for extracting text from generated classes.
24"""
Vasil Velichkov1789ae22019-08-13 20:32:05 +000025from __future__ import unicode_literals
piotr437f5462014-02-04 17:57:25 +010026
27def is_string(txt):
28 if isinstance(txt, str):
29 return True
30 try:
Vasil Velichkov1789ae22019-08-13 20:32:05 +000031 if isinstance(txt, str):
piotr437f5462014-02-04 17:57:25 +010032 return True
33 except NameError:
34 pass
35 return False
36
37def description(obj):
38 if obj is None:
39 return None
40 return description_bit(obj).strip()
41
42def description_bit(obj):
43 if hasattr(obj, 'content'):
44 contents = [description_bit(item) for item in obj.content]
45 result = ''.join(contents)
46 elif hasattr(obj, 'content_'):
47 contents = [description_bit(item) for item in obj.content_]
48 result = ''.join(contents)
49 elif hasattr(obj, 'value'):
50 result = description_bit(obj.value)
51 elif is_string(obj):
52 return obj
53 else:
Vasil Velichkov1789ae22019-08-13 20:32:05 +000054 raise Exception('Expecting a string or something with content, content_ or value attribute')
piotr437f5462014-02-04 17:57:25 +010055 # If this bit is a paragraph then add one some line breaks.
56 if hasattr(obj, 'name') and obj.name == 'para':
57 result += "\n\n"
58 return result