[Python-modules-commits] [python-digitalocean] 05/19: Human readable class representation (#163)

Andrew Starr-Bochicchio asb at moszumanska.debian.org
Tue Jun 20 00:31:28 UTC 2017


This is an automated email from the git hooks/post-receive script.

asb pushed a commit to annotated tag 1.10.1
in repository python-digitalocean.

commit a605b1109cbc9b91914273604813dbeae0726490
Author: Szabolcs Dombi <cprogrammer1994 at gmail.com>
Date:   Mon Oct 3 18:40:08 2016 +0300

    Human readable class representation (#163)
    
    * improve repr string
    
    * repr in BaseAPI
    
    * listing example
    
    * remove reimplemented repr
    
    * remove token from str and repr
---
 README.md                  | 11 +++++++++++
 digitalocean/Account.py    |  2 +-
 digitalocean/Action.py     |  2 +-
 digitalocean/Domain.py     |  2 +-
 digitalocean/Droplet.py    |  5 +----
 digitalocean/FloatingIP.py |  2 +-
 digitalocean/Image.py      |  5 +----
 digitalocean/Kernel.py     |  2 +-
 digitalocean/Manager.py    |  2 +-
 digitalocean/Metadata.py   |  2 +-
 digitalocean/Record.py     |  2 +-
 digitalocean/Region.py     |  2 +-
 digitalocean/SSHKey.py     |  2 +-
 digitalocean/Volume.py     |  5 +----
 digitalocean/baseapi.py    |  5 ++++-
 15 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/README.md b/README.md
index 37be55d..f9229a3 100644
--- a/README.md
+++ b/README.md
@@ -42,6 +42,17 @@ python-digitalocean support all the features provided via digitalocean.com APIs,
 
 
 ## Examples
+### Listing the droplets
+
+This example shows how to list all the active droplets:
+
+```python
+import digitalocean
+manager = digitalocean.Manager(token="secretspecialuniquesnowflake")
+print(manager.get_all_droplets())
+```
+
+
 ### Shutdown all droplets
 
 This example shows how to shutdown all the active droplets:
diff --git a/digitalocean/Account.py b/digitalocean/Account.py
index 1bac1f2..abef4b4 100644
--- a/digitalocean/Account.py
+++ b/digitalocean/Account.py
@@ -32,4 +32,4 @@ class Account(BaseAPI):
             setattr(self, attr, account[attr])
 
     def __str__(self):
-        return "%s" % self.email
+        return "%s" % (self.email)
diff --git a/digitalocean/Action.py b/digitalocean/Action.py
index 79c8322..f181794 100644
--- a/digitalocean/Action.py
+++ b/digitalocean/Action.py
@@ -67,4 +67,4 @@ class Action(BaseAPI):
         return self.status == u'completed'
 
     def __str__(self):
-        return "%s %s [%s]" % (self.id, self.type, self.status)
+        return "<Action: %s %s %s>" % (self.id, self.type, self.status)
diff --git a/digitalocean/Domain.py b/digitalocean/Domain.py
index 5507d27..50559fd 100644
--- a/digitalocean/Domain.py
+++ b/digitalocean/Domain.py
@@ -108,4 +108,4 @@ class Domain(BaseAPI):
         return records
 
     def __str__(self):
-        return "%s" % self.name
+        return "%s" % (self.name)
diff --git a/digitalocean/Droplet.py b/digitalocean/Droplet.py
index 2ce4a72..059d071 100644
--- a/digitalocean/Droplet.py
+++ b/digitalocean/Droplet.py
@@ -627,7 +627,4 @@ class Droplet(BaseAPI):
         return kernels
 
     def __str__(self):
-        return "<Droplet %s %s>" % (self.id, self.name)
-
-    def __repr__(self):
-        return str(self)
+        return "<Droplet: %s %s>" % (self.id, self.name)
diff --git a/digitalocean/FloatingIP.py b/digitalocean/FloatingIP.py
index ae93701..8a97b7b 100644
--- a/digitalocean/FloatingIP.py
+++ b/digitalocean/FloatingIP.py
@@ -109,4 +109,4 @@ class FloatingIP(BaseAPI):
         )
 
     def __str__(self):
-        return "%s" % self.ip
+        return "%s" % (self.ip)
diff --git a/digitalocean/Image.py b/digitalocean/Image.py
index 9f1ae56..d50f2f2 100644
--- a/digitalocean/Image.py
+++ b/digitalocean/Image.py
@@ -62,7 +62,4 @@ class Image(BaseAPI):
         )
 
     def __str__(self):
