mercurial/templateutil.py
changeset 52643 5cc8deb96b48
parent 51859 f4733654f144
child 52644 e627cc25b6f3
equal deleted inserted replaced
52642:73ab542565e0 52643:5cc8deb96b48
   547     The function ``make(context, *args)`` should return a generator of
   547     The function ``make(context, *args)`` should return a generator of
   548     mapping dicts.
   548     mapping dicts.
   549     """
   549     """
   550 
   550 
   551     def __init__(self, make, args=(), name=None, tmpl=None, sep=b''):
   551     def __init__(self, make, args=(), name=None, tmpl=None, sep=b''):
   552         super(mappinggenerator, self).__init__(name, tmpl, sep)
   552         super().__init__(name, tmpl, sep)
   553         self._make = make
   553         self._make = make
   554         self._args = args
   554         self._args = args
   555 
   555 
   556     def itermaps(self, context):
   556     def itermaps(self, context):
   557         return self._make(context, *self._args)
   557         return self._make(context, *self._args)
   562 
   562 
   563 class mappinglist(_mappingsequence):
   563 class mappinglist(_mappingsequence):
   564     """Wrapper for list of template mappings"""
   564     """Wrapper for list of template mappings"""
   565 
   565 
   566     def __init__(self, mappings, name=None, tmpl=None, sep=b''):
   566     def __init__(self, mappings, name=None, tmpl=None, sep=b''):
   567         super(mappinglist, self).__init__(name, tmpl, sep)
   567         super().__init__(name, tmpl, sep)
   568         self._mappings = mappings
   568         self._mappings = mappings
   569 
   569 
   570     def itermaps(self, context):
   570     def itermaps(self, context):
   571         return iter(self._mappings)
   571         return iter(self._mappings)
   572 
   572 
   580     This isn't a sequence in a way that the underlying dict won't be iterated
   580     This isn't a sequence in a way that the underlying dict won't be iterated
   581     as a dict, but shares most of the _mappingsequence functions.
   581     as a dict, but shares most of the _mappingsequence functions.
   582     """
   582     """
   583 
   583 
   584     def __init__(self, mapping, name=None, tmpl=None):
   584     def __init__(self, mapping, name=None, tmpl=None):
   585         super(mappingdict, self).__init__(name, tmpl)
   585         super().__init__(name, tmpl)
   586         self._mapping = mapping
   586         self._mapping = mapping
   587 
   587 
   588     def tomap(self, context):
   588     def tomap(self, context):
   589         return self._mapping
   589         return self._mapping
   590 
   590 
   593         # a mapping dict should have at least one item in practice, so always
   593         # a mapping dict should have at least one item in practice, so always
   594         # mark this as non-empty.
   594         # mark this as non-empty.
   595         return True
   595         return True
   596 
   596 
   597     def tovalue(self, context, mapping):
   597     def tovalue(self, context, mapping):
   598         return super(mappingdict, self).tovalue(context, mapping)[0]
   598         return super().tovalue(context, mapping)[0]
   599 
   599 
   600 
   600 
   601 class mappingnone(wrappedvalue):
   601 class mappingnone(wrappedvalue):
   602     """Wrapper for None, but supports map operation
   602     """Wrapper for None, but supports map operation
   603 
   603 
   604     This represents None of Optional[mappable]. It's similar to
   604     This represents None of Optional[mappable]. It's similar to
   605     mapplinglist([]), but the underlying value is not [], but None.
   605     mapplinglist([]), but the underlying value is not [], but None.
   606     """
   606     """
   607 
   607 
   608     def __init__(self):
   608     def __init__(self):
   609         super(mappingnone, self).__init__(None)
   609         super().__init__(None)
   610 
   610 
   611     def itermaps(self, context):
   611     def itermaps(self, context):
   612         return iter([])
   612         return iter([])
   613 
   613 
   614 
   614