piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2010 Free Software Foundation, Inc. |
| 3 | # |
Vasil Velichkov | 1789ae2 | 2019-08-13 20:32:05 +0000 | [diff] [blame] | 4 | # This file was generated by gr_modtool, a tool from the GNU Radio framework |
| 5 | # This file is a part of gr-gsm |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 6 | # |
| 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 | """ |
| 23 | Utilities for extracting text from generated classes. |
| 24 | """ |
Vasil Velichkov | 1789ae2 | 2019-08-13 20:32:05 +0000 | [diff] [blame] | 25 | from __future__ import unicode_literals |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 26 | |
| 27 | def is_string(txt): |
| 28 | if isinstance(txt, str): |
| 29 | return True |
| 30 | try: |
Vasil Velichkov | 1789ae2 | 2019-08-13 20:32:05 +0000 | [diff] [blame] | 31 | if isinstance(txt, str): |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 32 | return True |
| 33 | except NameError: |
| 34 | pass |
| 35 | return False |
| 36 | |
| 37 | def description(obj): |
| 38 | if obj is None: |
| 39 | return None |
| 40 | return description_bit(obj).strip() |
| 41 | |
| 42 | def 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 Velichkov | 1789ae2 | 2019-08-13 20:32:05 +0000 | [diff] [blame] | 54 | raise Exception('Expecting a string or something with content, content_ or value attribute') |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 55 | # 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 |