def get_href(self):
        """
        Gets the href for this collection. If the meta object has a ``url``
        set, it is returned. Otherwise, it concatenates the href of the parent
        object and the name of this collection to form the href and returns it.

        :returns: The href of this collection.

        """
        if self._meta_object.url is not None:
            return self._meta_object.url
        else:
            return self._parent.get_href() + "/" + xmlutil.make_xml_name(self._name)
Beispiel #2
0
 def _describe_methods(self):
     result = []
     if 'methods' in self._meta_object.values and \
         self._meta_object.values['methods'] is not None:
         for k, v in self._meta_object.values['methods'].items():
             if 'name' in v:
                 name = v['name']
             elif 'xml_name' in v:
                 name = v['xml_name']
             name = xmlutil.make_xml_name(name)
             url = '/'.join(['...', name])
             result.append((k, url))
     result.sort()
     return result
Beispiel #3
0
    def get_href(self):
        """
        Gets the href for this collection. If the meta object has a ``url``
        set, it is returned. Otherwise, it concatenates the href of the parent
        object and the name of this collection to form the href and returns it.

        :returns: The href of this collection.

        """
        if self._meta_object.url is not None:
            return self._meta_object.url
        else:
            return self._parent.get_href() + "/" + xmlutil.make_xml_name(
                self._name)
Beispiel #4
0
 def _describe_methods(self):
     result = []
     if 'methods' in self._meta_object.values and \
         self._meta_object.values['methods'] is not None:
         for k, v in self._meta_object.values['methods'].items():
             if 'name' in v:
                 name = v['name']
             elif 'xml_name' in v:
                 name = v['xml_name']
             name = xmlutil.make_xml_name(name)
             url = '/'.join(['...', name])
             result.append((k, url))
     result.sort()
     return result
Beispiel #5
0
    def __getattr__(self, attr):
        """
        This method is overridden in the class so that collections and
        methods contained by this resource can be accessed as *normal* Python
        attributes of this object. For example, if ``d`` is an object
        representing a *device* resource, ``d.exec_rpc`` gives access to the
        contained *exec-rpc* method. Also, ``d.configurations`` gives access
        to the contained *configurations* collection.

        If the given attr name does not match the name of a contained
        collection or method (based on meta object data), then it is passed on
        to the contained _xml_data for look-up. For example,
        ``d.platform`` will return the ``platform`` field value of the device
        object's XML representation.

        :param str attr: Name of the attribute being accessed.

        :returns: Collection or Method or the XML data field being accessed.
        """
        if attr in self._collections:
            return self._collections[attr]

        if attr in self._methods:
            return self._methods[attr]

        collection = self._meta_object.create_collection(self, attr)
        if collection is not None:
            self._collections[attr] = collection
            return collection

        method = self._meta_object.create_method(self, attr)
        if method is not None:
            self._methods[attr] = method
            return method

        # Check if it is an XML attribute
        thing = self._xml_data.get(attr)
        if thing is not None:
            return thing

        return self._xml_data[xmlutil.make_xml_name(attr)]
        # return self._xml_data.__getattr__(attr) # For issue #27

        """
Beispiel #6
0
    def __getattr__(self, attr):
        """
        This method is overridden in the class so that collections and
        methods contained by this resource can be accessed as *normal* Python
        attributes of this object. For example, if ``d`` is an object
        representing a *device* resource, ``d.exec_rpc`` gives access to the
        contained *exec-rpc* method. Also, ``d.configurations`` gives access
        to the contained *configurations* collection.

        If the given attr name does not match the name of a contained
        collection or method (based on meta object data), then it is passed on
        to the contained _xml_data for look-up. For example,
        ``d.platform`` will return the ``platform`` field value of the device
        object's XML representation.

        :param str attr: Name of the attribute being accessed.

        :returns: Collection or Method or the XML data field being accessed.
        """
        if attr in self._collections:
            return self._collections[attr]

        if attr in self._methods:
            return self._methods[attr]

        collection = self._meta_object.create_collection(self, attr)
        if collection is not None:
            self._collections[attr] = collection
            return collection

        method = self._meta_object.create_method(self, attr)
        if method is not None:
            self._methods[attr] = method
            return method

        # Check if it is an XML attribute
        thing = self._xml_data.get(attr)
        if thing is not None:
            return thing

        return self._xml_data[xmlutil.make_xml_name(attr)]
        # return self._xml_data.__getattr__(attr) # For issue #27
        """