Uploaded image for project: 'Libcloud'
  1. Libcloud
  2. LIBCLOUD-763

Making str2dicts util function more pythonic and simpler.

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 0.13.3
    • Fix Version/s: None
    • Component/s: Libcloud REST

      Description

      With reference to the str2dicts function here https://github.com/apache/libcloud/blob/trunk/libcloud/utils/misc.py#L154

      Two suggestions:

      • I personally think the "\n\n" is not being taken advantage of.
      • Initializing a list and appending a list with empty dict ({}) is not necessary and can be removed. This will allow to remove negative indexing on the list as well.

      My thoughts are to change it to look like so:

      def str2dicts(data):
         if data is not None and data != "":
              data_blocks = data.split("\n\n")
              line_list = [line.rstrip("\n").lstrip("\n").split("\n") for line in data_blocks]
              return [dict(key_value_string.split(" ") for key_value_string in line) for line in line_list]
          return list({})
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                annp89 Ann Paul
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: