{"action":"created","comment":{"url":"https://api.github.com/repos/spacetelescope/pyasdf/pulls/comments/29338660","id":29338660,"diff_hunk":"@@ -0,0 +1,43 @@\n+.. _context-managers:\n+\n+Context managers\n+================\n+\n+`~pyasdf.AsdfFile` objects can be used as context managers to be used\n+with ``with`` statements to help ensure that the underlying files are\n+automatically closed.  There is no single pattern to recommend when\n+using `~pyasdf.AsdfFile` objects as context managers, but it will\n+instead depend on the context (no pun intended) in which they are\n+used.\n+\n+For example, basic writing and reading of a file::\n+\n+  >>> import pyasdf\n+  >>> tree = {'key': 'value'}\n+  >>> with pyasdf.AsdfFile(tree).write_to('test.asdf'):\n+  ...     pass\n+\n+  >>> with pyasdf.AsdfFile.read('test.asdf') as ff:\n+  ...     print(ff.tree['key'])\n+\n+The reason that `~pyasdf.AsdfFile.write_to` and\n+`~pyasdf.AsdfFile.read` functions do not automatically close the file\n+(unless used with ``with`` statements), is to allow for updating the\n+file in-place later on.  For example::\n+\n+  >>> with pyasdf.AsdfFile.read('test.asdf', 'rw') as ff:\n+  ...     ff.tree['key'] = 'new value'\n+  ...     ff.update()\n+\n+You may also want to write the same file, with small modifications, to\n+a number of different files on disk, in which case a context manager\n+can be used for each write.\n+\n+  >>> ff = pyasdf.AsdfFile(tree)\n+\n+  >>> with ff.write_to('a.asdf'):\n+  ...     pass\n+\n+  >>> ff.tree['key'] = 'new value'\n+  >>> with ff.write_to('b.asdf'):\n+  ...     pass","path":"docs/pyasdf/context_managers.rst","position":44,"original_position":43,"commit_id":"6c782b0b550a0d936c91ae91073bb9ec64d10dd6","original_commit_id":"f3a8a7731f8f75f0f90aa194a23c6be78ceab8a2","user":{"login":"mdboom","id":38294,"avatar_url":"https://avatars.githubusercontent.com/u/38294?v=3","gravatar_id":"","url":"https://api.github.com/users/mdboom","html_url":"https://github.com/mdboom","followers_url":"https://api.github.com/users/mdboom/followers","following_url":"https://api.github.com/users/mdboom/following{/other_user}","gists_url":"https://api.github.com/users/mdboom/gists{/gist_id}","starred_url":"https://api.github.com/users/mdboom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdboom/subscriptions","organizations_url":"https://api.github.com/users/mdboom/orgs","repos_url":"https://api.github.com/users/mdboom/repos","events_url":"https://api.github.com/users/mdboom/events{/privacy}","received_events_url":"https://api.github.com/users/mdboom/received_events","type":"User","site_admin":false},"body":"Hmm...  The context manager is the AsdfFile object.  Not sure if we can actually detect whether it's in a `with` statement or not.","created_at":"2015-04-29T14:09:28Z","updated_at":"2015-04-29T14:09:28Z","html_url":"https://github.com/spacetelescope/pyasdf/pull/116#discussion_r29338660","pull_request_url":"https://api.github.com/repos/spacetelescope/pyasdf/pulls/116","_links":{"self":{"href":"https://api.github.com/repos/spacetelescope/pyasdf/pulls/comments/29338660"},"html":{"href":"https://github.com/spacetelescope/pyasdf/pull/116#discussion_r29338660"},"pull_request":{"href":"https://api.github.com/repos/spacetelescope/pyasdf/pulls/116"}}},"pull_request":{"url":"https://api.github.com/repos/spacetelescope/pyasdf/pulls/116","id":34298574,"html_url":"https://github.com/spacetelescope/pyasdf/pull/116","diff_url":"https://github.com/spacetelescope/pyasdf/pull/116.diff","patch_url":"https://github.com/spacetelescope/pyasdf/pull/116.patch","issue_url":"https://api.github.com/repos/spacetelescope/pyasdf/issues/116","number":116,"state":"open","locked":false,"title":"Explain context managers in greater detail","user":{"login":"mdboom","id":38294,"avatar_url":"https://avatars.githubusercontent.com/u/38294?v=3","gravatar_id":"","url":"https://api.github.com/users/mdboom","html_url":"https://github.com/mdboom","followers_url":"https://api.github.com/users/mdboom/followers","following_url":"https://api.github.com/users/mdboom/following{/other_user}","gists_url":"https://api.github.com/users/mdboom/gists{/gist_id}","starred_url":"https://api.github.com/users/mdboom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdboom/subscriptions","organizations_url":"https://api.github.com/users/mdboom/orgs","repos_url":"https://api.github.com/users/mdboom/repos","events_url":"https://api.github.com/users/mdboom/events{/privacy}","received_events_url":"https://api.github.com/users/mdboom/received_events","type":"User","site_admin":false},"body":"Fix #107.","created_at":"2015-04-28T18:48:41Z","updated_at":"2015-04-29T14:09:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7c3254fe1f3d2f6e48c512be247f5ca7129f6e1c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/spacetelescope/pyasdf/pulls/116/commits","review_comments_url":"https://api.github.com/repos/spacetelescope/pyasdf/pulls/116/comments","review_comment_url":"https://api.github.com/repos/spacetelescope/pyasdf/pulls/comments{/number}","comments_url":"https://api.github.com/repos/spacetelescope/pyasdf/issues/116/comments","statuses_url":"https://api.github.com/repos/spacetelescope/pyasdf/statuses/6c782b0b550a0d936c91ae91073bb9ec64d10dd6","head":{"label":"mdboom:cleanup-and-explain-context-manager","ref":"cleanup-and-explain-context-manager","sha":"6c782b0b550a0d936c91ae91073bb9ec64d10dd6","user":{"login":"mdboom","id":38294,"avatar_url":"https://avatars.githubusercontent.com/u/38294?v=3","gravatar_id":"","url":"https://api.github.com/users/mdboom","html_url":"https://github.com/mdboom","followers_url":"https://api.github.com/users/mdboom/followers","following_url":"https://api.github.com/users/mdboom/following{/other_user}","gists_url":"https://api.github.com/users/mdboom/gists{/gist_id}","starred_url":"https://api.github.com/users/mdboom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdboom/subscriptions","organizations_url":"https://api.github.com/users/mdboom/orgs","repos_url":"https://api.github.com/users/mdboom/repos","events_url":"https://api.github.com/users/mdboom/events{/privacy}","received_events_url":"https://api.github.com/users/mdboom/received_events","type":"User","site_admin":false},"repo":{"id":18112833,"name":"pyasdf","full_name":"mdboom/pyasdf","owner":{"login":"mdboom","id":38294,"avatar_url":"https://avatars.githubusercontent.com/u/38294?v=3","gravatar_id":"","url":"https://api.github.com/users/mdboom","html_url":"https://github.com/mdboom","followers_url":"https://api.github.com/users/mdboom/followers","following_url":"https://api.github.com/users/mdboom/following{/other_user}","gists_url":"https://api.github.com/users/mdboom/gists{/gist_id}","starred_url":"https://api.github.com/users/mdboom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdboom/subscriptions","organizations_url":"https://api.github.com/users/mdboom/orgs","repos_url":"https://api.github.com/users/mdboom/repos","events_url":"https://api.github.com/users/mdboom/events{/privacy}","received_events_url":"https://api.github.com/users/mdboom/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mdboom/pyasdf","description":"FINF (FINF is not FITS) is a next generation interchange format for astronomical data","fork":true,"url":"https://api.github.com/repos/mdboom/pyasdf","forks_url":"https://api.github.com/repos/mdboom/pyasdf/forks","keys_url":"https://api.github.com/repos/mdboom/pyasdf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mdboom/pyasdf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mdboom/pyasdf/teams","hooks_url":"https://api.github.com/repos/mdboom/pyasdf/hooks","issue_events_url":"https://api.github.com/repos/mdboom/pyasdf/issues/events{/number}","events_url":"https://api.github.com/repos/mdboom/pyasdf/events","assignees_url":"https://api.github.com/repos/mdboom/pyasdf/assignees{/user}","branches_url":"https://api.github.com/repos/mdboom/pyasdf/branches{/branch}","tags_url":"https://api.github.com/repos/mdboom/pyasdf/tags","blobs_url":"https://api.github.com/repos/mdboom/pyasdf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mdboom/pyasdf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mdboom/pyasdf/git/refs{/sha}","trees_url":"https://api.github.com/repos/mdboom/pyasdf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mdboom/pyasdf/statuses/{sha}","languages_url":"https://api.github.com/repos/mdboom/pyasdf/languages","stargazers_url":"https://api.github.com/repos/mdboom/pyasdf/stargazers","contributors_url":"https://api.github.com/repos/mdboom/pyasdf/contributors","subscribers_url":"https://api.github.com/repos/mdboom/pyasdf/subscribers","subscription_url":"https://api.github.com/repos/mdboom/pyasdf/subscription","commits_url":"https://api.github.com/repos/mdboom/pyasdf/commits{/sha}","git_commits_url":"https://api.github.com/repos/mdboom/pyasdf/git/commits{/sha}","comments_url":"https://api.github.com/repos/mdboom/pyasdf/comments{/number}","issue_comment_url":"https://api.github.com/repos/mdboom/pyasdf/issues/comments{/number}","contents_url":"https://api.github.com/repos/mdboom/pyasdf/contents/{+path}","compare_url":"https://api.github.com/repos/mdboom/pyasdf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mdboom/pyasdf/merges","archive_url":"https://api.github.com/repos/mdboom/pyasdf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mdboom/pyasdf/downloads","issues_url":"https://api.github.com/repos/mdboom/pyasdf/issues{/number}","pulls_url":"https://api.github.com/repos/mdboom/pyasdf/pulls{/number}","milestones_url":"https://api.github.com/repos/mdboom/pyasdf/milestones{/number}","notifications_url":"https://api.github.com/repos/mdboom/pyasdf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mdboom/pyasdf/labels{/name}","releases_url":"https://api.github.com/repos/mdboom/pyasdf/releases{/id}","created_at":"2014-03-25T19:03:27Z","updated_at":"2015-04-07T19:51:38Z","pushed_at":"2015-04-29T11:00:46Z","git_url":"git://github.com/mdboom/pyasdf.git","ssh_url":"git@github.com:mdboom/pyasdf.git","clone_url":"https://github.com/mdboom/pyasdf.git","svn_url":"https://github.com/mdboom/pyasdf","homepage":null,"size":1943,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"spacetelescope:master","ref":"master","sha":"d7caf86c73957943366f6df3aa67b53d585a6868","user":{"login":"spacetelescope","id":2751928,"avatar_url":"https://avatars.githubusercontent.com/u/2751928?v=3","gravatar_id":"","url":"https://api.github.com/users/spacetelescope","html_url":"https://github.com/spacetelescope","followers_url":"https://api.github.com/users/spacetelescope/followers","following_url":"https://api.github.com/users/spacetelescope/following{/other_user}","gists_url":"https://api.github.com/users/spacetelescope/gists{/gist_id}","starred_url":"https://api.github.com/users/spacetelescope/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spacetelescope/subscriptions","organizations_url":"https://api.github.com/users/spacetelescope/orgs","repos_url":"https://api.github.com/users/spacetelescope/repos","events_url":"https://api.github.com/users/spacetelescope/events{/privacy}","received_events_url":"https://api.github.com/users/spacetelescope/received_events","type":"Organization","site_admin":false},"repo":{"id":18112754,"name":"pyasdf","full_name":"spacetelescope/pyasdf","owner":{"login":"spacetelescope","id":2751928,"avatar_url":"https://avatars.githubusercontent.com/u/2751928?v=3","gravatar_id":"","url":"https://api.github.com/users/spacetelescope","html_url":"https://github.com/spacetelescope","followers_url":"https://api.github.com/users/spacetelescope/followers","following_url":"https://api.github.com/users/spacetelescope/following{/other_user}","gists_url":"https://api.github.com/users/spacetelescope/gists{/gist_id}","starred_url":"https://api.github.com/users/spacetelescope/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spacetelescope/subscriptions","organizations_url":"https://api.github.com/users/spacetelescope/orgs","repos_url":"https://api.github.com/users/spacetelescope/repos","events_url":"https://api.github.com/users/spacetelescope/events{/privacy}","received_events_url":"https://api.github.com/users/spacetelescope/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/spacetelescope/pyasdf","description":"ASDF (Advanced Scientific Data Format) is a next generation interchange format for astronomical data","fork":false,"url":"https://api.github.com/repos/spacetelescope/pyasdf","forks_url":"https://api.github.com/repos/spacetelescope/pyasdf/forks","keys_url":"https://api.github.com/repos/spacetelescope/pyasdf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spacetelescope/pyasdf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spacetelescope/pyasdf/teams","hooks_url":"https://api.github.com/repos/spacetelescope/pyasdf/hooks","issue_events_url":"https://api.github.com/repos/spacetelescope/pyasdf/issues/events{/number}","events_url":"https://api.github.com/repos/spacetelescope/pyasdf/events","assignees_url":"https://api.github.com/repos/spacetelescope/pyasdf/assignees{/user}","branches_url":"https://api.github.com/repos/spacetelescope/pyasdf/branches{/branch}","tags_url":"https://api.github.com/repos/spacetelescope/pyasdf/tags","blobs_url":"https://api.github.com/repos/spacetelescope/pyasdf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spacetelescope/pyasdf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spacetelescope/pyasdf/git/refs{/sha}","trees_url":"https://api.github.com/repos/spacetelescope/pyasdf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spacetelescope/pyasdf/statuses/{sha}","languages_url":"https://api.github.com/repos/spacetelescope/pyasdf/languages","stargazers_url":"https://api.github.com/repos/spacetelescope/pyasdf/stargazers","contributors_url":"https://api.github.com/repos/spacetelescope/pyasdf/contributors","subscribers_url":"https://api.github.com/repos/spacetelescope/pyasdf/subscribers","subscription_url":"https://api.github.com/repos/spacetelescope/pyasdf/subscription","commits_url":"https://api.github.com/repos/spacetelescope/pyasdf/commits{/sha}","git_commits_url":"https://api.github.com/repos/spacetelescope/pyasdf/git/commits{/sha}","comments_url":"https://api.github.com/repos/spacetelescope/pyasdf/comments{/number}","issue_comment_url":"https://api.github.com/repos/spacetelescope/pyasdf/issues/comments{/number}","contents_url":"https://api.github.com/repos/spacetelescope/pyasdf/contents/{+path}","compare_url":"https://api.github.com/repos/spacetelescope/pyasdf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spacetelescope/pyasdf/merges","archive_url":"https://api.github.com/repos/spacetelescope/pyasdf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spacetelescope/pyasdf/downloads","issues_url":"https://api.github.com/repos/spacetelescope/pyasdf/issues{/number}","pulls_url":"https://api.github.com/repos/spacetelescope/pyasdf/pulls{/number}","milestones_url":"https://api.github.com/repos/spacetelescope/pyasdf/milestones{/number}","notifications_url":"https://api.github.com/repos/spacetelescope/pyasdf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spacetelescope/pyasdf/labels{/name}","releases_url":"https://api.github.com/repos/spacetelescope/pyasdf/releases{/id}","created_at":"2014-03-25T19:00:43Z","updated_at":"2015-04-29T10:54:54Z","pushed_at":"2015-04-29T11:00:46Z","git_url":"git://github.com/spacetelescope/pyasdf.git","ssh_url":"git@github.com:spacetelescope/pyasdf.git","clone_url":"https://github.com/spacetelescope/pyasdf.git","svn_url":"https://github.com/spacetelescope/pyasdf","homepage":"http://pyasdf.readthedocs.org/","size":2208,"stargazers_count":2,"watchers_count":2,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":17,"forks":7,"open_issues":17,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/spacetelescope/pyasdf/pulls/116"},"html":{"href":"https://github.com/spacetelescope/pyasdf/pull/116"},"issue":{"href":"https://api.github.com/repos/spacetelescope/pyasdf/issues/116"},"comments":{"href":"https://api.github.com/repos/spacetelescope/pyasdf/issues/116/comments"},"review_comments":{"href":"https://api.github.com/repos/spacetelescope/pyasdf/pulls/116/comments"},"review_comment":{"href":"https://api.github.com/repos/spacetelescope/pyasdf/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/spacetelescope/pyasdf/pulls/116/commits"},"statuses":{"href":"https://api.github.com/repos/spacetelescope/pyasdf/statuses/6c782b0b550a0d936c91ae91073bb9ec64d10dd6"}}}}