Edgewall Software

Opened 6 years ago

Last modified 6 years ago

#12977 closed defect

"close" method of instance from "Node.get_content()" should be invoked if the method exists — at Initial Version

Reported by: Jun Omae Owned by:
Priority: normal Milestone: 1.0.17
Component: version control Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

Type Returned value close __enter__, __exit__
SubversionNode FileContentStream instance available n/a
GitNode cStringIO.StringIO instance available n/a *1
MercurialNode self n/a n/a

*1 io.BytesIO has __enter__

  • trac/versioncontrol/web_ui/changeset.py

    diff --git a/trac/versioncontrol/web_ui/changeset.py b/trac/versioncontrol/web_ui/changeset.py
    index d9831a4d5..b82c1df3a 100644
    a b class ChangesetModule(Component):  
    549549                return None
    550550            if mview.is_binary(new_node.content_type, new_node.path):
    551551                return None
    552             old_content = old_node.get_content().read()
     552            old_content = _read_content(old_node)
    553553            if mview.is_binary(content=old_content):
    554554                return None
    555             new_content = new_node.get_content().read()
     555            new_content = _read_content(new_node)
    556556            if mview.is_binary(content=new_content):
    557557                return None
    558558
    class ChangesetModule(Component):  
    719719                    continue
    720720                if mimeview.is_binary(old_node.content_type, old_node.path):
    721721                    continue
    722                 old_content = old_node.get_content().read()
     722                old_content = _read_content(old_node)
    723723                if mimeview.is_binary(content=old_content):
    724724                    continue
    725725                old_node_info = (old_node.path, old_node.rev)
    class ChangesetModule(Component):  
    730730                    continue
    731731                if mimeview.is_binary(new_node.content_type, new_node.path):
    732732                    continue
    733                 new_content = new_node.get_content().read()
     733                new_content = _read_content(new_node)
    734734                if mimeview.is_binary(content=new_content):
    735735                    continue
    736736                new_node_info = (new_node.path, new_node.rev)
    class AnyDiffModule(Component):  
    12261226
    12271227        add_script(req, 'common/js/suggest.js')
    12281228        return 'diff_form.html', data, None
     1229
     1230
     1231def _read_content(node):
     1232    content = node.get_content()
     1233    try:
     1234        return content.read()
     1235    finally:
     1236        if hasattr(content, 'close'):
     1237            content.close()
  • tracopt/versioncontrol/svn/svn_fs.py

    diff --git a/tracopt/versioncontrol/svn/svn_fs.py b/tracopt/versioncontrol/svn/svn_fs.py
    index 6b0ae405a..4f50f319a 100644
    a b class FileContentStream(object):  
    11981198                                                   node._scoped_path_utf8,
    11991199                                                   self.pool()))
    12001200
     1201    def __enter__(self):
     1202        return self
     1203
     1204    def __exit__(self, et, ev, tb):
     1205        self.close()
     1206
    12011207    def __del__(self):
    12021208        self.close()
    12031209

Change History (0)

Note: See TracTickets for help on using tickets.