From dc5b3f1133bfbe1e29a51eea95579b3c3fa7b795 Mon Sep 17 00:00:00 2001 From: Jakub Kadlčík Date: Nov 06 2018 23:37:20 +0000 Subject: [python] override Munch repr method --- diff --git a/python/copr/v3/exceptions.py b/python/copr/v3/exceptions.py index a48c278..16c51df 100644 --- a/python/copr/v3/exceptions.py +++ b/python/copr/v3/exceptions.py @@ -1,4 +1,4 @@ -from munch import Munch +from .munch import Munch class CoprException(Exception): diff --git a/python/copr/v3/helpers.py b/python/copr/v3/helpers.py index b684288..735618c 100644 --- a/python/copr/v3/helpers.py +++ b/python/copr/v3/helpers.py @@ -1,7 +1,7 @@ import os import six import configparser -from munch import Munch +from .munch import Munch from .exceptions import CoprNoConfigException, CoprConfigException diff --git a/python/copr/v3/munch.py b/python/copr/v3/munch.py new file mode 100644 index 0000000..feba0ce --- /dev/null +++ b/python/copr/v3/munch.py @@ -0,0 +1,25 @@ +from __future__ import absolute_import +import munch + + +class Munch(munch.Munch): + """ + We are extending a Munch class to modify some of its functionality. + The goal is to not do a great differences from the original. This class + is not a place for implementing methods that communicates with frontend + e.g. project.save(), build.chroots(), etc. + + Changes should be in line with the APIv3 philosophy. We want to e.g. + store some special attributes in munch, that we don't want to necessarily + show to user when printing because of degradation of data readability. + """ + + def __repr__(self): + public = {k: v for k, v in self.items()} + return '{0}({1})'.format(self.__class__.__name__, dict.__repr__(public)) + + def items(self): + return [(k, v) for k, v in super(Munch, self).items() if not k.startswith("__")] + + def keys(self): + return [k for k in super(Munch, self).keys() if not k.startswith("__")] diff --git a/python/copr/v3/requests.py b/python/copr/v3/requests.py index 7123fc3..ec12e48 100644 --- a/python/copr/v3/requests.py +++ b/python/copr/v3/requests.py @@ -3,8 +3,8 @@ from __future__ import absolute_import import os import json import requests -from munch import Munch from requests_toolbelt.multipart.encoder import MultipartEncoder, MultipartEncoderMonitor +from .munch import Munch from .helpers import List from .exceptions import CoprRequestException, CoprNoResultException