How to use the gpxpy.utils.make_str function in gpxpy

To help you get started, we’ve selected a few gpxpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tkrajina / gpxpy / gpxpy / parser.py View on Github external
def init(self, xml_or_file):
        """
        Store the XML and remove utf-8 Byte Order Mark if present.

        Args:
            xml_or_file: string or file object containing the gpx
                formatted xml

        """
        text = xml_or_file.read() if hasattr(xml_or_file, 'read') else xml_or_file
        self.xml = mod_utils.make_str(text)
github tkrajina / gpxpy / gpxpy / gpxfield.py View on Github external
tag_open = bool(tag)
    body = []
    if tag:
        body.append('\n' + indent + '<' + tag)
        if tag == 'gpx':  # write nsmap in root node
            body.append(' xmlns="{0}"'.format(nsmap['defaultns']))
            namespaces = set(nsmap.keys())
            namespaces.remove('defaultns')
            for prefix in sorted(namespaces):
                body.append(
                    ' xmlns:{0}="{1}"'.format(prefix, nsmap[prefix])
                )
        if custom_attributes:
            # Make sure to_xml() always return attributes in the same order:
            for key in sorted(custom_attributes.keys()):
                body.append(' {0}="{1}"'.format(key, mod_utils.make_str(custom_attributes[key])))
    suppressuntil = ''
    for gpx_field in fields:
        # strings indicate non-data container tags with subelements
        if isinstance(gpx_field, str):
            # Suppress empty tags
            if suppressuntil:
                if suppressuntil == gpx_field:
                    suppressuntil = ''
            else:
                suppressuntil, gpx_field = _check_dependents(instance,
                                                             gpx_field)
                if not suppressuntil:
                    if tag_open:
                        body.append('>')
                        tag_open = False
                    if gpx_field[0] == '/':
github tkrajina / gpxpy / gpxpy / gpxfield.py View on Github external
def to_xml(self, value, version, nsmap=None, prettyprint=True, indent=''):
        if value is None:
            return ''
        if not prettyprint:
            indent = ''
        if self.attribute:
            return '{0}="{1}"'.format(self.attribute, mod_utils.make_str(value))
        elif self.type_converter:
            value = self.type_converter.to_string(value)
        return mod_utils.to_xml(self.tag, content=value, escape=True,
                                prettyprint=prettyprint, indent=indent)
github tkrajina / gpxpy / gpxpy / gpxfield.py View on Github external
        self.to_string =   lambda flt    : mod_utils.make_str(flt)