-        return "%s %s %s" % (self.id, self.name, self.distribution)
-
-    def __repr__(self):
-        return "< %s %s %s >" % (self.id, self.distribution, self.name)
+        return "<Image: %s %s %s>" % (self.id, self.distribution, self.name)
diff --git a/digitalocean/Kernel.py b/digitalocean/Kernel.py
index 1453cc3..9f4e78c 100644
--- a/digitalocean/Kernel.py
+++ b/digitalocean/Kernel.py
@@ -10,4 +10,4 @@ class Kernel(BaseAPI):
         super(Kernel, self).__init__(*args, **kwargs)
 
     def __str__(self):
-        return "%s %s" % (self.name, self.version)
+        return "<Kernel: %s %s>" % (self.name, self.version)
diff --git a/digitalocean/Manager.py b/digitalocean/Manager.py
index 49ae662..728958c 100644
--- a/digitalocean/Manager.py
+++ b/digitalocean/Manager.py
@@ -287,4 +287,4 @@ class Manager(BaseAPI):
         return Volume.get_object(api_token=self.token, volume_id=volume_id)
 
     def __str__(self):
-        return "%s" % (self.token)
+        return "<Manager>"
diff --git a/digitalocean/Metadata.py b/digitalocean/Metadata.py
index 74802ce..12e865b 100644
--- a/digitalocean/Metadata.py
+++ b/digitalocean/Metadata.py
@@ -42,4 +42,4 @@ class Metadata(BaseAPI):
         return self
 
     def __str__(self):
-        return "%s" % self.droplet_id
+        return "<Metadata: %s>" % (self.droplet_id)
diff --git a/digitalocean/Record.py b/digitalocean/Record.py
index c9e8f8c..9cb6490 100644
--- a/digitalocean/Record.py
+++ b/digitalocean/Record.py
@@ -84,4 +84,4 @@ class Record(BaseAPI):
                 setattr(self, attr, record[attr])
 
     def __str__(self):
-        return "%s %s" % (self.id, self.domain)
+        return "<Record: %s %s>" % (self.id, self.domain)
diff --git a/digitalocean/Region.py b/digitalocean/Region.py
index 03cb60b..7da1262 100644
--- a/digitalocean/Region.py
+++ b/digitalocean/Region.py
@@ -12,4 +12,4 @@ class Region(BaseAPI):
         super(Region, self).__init__(*args, **kwargs)
 
     def __str__(self):
-        return "%s" % self.name
+        return "<Region: %s %s>" % (self.slug, self.name)
diff --git a/digitalocean/SSHKey.py b/digitalocean/SSHKey.py
index b212bc4..8772d91 100644
--- a/digitalocean/SSHKey.py
+++ b/digitalocean/SSHKey.py
@@ -95,4 +95,4 @@ class SSHKey(BaseAPI):
         return self.get_data("account/keys/%s" % self.id, type=DELETE)
 
     def __str__(self):
-        return "%s %s" % (self.id, self.name)
+        return "<SSHKey: %s %s>" % (self.id, self.name)
diff --git a/digitalocean/Volume.py b/digitalocean/Volume.py
index c39f557..2892f66 100644
--- a/digitalocean/Volume.py
+++ b/digitalocean/Volume.py
@@ -116,7 +116,4 @@ class Volume(BaseAPI):
         )
 
     def __str__(self):
-        return "%s %s %s" % (self.id, self.name, self.size_gigabytes)
-
-    def __repr__(self):
-        return "< %s %s %s >" % (self.id, self.name, self.size_gigabytes)
+        return "<Volume: %s %s %s>" % (self.id, self.name, self.size_gigabytes)
diff --git a/digitalocean/baseapi.py b/digitalocean/baseapi.py
index 41893ed..adca55d 100644
--- a/digitalocean/baseapi.py
+++ b/digitalocean/baseapi.py
@@ -114,7 +114,10 @@ class BaseAPI(object):
         return data
 
     def __str__(self):
-        return "%s" % self.token
+        return "<%s>" % self.__class__.__name__
 
     def __unicode__(self):
         return u"%s" % self.__str__()
+
+    def __repr__(self):
+        return str(self)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-digitalocean.git



More information about the Python-modules-commits mailing list