diff --git a/docs/config.rst b/docs/config.rst index 5c091e752..6122a6446 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -17,8 +17,7 @@ The Config type .. method:: Config.__iter__() The :class:`Config` class has an iterator which can be used to loop - through all the entries in the configuration. Each element is a tuple - containing the name and the value of each configuration variable. Be + through all the entries in the configuration. Each element is a ``ConfigEntry`` object containing the name, level, and value of each configuration variable. Be aware that this may return multiple versions of each entry if they are set multiple times in the configuration files. @@ -32,3 +31,14 @@ string. In order to apply the git-config parsing rules, you can use .. automethod:: pygit2.Config.get_bool .. automethod:: pygit2.Config.get_int + + +The ConfigEntry type +==================== + +.. automethod:: pygit2.ConfigEntry.decode_as_string +.. automethod:: pygit2.ConfigEntry._from_c +.. automethod:: pygit2.ConfigEntry.name +.. automethod:: pygit2.ConfigEntry.level +.. automethod:: pygit2.ConfigEntry.value +.. automethod:: pygit2.ConfigEntry.value_string diff --git a/pygit2/config.py b/pygit2/config.py index fd9ab4967..07a61219c 100644 --- a/pygit2/config.py +++ b/pygit2/config.py @@ -292,6 +292,10 @@ class ConfigEntry(object): @classmethod def _from_c(cls, ptr, from_iterator=False): + """Builds the entry from a ``git_config_entry`` pointer. ``from_iterator`` + should be ``True`` when the entry was created during ``git_config_iterator`` + actions + """ entry = cls.__new__(cls) entry._entry = ptr entry.from_iterator = from_iterator @@ -303,20 +307,30 @@ def __del__(self): @property def value(self): + """The raw ``cData`` entry value + """ return self._entry.value @property def level(self): + """The entry's ``git_config_level_t`` value + """ return self._entry.level @property def name(self): + """The entry's name + """ return self.decode_as_string(self._entry.name) @property def value_string(self): + """The entry's value as a string + """ return self.decode_as_string(self.value) @staticmethod def decode_as_string(value): + """Returns ``value`` as a decoded ``utf-8`` string. + """ return ffi.string(value).decode('utf-8')