#!/usr/bin/env python
"""
Copyright 2015 Brocade Communications Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import xml.etree.ElementTree as ET


def return_xml(element_tree):
    """Return an XML Element.

        Args:
            element_tree (Element): XML Element to be returned.  If sent as a
                ``str``, this function will attempt to convert it to an
                ``Element``.

        Returns:
            Element: An XML Element.

        Raises:
            TypeError: if `element_tree` is not of type ``Element`` and it
                cannot be converted from a ``str``.

        Examples:
            >>> import pynos.utilities
            >>> import xml.etree.ElementTree as ET
            >>> ele = pynos.utilities.return_xml(ET.Element('config'))
            >>> assert isinstance(ele, ET.Element)
            >>> ele = pynos.utilities.return_xml('<config />')
            >>> assert isinstance(ele, ET.Element)
            >>> ele = pynos.utilities.return_xml(
            ... ['hodor']) # doctest: +IGNORE_EXCEPTION_DETAIL
            Traceback (most recent call last):
            TypeError
    """
    if isinstance(element_tree, ET.Element):
        return element_tree
    try:
        return ET.fromstring(element_tree)
    except TypeError:
        raise TypeError('{} takes either {} or {} type.'
                        .format(repr(return_xml.__name__),
                                repr(str.__name__),
                                repr(ET.Element.__name__)))


def print_xml_string(element_tree):
    """Prints the string representation of an XML Element.

        Args:
            element_tree (Element): XML Element to be returned.  If sent as a
                ``str``, this function will attempt to convert it to an
                ``Element``.

        Returns:
            Element: An XML Element.

        Examples:
            >>> import pynos.utilities
            >>> import xml.etree.ElementTree as ET
            >>> pynos.utilities.print_xml_string(ET.Element('config'))
            '<config />'
            >>> ele = pynos.utilities.return_xml(
            ... ['hodor']) # doctest: +IGNORE_EXCEPTION_DETAIL
            Traceback (most recent call last):
            AttributeError
    """
    print(ET.tostring(element_tree))

@@ -591,16 +591,54 @@
 se.%0A%22%22%22%0A
+from __future__ import print_function%0A
 import x
@@ -2368,32 +2368,123 @@
 n XML Element.%0A%0A
+        Raises:%0A            AttributeError: if %60element_tree%60 is not of type %60%60Element%60%60.%0A%0A
         Examples
@@ -2658,17 +2658,16 @@
         
-'
 %3Cconfig 
@@ -2668,17 +2668,16 @@
 onfig /%3E
-'
 %0A       
@@ -2676,38 +2676,32 @@
 %0A            %3E%3E%3E
- ele =
  pynos.utilities
@@ -2697,34 +2697,40 @@
 s.utilities.
-return_xml
+print_xml_string
 (%0A          

fix print_xml_string method add raises section to docstring fix doctest method to be print_xml_string instead of return_xml