Skip to content

Is all get_ commands supposed to return a string instead of xml? #9

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
falkowich opened this issue Nov 2, 2018 · 1 comment
Closed
Assignees
Labels
documentation Documentation is invalid, outdated, missing, ...

Comments

@falkowich
Copy link

In the example in the README.md is seems like these get_ functions should return an xml object.

# Retrieve all tasks
tasks = gmp.get_tasks()

# Get names of tasks
task_names = tasks.xpath('task/name/text()')

But now they seem to return an string
Is this an error or by design?

   def get_tasks_command(self, kwargs):
        """Generates xml string for get tasks on gvmd."""
        cmd = XmlCommand('get_tasks')
        cmd.set_attributes(kwargs)
        return cmd.to_string()

--
Regards Falk

@bjoernricks
Copy link
Contributor

First of all GmpCommandFactory is not a public api and will be removed in future. My plan is to remove it before the final python-gvm 1.0 release. And it only creates gmp xml commands as a string.

Second I did change the Gmp class to allow to return any kind of python type from each get/modify/delete/.. method.
Please take a look at the gvm.protocols.gmpv7.Gmp __init__ method for the transform parameter and gvm.transforms for the build in classes for this parameter. Passing a transform allows to change the response.

But you are right. The example in the README.md is currently wrong. By default the Gmp methods are returning a string. A EtreeTransform instance should be passed to Gmp as transform param.

@bjoernricks bjoernricks added the documentation Documentation is invalid, outdated, missing, ... label Nov 3, 2018
@bjoernricks bjoernricks self-assigned this Nov 3, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
documentation Documentation is invalid, outdated, missing, ...
Projects
None yet
Development

No branches or pull requests

2 participants