{"action":"created","comment":{"url":"https://api.github.com/repos/rthalley/dnspython/pulls/comments/73714880","id":73714880,"diff_hunk":"@@ -500,16 +501,27 @@ def to_file(self, f, sorted=True, relativize=True, nl=None):\n \n         str_type = string_types\n \n-        if nl is None:\n-            opts = 'wb'\n-        else:\n-            opts = 'wb'\n-\n         if isinstance(f, str_type):\n-            f = open(f, opts)\n+            f = open(f, 'wb')\n             want_close = True\n         else:\n             want_close = False\n+\n+        # must be in this way, f.encoding may contain None, or even attribute\n+        # may not be there\n+        file_enc = getattr(f, 'encoding', None)\n+        if file_enc is None:\n+            file_enc = 'utf-8'","path":"dns/zone.py","position":39,"original_position":39,"commit_id":"ae19cb5bea06a8ef7792d865eb134c9af9fa1307","original_commit_id":"ae19cb5bea06a8ef7792d865eb134c9af9fa1307","user":{"login":"sebix","id":199050,"avatar_url":"https://avatars.githubusercontent.com/u/199050?v=3","gravatar_id":"","url":"https://api.github.com/users/sebix","html_url":"https://github.com/sebix","followers_url":"https://api.github.com/users/sebix/followers","following_url":"https://api.github.com/users/sebix/following{/other_user}","gists_url":"https://api.github.com/users/sebix/gists{/gist_id}","starred_url":"https://api.github.com/users/sebix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebix/subscriptions","organizations_url":"https://api.github.com/users/sebix/orgs","repos_url":"https://api.github.com/users/sebix/repos","events_url":"https://api.github.com/users/sebix/events{/privacy}","received_events_url":"https://api.github.com/users/sebix/received_events","type":"User","site_admin":false},"body":"And when `f.encoding` is None (python 2, binary) or throws `AttributeError` we have binary mode, utf-8 may be default for text. This should be ascii as far as I understand.\r\n\r\nOn python2 with text mode, we have `None` too...\r\n\r\nI suppose to just drop support for binary mode. In py2 we check for existence of `t` in `f.mode` and for py3 we check for an existing `f.encoding`: `if hasattr(f, 'encoding') or 't' in f.mode`.","created_at":"2016-08-05T15:49:39Z","updated_at":"2016-08-05T15:49:39Z","html_url":"https://github.com/rthalley/dnspython/pull/188#discussion_r73714880","pull_request_url":"https://api.github.com/repos/rthalley/dnspython/pulls/188","_links":{"self":{"href":"https://api.github.com/repos/rthalley/dnspython/pulls/comments/73714880"},"html":{"href":"https://github.com/rthalley/dnspython/pull/188#discussion_r73714880"},"pull_request":{"href":"https://api.github.com/repos/rthalley/dnspython/pulls/188"}}},"pull_request":{"url":"https://api.github.com/repos/rthalley/dnspython/pulls/188","id":76077707,"html_url":"https://github.com/rthalley/dnspython/pull/188","diff_url":"https://github.com/rthalley/dnspython/pull/188.diff","patch_url":"https://github.com/rthalley/dnspython/pull/188.patch","issue_url":"https://api.github.com/repos/rthalley/dnspython/issues/188","number":188,"state":"open","locked":false,"title":"Fix encoding errors zone.to_file()","user":{"login":"bastiak","id":4238177,"avatar_url":"https://avatars.githubusercontent.com/u/4238177?v=3","gravatar_id":"","url":"https://api.github.com/users/bastiak","html_url":"https://github.com/bastiak","followers_url":"https://api.github.com/users/bastiak/followers","following_url":"https://api.github.com/users/bastiak/following{/other_user}","gists_url":"https://api.github.com/users/bastiak/gists{/gist_id}","starred_url":"https://api.github.com/users/bastiak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bastiak/subscriptions","organizations_url":"https://api.github.com/users/bastiak/orgs","repos_url":"https://api.github.com/users/bastiak/repos","events_url":"https://api.github.com/users/bastiak/events{/privacy}","received_events_url":"https://api.github.com/users/bastiak/received_events","type":"User","site_admin":false},"body":"From the code it looks like the only 'binary' mode is supported after migration to py3.\r\nI fixed py3 with 'wb', but I think that also files in text mode should be supported.\r\n\r\n\r\nThis needed much more love than I originally thought. I'm not sure If I fixed it right.\r\n\r\nI think that it should also allow files opened in text mode (sys.stdout, sys.stderr)\r\n\r\nPartially fixes #182 (only binary mode)","created_at":"2016-07-03T00:30:41Z","updated_at":"2016-08-05T15:49:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"03f3d05c1f652382d55db909f912e20b39f22e4a","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/rthalley/dnspython/pulls/188/commits","review_comments_url":"https://api.github.com/repos/rthalley/dnspython/pulls/188/comments","review_comment_url":"https://api.github.com/repos/rthalley/dnspython/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rthalley/dnspython/issues/188/comments","statuses_url":"https://api.github.com/repos/rthalley/dnspython/statuses/ae19cb5bea06a8ef7792d865eb134c9af9fa1307","head":{"label":"bastiak:py3-zonefix","ref":"py3-zonefix","sha":"ae19cb5bea06a8ef7792d865eb134c9af9fa1307","user":{"login":"bastiak","id":4238177,"avatar_url":"https://avatars.githubusercontent.com/u/4238177?v=3","gravatar_id":"","url":"https://api.github.com/users/bastiak","html_url":"https://github.com/bastiak","followers_url":"https://api.github.com/users/bastiak/followers","following_url":"https://api.github.com/users/bastiak/following{/other_user}","gists_url":"https://api.github.com/users/bastiak/gists{/gist_id}","starred_url":"https://api.github.com/users/bastiak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bastiak/subscriptions","organizations_url":"https://api.github.com/users/bastiak/orgs","repos_url":"https://api.github.com/users/bastiak/repos","events_url":"https://api.github.com/users/bastiak/events{/privacy}","received_events_url":"https://api.github.com/users/bastiak/received_events","type":"User","site_admin":false},"repo":{"id":18794901,"name":"dnspython","full_name":"bastiak/dnspython","owner":{"login":"bastiak","id":4238177,"avatar_url":"https://avatars.githubusercontent.com/u/4238177?v=3","gravatar_id":"","url":"https://api.github.com/users/bastiak","html_url":"https://github.com/bastiak","followers_url":"https://api.github.com/users/bastiak/followers","following_url":"https://api.github.com/users/bastiak/following{/other_user}","gists_url":"https://api.github.com/users/bastiak/gists{/gist_id}","starred_url":"https://api.github.com/users/bastiak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bastiak/subscriptions","organizations_url":"https://api.github.com/users/bastiak/orgs","repos_url":"https://api.github.com/users/bastiak/repos","events_url":"https://api.github.com/users/bastiak/events{/privacy}","received_events_url":"https://api.github.com/users/bastiak/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bastiak/dnspython","description":"a powerful DNS toolkit for python","fork":true,"url":"https://api.github.com/repos/bastiak/dnspython","forks_url":"https://api.github.com/repos/bastiak/dnspython/forks","keys_url":"https://api.github.com/repos/bastiak/dnspython/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bastiak/dnspython/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bastiak/dnspython/teams","hooks_url":"https://api.github.com/repos/bastiak/dnspython/hooks","issue_events_url":"https://api.github.com/repos/bastiak/dnspython/issues/events{/number}","events_url":"https://api.github.com/repos/bastiak/dnspython/events","assignees_url":"https://api.github.com/repos/bastiak/dnspython/assignees{/user}","branches_url":"https://api.github.com/repos/bastiak/dnspython/branches{/branch}","tags_url":"https://api.github.com/repos/bastiak/dnspython/tags","blobs_url":"https://api.github.com/repos/bastiak/dnspython/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bastiak/dnspython/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bastiak/dnspython/git/refs{/sha}","trees_url":"https://api.github.com/repos/bastiak/dnspython/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bastiak/dnspython/statuses/{sha}","languages_url":"https://api.github.com/repos/bastiak/dnspython/languages","stargazers_url":"https://api.github.com/repos/bastiak/dnspython/stargazers","contributors_url":"https://api.github.com/repos/bastiak/dnspython/contributors","subscribers_url":"https://api.github.com/repos/bastiak/dnspython/subscribers","subscription_url":"https://api.github.com/repos/bastiak/dnspython/subscription","commits_url":"https://api.github.com/repos/bastiak/dnspython/commits{/sha}","git_commits_url":"https://api.github.com/repos/bastiak/dnspython/git/commits{/sha}","comments_url":"https://api.github.com/repos/bastiak/dnspython/comments{/number}","issue_comment_url":"https://api.github.com/repos/bastiak/dnspython/issues/comments{/number}","contents_url":"https://api.github.com/repos/bastiak/dnspython/contents/{+path}","compare_url":"https://api.github.com/repos/bastiak/dnspython/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bastiak/dnspython/merges","archive_url":"https://api.github.com/repos/bastiak/dnspython/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bastiak/dnspython/downloads","issues_url":"https://api.github.com/repos/bastiak/dnspython/issues{/number}","pulls_url":"https://api.github.com/repos/bastiak/dnspython/pulls{/number}","milestones_url":"https://api.github.com/repos/bastiak/dnspython/milestones{/number}","notifications_url":"https://api.github.com/repos/bastiak/dnspython/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bastiak/dnspython/labels{/name}","releases_url":"https://api.github.com/repos/bastiak/dnspython/releases{/id}","deployments_url":"https://api.github.com/repos/bastiak/dnspython/deployments","created_at":"2014-04-15T09:42:09Z","updated_at":"2016-01-29T17:24:57Z","pushed_at":"2016-08-04T23:34:19Z","git_url":"git://github.com/bastiak/dnspython.git","ssh_url":"git@github.com:bastiak/dnspython.git","clone_url":"https://github.com/bastiak/dnspython.git","svn_url":"https://github.com/bastiak/dnspython","homepage":"http://www.dnspython.org","size":1313,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rthalley:master","ref":"master","sha":"5ea92537d776687e1718a3fba11ff5509166f6e8","user":{"login":"rthalley","id":78507,"avatar_url":"https://avatars.githubusercontent.com/u/78507?v=3","gravatar_id":"","url":"https://api.github.com/users/rthalley","html_url":"https://github.com/rthalley","followers_url":"https://api.github.com/users/rthalley/followers","following_url":"https://api.github.com/users/rthalley/following{/other_user}","gists_url":"https://api.github.com/users/rthalley/gists{/gist_id}","starred_url":"https://api.github.com/users/rthalley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rthalley/subscriptions","organizations_url":"https://api.github.com/users/rthalley/orgs","repos_url":"https://api.github.com/users/rthalley/repos","events_url":"https://api.github.com/users/rthalley/events{/privacy}","received_events_url":"https://api.github.com/users/rthalley/received_events","type":"User","site_admin":false},"repo":{"id":2261155,"name":"dnspython","full_name":"rthalley/dnspython","owner":{"login":"rthalley","id":78507,"avatar_url":"https://avatars.githubusercontent.com/u/78507?v=3","gravatar_id":"","url":"https://api.github.com/users/rthalley","html_url":"https://github.com/rthalley","followers_url":"https://api.github.com/users/rthalley/followers","following_url":"https://api.github.com/users/rthalley/following{/other_user}","gists_url":"https://api.github.com/users/rthalley/gists{/gist_id}","starred_url":"https://api.github.com/users/rthalley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rthalley/subscriptions","organizations_url":"https://api.github.com/users/rthalley/orgs","repos_url":"https://api.github.com/users/rthalley/repos","events_url":"https://api.github.com/users/rthalley/events{/privacy}","received_events_url":"https://api.github.com/users/rthalley/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rthalley/dnspython","description":"a powerful DNS toolkit for python","fork":false,"url":"https://api.github.com/repos/rthalley/dnspython","forks_url":"https://api.github.com/repos/rthalley/dnspython/forks","keys_url":"https://api.github.com/repos/rthalley/dnspython/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rthalley/dnspython/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rthalley/dnspython/teams","hooks_url":"https://api.github.com/repos/rthalley/dnspython/hooks","issue_events_url":"https://api.github.com/repos/rthalley/dnspython/issues/events{/number}","events_url":"https://api.github.com/repos/rthalley/dnspython/events","assignees_url":"https://api.github.com/repos/rthalley/dnspython/assignees{/user}","branches_url":"https://api.github.com/repos/rthalley/dnspython/branches{/branch}","tags_url":"https://api.github.com/repos/rthalley/dnspython/tags","blobs_url":"https://api.github.com/repos/rthalley/dnspython/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rthalley/dnspython/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rthalley/dnspython/git/refs{/sha}","trees_url":"https://api.github.com/repos/rthalley/dnspython/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rthalley/dnspython/statuses/{sha}","languages_url":"https://api.github.com/repos/rthalley/dnspython/languages","stargazers_url":"https://api.github.com/repos/rthalley/dnspython/stargazers","contributors_url":"https://api.github.com/repos/rthalley/dnspython/contributors","subscribers_url":"https://api.github.com/repos/rthalley/dnspython/subscribers","subscription_url":"https://api.github.com/repos/rthalley/dnspython/subscription","commits_url":"https://api.github.com/repos/rthalley/dnspython/commits{/sha}","git_commits_url":"https://api.github.com/repos/rthalley/dnspython/git/commits{/sha}","comments_url":"https://api.github.com/repos/rthalley/dnspython/comments{/number}","issue_comment_url":"https://api.github.com/repos/rthalley/dnspython/issues/comments{/number}","contents_url":"https://api.github.com/repos/rthalley/dnspython/contents/{+path}","compare_url":"https://api.github.com/repos/rthalley/dnspython/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rthalley/dnspython/merges","archive_url":"https://api.github.com/repos/rthalley/dnspython/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rthalley/dnspython/downloads","issues_url":"https://api.github.com/repos/rthalley/dnspython/issues{/number}","pulls_url":"https://api.github.com/repos/rthalley/dnspython/pulls{/number}","milestones_url":"https://api.github.com/repos/rthalley/dnspython/milestones{/number}","notifications_url":"https://api.github.com/repos/rthalley/dnspython/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rthalley/dnspython/labels{/name}","releases_url":"https://api.github.com/repos/rthalley/dnspython/releases{/id}","deployments_url":"https://api.github.com/repos/rthalley/dnspython/deployments","created_at":"2011-08-24T11:36:39Z","updated_at":"2016-08-03T03:18:29Z","pushed_at":"2016-08-05T15:15:55Z","git_url":"git://github.com/rthalley/dnspython.git","ssh_url":"git@github.com:rthalley/dnspython.git","clone_url":"https://github.com/rthalley/dnspython.git","svn_url":"https://github.com/rthalley/dnspython","homepage":"http://www.dnspython.org","size":1871,"stargazers_count":581,"watchers_count":581,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":151,"mirror_url":null,"open_issues_count":15,"forks":151,"open_issues":15,"watchers":581,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rthalley/dnspython/pulls/188"},"html":{"href":"https://github.com/rthalley/dnspython/pull/188"},"issue":{"href":"https://api.github.com/repos/rthalley/dnspython/issues/188"},"comments":{"href":"https://api.github.com/repos/rthalley/dnspython/issues/188/comments"},"review_comments":{"href":"https://api.github.com/repos/rthalley/dnspython/pulls/188/comments"},"review_comment":{"href":"https://api.github.com/repos/rthalley/dnspython/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rthalley/dnspython/pulls/188/commits"},"statuses":{"href":"https://api.github.com/repos/rthalley/dnspython/statuses/ae19cb5bea06a8ef7792d865eb134c9af9fa1307"}}}}
{"actor":{"display_login":"sebix"}}