X-Git-Url: http://www.iramuteq.org/git?a=blobdiff_plain;f=configparser_helpers.py;h=0536bf58c2b0a7afaf3641a791faaebe31694b1b;hb=eaa044d1147e26b82942ce56d5965c83fdddf069;hp=470cd5f8ed66b0cb0bef013abb5a105c334f1da2;hpb=10d67a5cd48583c060b6a0e77e87c41f80671027;p=iramuteq diff --git a/configparser_helpers.py b/configparser_helpers.py index 470cd5f..0536bf5 100644 --- a/configparser_helpers.py +++ b/configparser_helpers.py @@ -1,9 +1,15 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- +#modification pour python 3 : Laurent Mérat, 6x7 - mai 2020 +#License: GNU/GPL +#------------------------------------ +# import des modules python +#------------------------------------ from collections import MutableMapping + + try: - from thread import get_ident + from _thread import get_ident except ImportError: try: from _thread import get_ident @@ -11,8 +17,9 @@ except ImportError: from _dummy_thread import get_ident # from reprlib 3.2.1 -def recursive_repr(fillvalue=u'...'): - u'Decorator to make a repr function return fillvalue for a recursive call' + +def recursive_repr(fillvalue='...'): + 'Decorator to make a repr function return fillvalue for a recursive call' def decorating_function(user_function): repr_running = set() @@ -29,17 +36,18 @@ def recursive_repr(fillvalue=u'...'): return result # Can't use functools.wraps() here because of bootstrap issues - wrapper.__module__ = getattr(user_function, u'__module__') - wrapper.__doc__ = getattr(user_function, u'__doc__') - wrapper.__name__ = getattr(user_function, u'__name__') - wrapper.__annotations__ = getattr(user_function, u'__annotations__', {}) + wrapper.__module__ = getattr(user_function, '__module__') + wrapper.__doc__ = getattr(user_function, '__doc__') + wrapper.__name__ = getattr(user_function, '__name__') + wrapper.__annotations__ = getattr(user_function, '__annotations__', {}) return wrapper return decorating_function # from collections 3.2.1 + class _ChainMap(MutableMapping): - u''' A ChainMap groups multiple dicts (or other mappings) together + ''' A ChainMap groups multiple dicts (or other mappings) together to create a single, updateable view. The underlying mappings are stored in a list. That list is public and can @@ -52,7 +60,7 @@ class _ChainMap(MutableMapping): ''' def __init__(self, *maps): - u'''Initialize a ChainMap by setting *maps* to the given mappings. + '''Initialize a ChainMap by setting *maps* to the given mappings. If no mappings are provided, a single empty dictionary is used. ''' @@ -83,27 +91,27 @@ class _ChainMap(MutableMapping): @recursive_repr() def __repr__(self): - return u'{0.__class__.__name__}({1})'.format( - self, u', '.join(map(repr, self.maps))) + return '{0.__class__.__name__}({1})'.format( + self, ', '.join(map(repr, self.maps))) @classmethod def fromkeys(cls, iterable, *args): - u'Create a ChainMap with a single dict created from the iterable.' + 'Create a ChainMap with a single dict created from the iterable.' return cls(dict.fromkeys(iterable, *args)) def copy(self): - u'New ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]' + 'New ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]' return self.__class__(self.maps[0].copy(), *self.maps[1:]) __copy__ = copy def new_child(self): # like Django's Context.push() - u'New ChainMap with a new dict followed by all previous maps.' + 'New ChainMap with a new dict followed by all previous maps.' return self.__class__({}, *self.maps) @property def parents(self): # like Django's Context.pop() - u'New ChainMap from maps[1:].' + 'New ChainMap from maps[1:].' return self.__class__(*self.maps[1:]) def __setitem__(self, key, value): @@ -113,22 +121,22 @@ class _ChainMap(MutableMapping): try: del self.maps[0][key] except KeyError: - raise KeyError(u'Key not found in the first mapping: {!r}'.format(key)) + raise KeyError('Key not found in the first mapping: {!r}'.format(key)) def popitem(self): - u'Remove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.' + 'Remove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.' try: return self.maps[0].popitem() except KeyError: - raise KeyError(u'No keys found in the first mapping.') + raise KeyError('No keys found in the first mapping.') def pop(self, key, *args): - u'Remove *key* from maps[0] and return its value. Raise KeyError if *key* not in maps[0].' + 'Remove *key* from maps[0] and return its value. Raise KeyError if *key* not in maps[0].' try: return self.maps[0].pop(key, *args) except KeyError: - raise KeyError(u'Key not found in the first mapping: {!r}'.format(key)) + raise KeyError('Key not found in the first mapping: {!r}'.format(key)) def clear(self): - u'Clear maps[0], leaving maps[1:] intact.' + 'Clear maps[0], leaving maps[1:] intact.' self.maps[0].clear()