{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-notifications/pulls/comments/24115799","id":24115799,"diff_hunk":"@@ -0,0 +1,287 @@\n+\"\"\"\n+Base objects that data.py uses\n+\"\"\"\n+\n+import json\n+import copy\n+import inspect\n+import dateutil.parser\n+\n+from datetime import datetime\n+\n+from weakref import WeakKeyDictionary\n+\n+\n+class TypedField(object):\n+    \"\"\"\n+    Field Decscriptors used to enforce correct typing\n+    \"\"\"\n+\n+    _expected_type = None\n+\n+    def __init__(self, *args, **kwargs):\n+        \"\"\"\n+        Initializer which takes in the type this field\n+        should be set it is set\n+        \"\"\"\n+\n+        self._expected_type = [args[0]] if not isinstance(args[0], list) else args[0]\n+        self._default = kwargs.get('default', None)\n+        self._data = WeakKeyDictionary()\n+\n+    def __get__(self, instance, owner):\n+        \"\"\"\n+        Descriptor getter\n+        \"\"\"\n+        if not instance:\n+            # called as a class method, so return the descriptor (ourselves)\n+            return self\n+\n+        return self._data.get(instance, self._default)\n+\n+    def __set__(self, instance, value):\n+        \"\"\"\n+        Descriptor setter. Be sure to enforce type on setting. But None is allowed.\n+        \"\"\"\n+\n+        value_type = type(value)\n+\n+        if value and type(value) not in self._expected_type:\n+            raise TypeError(\n+                (\n+                    \"Field expected type of '{expected}' got '{got}'\"\n+                ).format(expected=self._expected_type, got=value_type)\n+            )\n+        self._data[instance] = value\n+\n+\n+class StringField(TypedField):\n+    \"\"\"\n+    Specialized subclass of TypedField(unicode) as a convienence\n+    \"\"\"\n+\n+    def __init__(self, **kwargs):\n+        super(StringField, self).__init__(unicode, kwargs)\n+\n+    def __set__(self, instance, value):\n+        \"\"\"\n+        Check to see if we were passed a str type, and if so\n+        coerce it into a unicode\n+        \"\"\"\n+\n+        if isinstance(value, str):\n+            super(StringField, self).__set__(instance, unicode(value))\n+        else:\n+            super(StringField, self).__set__(instance, value)\n+\n+\n+class IntegerField(TypedField):\n+    \"\"\"\n+    Specialized subclass of TypedField(int) as a convienence\n+    \"\"\"\n+\n+    def __init__(self, **kwargs):\n+        super(IntegerField, self).__init__([int, long], kwargs)\n+\n+\n+class DictField(TypedField):\n+    \"\"\"\n+    Specialized subclass of TypedField(dict) as a convienence\n+    \"\"\"\n+\n+    def __init__(self, **kwargs):\n+        super(DictField, self).__init__(dict, kwargs)\n+\n+    @classmethod\n+    def to_json(cls, data):\n+        \"\"\"\n+        Serialize to json\n+        \"\"\"\n+\n+        if not data:\n+            return None\n+\n+        _dict = copy.deepcopy(data)\n+\n+        for key, value in _dict.iteritems():\n+            if isinstance(value, datetime):\n+                _dict[key] = value.isoformat()\n+\n+        return json.dumps(_dict)\n+\n+    @classmethod\n+    def from_json(cls, value):\n+        \"\"\"\n+        Descerialize from json\n+        \"\"\"\n+\n+        if not value:\n+            return None\n+\n+        _dict = json.loads(value)\n+\n+        for key, value in _dict.iteritems():\n+            if isinstance(value, basestring):\n+                # This could be a datetime posing as a ISO8601 formatted string\n+                # we so have to apply some heuristics here\n+                # to see if we want to even attempt\n+                if value.count('-') == 2 and value.count(':') == 2 and value.count('T') == 1:","path":"edx_notifications/base_data.py","position":128,"original_position":128,"commit_id":"90b47f7a737e306a52cb97603e28fb6deef13f82","original_commit_id":"0a1727596a63c40359e988cf4e55815283166e0c","user":{"login":"chrisndodge","id":2362917,"avatar_url":"https://avatars.githubusercontent.com/u/2362917?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisndodge","html_url":"https://github.com/chrisndodge","followers_url":"https://api.github.com/users/chrisndodge/followers","following_url":"https://api.github.com/users/chrisndodge/following{/other_user}","gists_url":"https://api.github.com/users/chrisndodge/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisndodge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisndodge/subscriptions","organizations_url":"https://api.github.com/users/chrisndodge/orgs","repos_url":"https://api.github.com/users/chrisndodge/repos","events_url":"https://api.github.com/users/chrisndodge/events{/privacy}","received_events_url":"https://api.github.com/users/chrisndodge/received_events","type":"User","site_admin":false},"body":"do you mean a string \"magic\" prefix?","created_at":"2015-02-04T20:20:57Z","updated_at":"2015-02-04T20:20:57Z","html_url":"https://github.com/edx/edx-notifications/pull/12#discussion_r24115799","pull_request_url":"https://api.github.com/repos/edx/edx-notifications/pulls/12","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-notifications/pulls/comments/24115799"},"html":{"href":"https://github.com/edx/edx-notifications/pull/12#discussion_r24115799"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-notifications/pulls/12"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-notifications/pulls/12","id":28491511,"html_url":"https://github.com/edx/edx-notifications/pull/12","diff_url":"https://github.com/edx/edx-notifications/pull/12.diff","patch_url":"https://github.com/edx/edx-notifications/pull/12.patch","issue_url":"https://api.github.com/repos/edx/edx-notifications/issues/12","number":12,"state":"open","locked":false,"title":"For ongoing reviews/comments","user":{"login":"chrisndodge","id":2362917,"avatar_url":"https://avatars.githubusercontent.com/u/2362917?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisndodge","html_url":"https://github.com/chrisndodge","followers_url":"https://api.github.com/users/chrisndodge/followers","following_url":"https://api.github.com/users/chrisndodge/following{/other_user}","gists_url":"https://api.github.com/users/chrisndodge/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisndodge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisndodge/subscriptions","organizations_url":"https://api.github.com/users/chrisndodge/orgs","repos_url":"https://api.github.com/users/chrisndodge/repos","events_url":"https://api.github.com/users/chrisndodge/events{/privacy}","received_events_url":"https://api.github.com/users/chrisndodge/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-02-02T18:37:25Z","updated_at":"2015-02-04T20:20:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a0ac7cfcb31298225b1102a5e2db9cfc662229c5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-notifications/pulls/12/commits","review_comments_url":"https://api.github.com/repos/edx/edx-notifications/pulls/12/comments","review_comment_url":"https://api.github.com/repos/edx/edx-notifications/pulls/comments/{number}","comments_url":"https://api.github.com/repos/edx/edx-notifications/issues/12/comments","statuses_url":"https://api.github.com/repos/edx/edx-notifications/statuses/90b47f7a737e306a52cb97603e28fb6deef13f82","head":{"label":"edx:master","ref":"master","sha":"90b47f7a737e306a52cb97603e28fb6deef13f82","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":29154572,"name":"edx-notifications","full_name":"edx/edx-notifications","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-notifications","description":"","fork":false,"url":"https://api.github.com/repos/edx/edx-notifications","forks_url":"https://api.github.com/repos/edx/edx-notifications/forks","keys_url":"https://api.github.com/repos/edx/edx-notifications/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-notifications/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-notifications/teams","hooks_url":"https://api.github.com/repos/edx/edx-notifications/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-notifications/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-notifications/events","assignees_url":"https://api.github.com/repos/edx/edx-notifications/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-notifications/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-notifications/tags","blobs_url":"https://api.github.com/repos/edx/edx-notifications/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-notifications/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-notifications/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-notifications/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-notifications/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-notifications/languages","stargazers_url":"https://api.github.com/repos/edx/edx-notifications/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-notifications/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-notifications/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-notifications/subscription","commits_url":"https://api.github.com/repos/edx/edx-notifications/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-notifications/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-notifications/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-notifications/issues/comments/{number}","contents_url":"https://api.github.com/repos/edx/edx-notifications/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-notifications/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-notifications/merges","archive_url":"https://api.github.com/repos/edx/edx-notifications/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-notifications/downloads","issues_url":"https://api.github.com/repos/edx/edx-notifications/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-notifications/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-notifications/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-notifications/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-notifications/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-notifications/releases{/id}","created_at":"2015-01-12T20:11:02Z","updated_at":"2015-02-04T18:34:31Z","pushed_at":"2015-02-04T18:34:30Z","git_url":"git://github.com/edx/edx-notifications.git","ssh_url":"git@github.com:edx/edx-notifications.git","clone_url":"https://github.com/edx/edx-notifications.git","svn_url":"https://github.com/edx/edx-notifications","homepage":null,"size":1036,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":4,"forks":1,"open_issues":4,"watchers":0,"default_branch":"master"}},"base":{"label":"edx:empty","ref":"empty","sha":"e624fc3ebe0bc444ac580f93c4c971b4bb878c95","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":29154572,"name":"edx-notifications","full_name":"edx/edx-notifications","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-notifications","description":"","fork":false,"url":"https://api.github.com/repos/edx/edx-notifications","forks_url":"https://api.github.com/repos/edx/edx-notifications/forks","keys_url":"https://api.github.com/repos/edx/edx-notifications/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-notifications/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-notifications/teams","hooks_url":"https://api.github.com/repos/edx/edx-notifications/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-notifications/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-notifications/events","assignees_url":"https://api.github.com/repos/edx/edx-notifications/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-notifications/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-notifications/tags","blobs_url":"https://api.github.com/repos/edx/edx-notifications/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-notifications/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-notifications/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-notifications/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-notifications/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-notifications/languages","stargazers_url":"https://api.github.com/repos/edx/edx-notifications/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-notifications/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-notifications/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-notifications/subscription","commits_url":"https://api.github.com/repos/edx/edx-notifications/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-notifications/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-notifications/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-notifications/issues/comments/{number}","contents_url":"https://api.github.com/repos/edx/edx-notifications/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-notifications/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-notifications/merges","archive_url":"https://api.github.com/repos/edx/edx-notifications/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-notifications/downloads","issues_url":"https://api.github.com/repos/edx/edx-notifications/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-notifications/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-notifications/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-notifications/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-notifications/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-notifications/releases{/id}","created_at":"2015-01-12T20:11:02Z","updated_at":"2015-02-04T18:34:31Z","pushed_at":"2015-02-04T18:34:30Z","git_url":"git://github.com/edx/edx-notifications.git","ssh_url":"git@github.com:edx/edx-notifications.git","clone_url":"https://github.com/edx/edx-notifications.git","svn_url":"https://github.com/edx/edx-notifications","homepage":null,"size":1036,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":4,"forks":1,"open_issues":4,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-notifications/pulls/12"},"html":{"href":"https://github.com/edx/edx-notifications/pull/12"},"issue":{"href":"https://api.github.com/repos/edx/edx-notifications/issues/12"},"comments":{"href":"https://api.github.com/repos/edx/edx-notifications/issues/12/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-notifications/pulls/12/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-notifications/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-notifications/pulls/12/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-notifications/statuses/90b47f7a737e306a52cb97603e28fb6deef13f82"}}}}