Edgewall Software
Modify

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#12977 closed defect (fixed)

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

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

Invoke close method of instances from Node.get_content() and Node.get_processed_content() if the method is existent.

API Changes:
Internal Changes:

Description (last modified by Jun Omae)

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

Attachments (0)

Change History (6)

comment:1 by Jun Omae, 7 years ago

Description: modified (diff)

comment:2 by Ryan J Ollos, 7 years ago

Looks like a good change to make.

comment:3 by Jun Omae, 7 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: newclosed

Thanks! Committed in [16591] and merged in [16592-16593].

comment:4 by Jun Omae, 7 years ago

Owner: set to Jun Omae

comment:5 by Ryan J Ollos, 7 years ago

Minor revision on trunk in r16607.

comment:6 by Jun Omae, 7 years ago

Hmm, I often wrongly merge such lines from 1.0-stable.

I added the following lines to my Makefile.cfg to check the cases before unit-test:

test-py26 :
        grep -q '^min_python = (2, [0-5])' setup.py || ( \
            ! grep -r --include='*.py' '\<import *with_statement\>' . && \
            ! grep -r --include='*.py' '\<except *.*, *[A-Za-z0-9_]\+:' . \
        )

unit-test : test-py26

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.