{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/kuma/pulls/comments/41791276","id":41791276,"diff_hunk":"@@ -0,0 +1,174 @@\n+import urlparse\n+\n+from constance import config\n+from django.conf import settings\n+from requests.packages.urllib3.util import Retry\n+from requests.adapters import HTTPAdapter\n+from requests import Session, exceptions\n+\n+\n+class AkismetError(Exception):\n+    \"\"\"\n+    A custom exception that takes the requests' response, its status code\n+    and an optional debug help directly from Akismet.\n+    \"\"\"\n+    def __init__(self, response, status_code, debug_help):\n+        self.response = response\n+        self.status_code = status_code\n+        self.debug_help = debug_help\n+\n+    def __str__(self):\n+        return ('%s response, debug help: %s, full response: %s' %\n+                (self.status_code, self.debug_help, self.response.text))\n+\n+\n+class Akismet(object):\n+    \"\"\"\n+    The Akismet client implementation wrapping a request session and\n+    having API specific methods for easy spam and ham handling.\n+    \"\"\"\n+    submission_success = 'Thanks for making the web a better place.'\n+\n+    def __init__(self):\n+        self.key = config.AKISMET_KEY\n+        self.domain = settings.DOMAIN\n+        self.session = Session()\n+        self.adapter = HTTPAdapter(\n+            max_retries=Retry(\n+                # number of total retries\n+                total=5,\n+                # retry once in case we can't connect to Akismet\n+                connect=1,\n+                # retry once in case we can't read the response from Akismet\n+                read=1,\n+                # retry once in case we're redirect by Akismet\n+                redirect=1,\n+                # definitely retry if Akismet is unwell\n+                status_forcelist=[500, 503])\n+        )\n+        self.session.mount('http://', self.adapter)\n+        self.session.mount('https://', self.adapter)\n+        # define if this client is even usable\n+        # use this in the app code\n+        try:\n+            self.ready = self.verify_key()\n+        except AkismetError:\n+            # just take a shortcut when there was an\n+            # error accessing Akismet\n+            self.ready = False\n+\n+    @property\n+    def url(self):\n+        return 'https://%s.rest.akismet.com/1.1/' % self.key\n+\n+    def send(self, method, user_ip='', user_agent='', **payload):","path":"kuma/spam/akismet.py","position":64,"original_position":64,"commit_id":"c624cd8cb2e6b2e34e538f51676f8200a477514a","original_commit_id":"c624cd8cb2e6b2e34e538f51676f8200a477514a","user":{"login":"jezdez","id":1610,"avatar_url":"https://avatars.githubusercontent.com/u/1610?v=3","gravatar_id":"","url":"https://api.github.com/users/jezdez","html_url":"https://github.com/jezdez","followers_url":"https://api.github.com/users/jezdez/followers","following_url":"https://api.github.com/users/jezdez/following{/other_user}","gists_url":"https://api.github.com/users/jezdez/gists{/gist_id}","starred_url":"https://api.github.com/users/jezdez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jezdez/subscriptions","organizations_url":"https://api.github.com/users/jezdez/orgs","repos_url":"https://api.github.com/users/jezdez/repos","events_url":"https://api.github.com/users/jezdez/events{/privacy}","received_events_url":"https://api.github.com/users/jezdez/received_events","type":"User","site_admin":false},"body":"Ah, ok, I'll take another look and will get back to you","created_at":"2015-10-12T19:20:02Z","updated_at":"2015-10-12T19:20:02Z","html_url":"https://github.com/mozilla/kuma/pull/3482#discussion_r41791276","pull_request_url":"https://api.github.com/repos/mozilla/kuma/pulls/3482","_links":{"self":{"href":"https://api.github.com/repos/mozilla/kuma/pulls/comments/41791276"},"html":{"href":"https://github.com/mozilla/kuma/pull/3482#discussion_r41791276"},"pull_request":{"href":"https://api.github.com/repos/mozilla/kuma/pulls/3482"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/kuma/pulls/3482","id":45093707,"html_url":"https://github.com/mozilla/kuma/pull/3482","diff_url":"https://github.com/mozilla/kuma/pull/3482.diff","patch_url":"https://github.com/mozilla/kuma/pull/3482.patch","issue_url":"https://api.github.com/repos/mozilla/kuma/issues/3482","number":3482,"state":"open","locked":false,"title":"Bug 1188029 - Spam prevention via Akismet","user":{"login":"jezdez","id":1610,"avatar_url":"https://avatars.githubusercontent.com/u/1610?v=3","gravatar_id":"","url":"https://api.github.com/users/jezdez","html_url":"https://github.com/jezdez","followers_url":"https://api.github.com/users/jezdez/followers","following_url":"https://api.github.com/users/jezdez/following{/other_user}","gists_url":"https://api.github.com/users/jezdez/gists{/gist_id}","starred_url":"https://api.github.com/users/jezdez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jezdez/subscriptions","organizations_url":"https://api.github.com/users/jezdez/orgs","repos_url":"https://api.github.com/users/jezdez/repos","events_url":"https://api.github.com/users/jezdez/events{/privacy}","received_events_url":"https://api.github.com/users/jezdez/received_events","type":"User","site_admin":false},"body":null,"created_at":"2015-09-15T19:49:09Z","updated_at":"2015-10-12T19:20:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ffafedc53b119a82f54b58150d43c75e08fdf2c2","assignee":{"login":"jwhitlock","id":286017,"avatar_url":"https://avatars.githubusercontent.com/u/286017?v=3","gravatar_id":"","url":"https://api.github.com/users/jwhitlock","html_url":"https://github.com/jwhitlock","followers_url":"https://api.github.com/users/jwhitlock/followers","following_url":"https://api.github.com/users/jwhitlock/following{/other_user}","gists_url":"https://api.github.com/users/jwhitlock/gists{/gist_id}","starred_url":"https://api.github.com/users/jwhitlock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwhitlock/subscriptions","organizations_url":"https://api.github.com/users/jwhitlock/orgs","repos_url":"https://api.github.com/users/jwhitlock/repos","events_url":"https://api.github.com/users/jwhitlock/events{/privacy}","received_events_url":"https://api.github.com/users/jwhitlock/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/kuma/pulls/3482/commits","review_comments_url":"https://api.github.com/repos/mozilla/kuma/pulls/3482/comments","review_comment_url":"https://api.github.com/repos/mozilla/kuma/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/kuma/issues/3482/comments","statuses_url":"https://api.github.com/repos/mozilla/kuma/statuses/c624cd8cb2e6b2e34e538f51676f8200a477514a","head":{"label":"mozilla:bug1188029","ref":"bug1188029","sha":"c624cd8cb2e6b2e34e538f51676f8200a477514a","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":1352520,"name":"kuma","full_name":"mozilla/kuma","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/kuma","description":"The Django project that powers MDN.","fork":false,"url":"https://api.github.com/repos/mozilla/kuma","forks_url":"https://api.github.com/repos/mozilla/kuma/forks","keys_url":"https://api.github.com/repos/mozilla/kuma/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/kuma/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/kuma/teams","hooks_url":"https://api.github.com/repos/mozilla/kuma/hooks","issue_events_url":"https://api.github.com/repos/mozilla/kuma/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/kuma/events","assignees_url":"https://api.github.com/repos/mozilla/kuma/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/kuma/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/kuma/tags","blobs_url":"https://api.github.com/repos/mozilla/kuma/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/kuma/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/kuma/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/kuma/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/kuma/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/kuma/languages","stargazers_url":"https://api.github.com/repos/mozilla/kuma/stargazers","contributors_url":"https://api.github.com/repos/mozilla/kuma/contributors","subscribers_url":"https://api.github.com/repos/mozilla/kuma/subscribers","subscription_url":"https://api.github.com/repos/mozilla/kuma/subscription","commits_url":"https://api.github.com/repos/mozilla/kuma/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/kuma/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/kuma/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/kuma/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/kuma/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/kuma/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/kuma/merges","archive_url":"https://api.github.com/repos/mozilla/kuma/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/kuma/downloads","issues_url":"https://api.github.com/repos/mozilla/kuma/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/kuma/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/kuma/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/kuma/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/kuma/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/kuma/releases{/id}","created_at":"2011-02-10T21:48:06Z","updated_at":"2015-10-07T11:15:40Z","pushed_at":"2015-10-12T18:32:51Z","git_url":"git://github.com/mozilla/kuma.git","ssh_url":"git@github.com:mozilla/kuma.git","clone_url":"https://github.com/mozilla/kuma.git","svn_url":"https://github.com/mozilla/kuma","homepage":"https://developer.mozilla.org","size":161390,"stargazers_count":649,"watchers_count":649,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":426,"mirror_url":null,"open_issues_count":12,"forks":426,"open_issues":12,"watchers":649,"default_branch":"master"}},"base":{"label":"mozilla:master","ref":"master","sha":"d0767f54040b2d774a51be0c0371e3c838e4eaf6","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":1352520,"name":"kuma","full_name":"mozilla/kuma","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/kuma","description":"The Django project that powers MDN.","fork":false,"url":"https://api.github.com/repos/mozilla/kuma","forks_url":"https://api.github.com/repos/mozilla/kuma/forks","keys_url":"https://api.github.com/repos/mozilla/kuma/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/kuma/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/kuma/teams","hooks_url":"https://api.github.com/repos/mozilla/kuma/hooks","issue_events_url":"https://api.github.com/repos/mozilla/kuma/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/kuma/events","assignees_url":"https://api.github.com/repos/mozilla/kuma/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/kuma/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/kuma/tags","blobs_url":"https://api.github.com/repos/mozilla/kuma/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/kuma/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/kuma/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/kuma/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/kuma/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/kuma/languages","stargazers_url":"https://api.github.com/repos/mozilla/kuma/stargazers","contributors_url":"https://api.github.com/repos/mozilla/kuma/contributors","subscribers_url":"https://api.github.com/repos/mozilla/kuma/subscribers","subscription_url":"https://api.github.com/repos/mozilla/kuma/subscription","commits_url":"https://api.github.com/repos/mozilla/kuma/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/kuma/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/kuma/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/kuma/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/kuma/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/kuma/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/kuma/merges","archive_url":"https://api.github.com/repos/mozilla/kuma/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/kuma/downloads","issues_url":"https://api.github.com/repos/mozilla/kuma/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/kuma/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/kuma/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/kuma/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/kuma/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/kuma/releases{/id}","created_at":"2011-02-10T21:48:06Z","updated_at":"2015-10-07T11:15:40Z","pushed_at":"2015-10-12T18:32:51Z","git_url":"git://github.com/mozilla/kuma.git","ssh_url":"git@github.com:mozilla/kuma.git","clone_url":"https://github.com/mozilla/kuma.git","svn_url":"https://github.com/mozilla/kuma","homepage":"https://developer.mozilla.org","size":161390,"stargazers_count":649,"watchers_count":649,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":426,"mirror_url":null,"open_issues_count":12,"forks":426,"open_issues":12,"watchers":649,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/kuma/pulls/3482"},"html":{"href":"https://github.com/mozilla/kuma/pull/3482"},"issue":{"href":"https://api.github.com/repos/mozilla/kuma/issues/3482"},"comments":{"href":"https://api.github.com/repos/mozilla/kuma/issues/3482/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/kuma/pulls/3482/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/kuma/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/kuma/pulls/3482/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/kuma/statuses/c624cd8cb2e6b2e34e538f51676f8200a477514a"}}}}