{"action":"created","comment":{"url":"https://api.github.com/repos/uber/tchannel/pulls/comments/29523581","id":29523581,"diff_hunk":"@@ -0,0 +1,421 @@\n+# Copyright (c) 2015 Uber Technologies, Inc.\n+#\n+# Permission is hereby granted, free of charge, to any person obtaining a copy\n+# of this software and associated documentation files (the \"Software\"), to deal\n+# in the Software without restriction, including without limitation the rights\n+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+# copies of the Software, and to permit persons to whom the Software is\n+# furnished to do so, subject to the following conditions:\n+#\n+# The above copyright notice and this permission notice shall be included in\n+# all copies or substantial portions of the Software.\n+#\n+# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+# THE SOFTWARE.\n+\n+from __future__ import absolute_import\n+\n+\n+import tornado\n+import tornado.gen\n+\n+from ..messages.common import StreamState, FlagsType\n+from .stream import InMemStream\n+from .util import get_arg, serialize_json, deserialize_json\n+from ..zipkin.trace import Trace\n+from ..exceptions import TChannelException\n+\n+\n+class Request(object):\n+    \"\"\"Represents an incoming request to an endpoint.\n+\n+    Request class is used to represent the CallRequestMessage at User's level.\n+    This is going to hide the protocol level message information.\n+    \"\"\"\n+\n+    # TODO decide which elements inside \"message\" object to expose to user.\n+    def __init__(\n+        self,\n+        id=None,\n+        flags=FlagsType.none,\n+        ttl=10,\n+        tracing=None,\n+        service=None,\n+        headers=None,\n+        checksum=None,\n+        argstreams=None\n+    ):\n+        self.flags = flags\n+        self.ttl = ttl\n+        self.service = service\n+        self.tracing = tracing or Trace()\n+        # argstreams is a list of InMemStream/PipeStream objects\n+        self.argstreams = argstreams\n+        self.checksum = checksum\n+        self.id = id\n+        self.headers = headers or {}\n+        self.state = StreamState.init\n+        self.endpoint = \"\"\n+        self.header = None\n+        self.body = None\n+\n+    @property\n+    def arg_scheme(self):\n+        return self.headers.get('as', None)\n+\n+    def close_argstreams(self, force=False):\n+        for stream in self.argstreams:\n+            if stream.auto_close or force:\n+                stream.close()\n+\n+    def get_header(self):\n+        \"\"\"Get the header value from the request.\n+\n+        :return: a future contains the value of header\n+        \"\"\"\n+        return get_arg(self, 1)\n+\n+    def get_body(self):\n+        \"\"\"Get the body value from the request.\n+\n+        :return: a future contains the value of body\n+        \"\"\"\n+        return get_arg(self, 2)\n+\n+    def get_header_s(self):\n+        \"\"\"Get the raw stream of header.\n+\n+        :return: the argstream of header\n+        \"\"\"\n+        return self.argstreams[1]\n+\n+    def get_body_s(self):\n+        \"\"\"Get the raw stream of body.\n+\n+        :return: the argstream of body\n+        \"\"\"\n+        return self.argstreams[2]\n+\n+\n+class JsonRequest(Request):\n+    def __init__(self, req=None, serializer=None, deserializer=None):\n+        if isinstance(req, Request):\n+            super(JsonRequest, self).__init__(\n+                id=req.id,\n+                flags=req.flags,\n+                ttl=req.ttl,\n+                tracing=req.tracing,\n+                service=req.service,\n+                headers=req.headers,\n+                checksum=req.checksum,","path":"python/tchannel/tornado/data.py","position":115,"original_position":115,"commit_id":"571146395e6c3696689ee00e3ba2506476e9c81d","original_commit_id":"571146395e6c3696689ee00e3ba2506476e9c81d","user":{"login":"abhinav","id":41730,"avatar_url":"https://avatars.githubusercontent.com/u/41730?v=3","gravatar_id":"","url":"https://api.github.com/users/abhinav","html_url":"https://github.com/abhinav","followers_url":"https://api.github.com/users/abhinav/followers","following_url":"https://api.github.com/users/abhinav/following{/other_user}","gists_url":"https://api.github.com/users/abhinav/gists{/gist_id}","starred_url":"https://api.github.com/users/abhinav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abhinav/subscriptions","organizations_url":"https://api.github.com/users/abhinav/orgs","repos_url":"https://api.github.com/users/abhinav/repos","events_url":"https://api.github.com/users/abhinav/events{/privacy}","received_events_url":"https://api.github.com/users/abhinav/received_events","type":"User","site_admin":false},"body":"Indentation","created_at":"2015-05-01T18:43:05Z","updated_at":"2015-05-01T18:43:05Z","html_url":"https://github.com/uber/tchannel/pull/508#discussion_r29523581","pull_request_url":"https://api.github.com/repos/uber/tchannel/pulls/508","_links":{"self":{"href":"https://api.github.com/repos/uber/tchannel/pulls/comments/29523581"},"html":{"href":"https://github.com/uber/tchannel/pull/508#discussion_r29523581"},"pull_request":{"href":"https://api.github.com/repos/uber/tchannel/pulls/508"}}},"pull_request":{"url":"https://api.github.com/repos/uber/tchannel/pulls/508","id":34556971,"html_url":"https://github.com/uber/tchannel/pull/508","diff_url":"https://github.com/uber/tchannel/pull/508.diff","patch_url":"https://github.com/uber/tchannel/pull/508.patch","issue_url":"https://api.github.com/repos/uber/tchannel/issues/508","number":508,"state":"open","locked":false,"title":"add tchannel json arg schema","user":{"login":"junchaowu","id":3731781,"avatar_url":"https://avatars.githubusercontent.com/u/3731781?v=3","gravatar_id":"","url":"https://api.github.com/users/junchaowu","html_url":"https://github.com/junchaowu","followers_url":"https://api.github.com/users/junchaowu/followers","following_url":"https://api.github.com/users/junchaowu/following{/other_user}","gists_url":"https://api.github.com/users/junchaowu/gists{/gist_id}","starred_url":"https://api.github.com/users/junchaowu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/junchaowu/subscriptions","organizations_url":"https://api.github.com/users/junchaowu/orgs","repos_url":"https://api.github.com/users/junchaowu/repos","events_url":"https://api.github.com/users/junchaowu/events{/privacy}","received_events_url":"https://api.github.com/users/junchaowu/received_events","type":"User","site_admin":false},"body":"cc @breerly @abhinav @blampe \r\n\r\ntest_json_trace is example how to use it in both client and server sides.\r\n","created_at":"2015-05-01T18:39:15Z","updated_at":"2015-05-01T18:43:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dc74a5711711a7b3fe913743ab72a59ef61479a0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/uber/tchannel/pulls/508/commits","review_comments_url":"https://api.github.com/repos/uber/tchannel/pulls/508/comments","review_comment_url":"https://api.github.com/repos/uber/tchannel/pulls/comments{/number}","comments_url":"https://api.github.com/repos/uber/tchannel/issues/508/comments","statuses_url":"https://api.github.com/repos/uber/tchannel/statuses/571146395e6c3696689ee00e3ba2506476e9c81d","head":{"label":"uber:json","ref":"json","sha":"571146395e6c3696689ee00e3ba2506476e9c81d","user":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"repo":{"id":28419663,"name":"tchannel","full_name":"uber/tchannel","owner":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber/tchannel","description":"network multiplexing and framing protocol for RPC","fork":false,"url":"https://api.github.com/repos/uber/tchannel","forks_url":"https://api.github.com/repos/uber/tchannel/forks","keys_url":"https://api.github.com/repos/uber/tchannel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber/tchannel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber/tchannel/teams","hooks_url":"https://api.github.com/repos/uber/tchannel/hooks","issue_events_url":"https://api.github.com/repos/uber/tchannel/issues/events{/number}","events_url":"https://api.github.com/repos/uber/tchannel/events","assignees_url":"https://api.github.com/repos/uber/tchannel/assignees{/user}","branches_url":"https://api.github.com/repos/uber/tchannel/branches{/branch}","tags_url":"https://api.github.com/repos/uber/tchannel/tags","blobs_url":"https://api.github.com/repos/uber/tchannel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber/tchannel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber/tchannel/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber/tchannel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber/tchannel/statuses/{sha}","languages_url":"https://api.github.com/repos/uber/tchannel/languages","stargazers_url":"https://api.github.com/repos/uber/tchannel/stargazers","contributors_url":"https://api.github.com/repos/uber/tchannel/contributors","subscribers_url":"https://api.github.com/repos/uber/tchannel/subscribers","subscription_url":"https://api.github.com/repos/uber/tchannel/subscription","commits_url":"https://api.github.com/repos/uber/tchannel/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber/tchannel/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber/tchannel/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber/tchannel/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber/tchannel/contents/{+path}","compare_url":"https://api.github.com/repos/uber/tchannel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber/tchannel/merges","archive_url":"https://api.github.com/repos/uber/tchannel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber/tchannel/downloads","issues_url":"https://api.github.com/repos/uber/tchannel/issues{/number}","pulls_url":"https://api.github.com/repos/uber/tchannel/pulls{/number}","milestones_url":"https://api.github.com/repos/uber/tchannel/milestones{/number}","notifications_url":"https://api.github.com/repos/uber/tchannel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber/tchannel/labels{/name}","releases_url":"https://api.github.com/repos/uber/tchannel/releases{/id}","created_at":"2014-12-23T21:06:57Z","updated_at":"2015-05-01T05:15:54Z","pushed_at":"2015-05-01T18:39:15Z","git_url":"git://github.com/uber/tchannel.git","ssh_url":"git@github.com:uber/tchannel.git","clone_url":"https://github.com/uber/tchannel.git","svn_url":"https://github.com/uber/tchannel","homepage":"","size":15525,"stargazers_count":47,"watchers_count":47,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":62,"forks":3,"open_issues":62,"watchers":47,"default_branch":"master"}},"base":{"label":"uber:master","ref":"master","sha":"f003b0c79bdc7e94d538dd49b3875c004b95a5e4","user":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"repo":{"id":28419663,"name":"tchannel","full_name":"uber/tchannel","owner":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber/tchannel","description":"network multiplexing and framing protocol for RPC","fork":false,"url":"https://api.github.com/repos/uber/tchannel","forks_url":"https://api.github.com/repos/uber/tchannel/forks","keys_url":"https://api.github.com/repos/uber/tchannel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber/tchannel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber/tchannel/teams","hooks_url":"https://api.github.com/repos/uber/tchannel/hooks","issue_events_url":"https://api.github.com/repos/uber/tchannel/issues/events{/number}","events_url":"https://api.github.com/repos/uber/tchannel/events","assignees_url":"https://api.github.com/repos/uber/tchannel/assignees{/user}","branches_url":"https://api.github.com/repos/uber/tchannel/branches{/branch}","tags_url":"https://api.github.com/repos/uber/tchannel/tags","blobs_url":"https://api.github.com/repos/uber/tchannel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber/tchannel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber/tchannel/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber/tchannel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber/tchannel/statuses/{sha}","languages_url":"https://api.github.com/repos/uber/tchannel/languages","stargazers_url":"https://api.github.com/repos/uber/tchannel/stargazers","contributors_url":"https://api.github.com/repos/uber/tchannel/contributors","subscribers_url":"https://api.github.com/repos/uber/tchannel/subscribers","subscription_url":"https://api.github.com/repos/uber/tchannel/subscription","commits_url":"https://api.github.com/repos/uber/tchannel/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber/tchannel/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber/tchannel/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber/tchannel/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber/tchannel/contents/{+path}","compare_url":"https://api.github.com/repos/uber/tchannel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber/tchannel/merges","archive_url":"https://api.github.com/repos/uber/tchannel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber/tchannel/downloads","issues_url":"https://api.github.com/repos/uber/tchannel/issues{/number}","pulls_url":"https://api.github.com/repos/uber/tchannel/pulls{/number}","milestones_url":"https://api.github.com/repos/uber/tchannel/milestones{/number}","notifications_url":"https://api.github.com/repos/uber/tchannel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber/tchannel/labels{/name}","releases_url":"https://api.github.com/repos/uber/tchannel/releases{/id}","created_at":"2014-12-23T21:06:57Z","updated_at":"2015-05-01T05:15:54Z","pushed_at":"2015-05-01T18:39:15Z","git_url":"git://github.com/uber/tchannel.git","ssh_url":"git@github.com:uber/tchannel.git","clone_url":"https://github.com/uber/tchannel.git","svn_url":"https://github.com/uber/tchannel","homepage":"","size":15525,"stargazers_count":47,"watchers_count":47,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":62,"forks":3,"open_issues":62,"watchers":47,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/uber/tchannel/pulls/508"},"html":{"href":"https://github.com/uber/tchannel/pull/508"},"issue":{"href":"https://api.github.com/repos/uber/tchannel/issues/508"},"comments":{"href":"https://api.github.com/repos/uber/tchannel/issues/508/comments"},"review_comments":{"href":"https://api.github.com/repos/uber/tchannel/pulls/508/comments"},"review_comment":{"href":"https://api.github.com/repos/uber/tchannel/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/uber/tchannel/pulls/508/commits"},"statuses":{"href":"https://api.github.com/repos/uber/tchannel/statuses/571146395e6c3696689ee00e3ba2506476e9c81d"}}}}