{"action":"created","comment":{"url":"https://api.github.com/repos/scrapy/parsel/pulls/comments/35858578","id":35858578,"diff_hunk":"@@ -66,26 +53,28 @@ class Selector(object_ref):\n     }\n     _lxml_smart_strings = False\n \n-    def __init__(self, response=None, text=None, type=None, namespaces=None,\n-                 _root=None, _expr=None):\n-        self.type = st = _st(response, type or self._default_type)\n+    def __init__(self, text=None, type=None, namespaces=None, root=None, _expr=None):\n+        self.type = st = _st(type or self._default_type)\n         self._parser = _ctgroup[st]['_parser']\n         self._csstranslator = _ctgroup[st]['_csstranslator']\n         self._tostring_method = _ctgroup[st]['_tostring_method']\n \n         if text is not None:\n-            response = _response_from_text(text, st)\n-\n-        if response is not None:\n-            _root = LxmlDocument(response, self._parser)\n+            root = self._get_root(text)\n+        elif root is None:\n+            raise ValueError(\"Selector needs either text or root argument\")\n \n-        self.response = response\n         self.namespaces = dict(self._default_namespaces)\n         if namespaces is not None:\n             self.namespaces.update(namespaces)\n-        self._root = _root\n+        self._root = root\n         self._expr = _expr\n \n+    def _get_root(self, text):\n+        body = text.strip().encode('utf8') or u'<html/>'","path":"parsel/unified.py","position":82,"original_position":82,"commit_id":"fa446916c83d14600e1653709d4160bbe4a83e37","original_commit_id":"fa446916c83d14600e1653709d4160bbe4a83e37","user":{"login":"kmike","id":107893,"avatar_url":"https://avatars.githubusercontent.com/u/107893?v=3","gravatar_id":"","url":"https://api.github.com/users/kmike","html_url":"https://github.com/kmike","followers_url":"https://api.github.com/users/kmike/followers","following_url":"https://api.github.com/users/kmike/following{/other_user}","gists_url":"https://api.github.com/users/kmike/gists{/gist_id}","starred_url":"https://api.github.com/users/kmike/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kmike/subscriptions","organizations_url":"https://api.github.com/users/kmike/orgs","repos_url":"https://api.github.com/users/kmike/repos","events_url":"https://api.github.com/users/kmike/events{/privacy}","received_events_url":"https://api.github.com/users/kmike/received_events","type":"User","site_admin":false},"body":"This doesn't look correct: if text is empty body becomes unicode (`u'<html/>'`), but if text is not empty body becomes a bytestring (`foo.encode('..')`).\r\n\r\nAFAIK we require unicode here to unify data to utf8 before passing it to lxml. LXML can work on bytes (it'll try to detect the encoding), but we can do it better because there are other signs available like HTTP headers.","created_at":"2015-07-30T10:43:41Z","updated_at":"2015-07-30T10:43:41Z","html_url":"https://github.com/scrapy/parsel/pull/4#discussion_r35858578","pull_request_url":"https://api.github.com/repos/scrapy/parsel/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/scrapy/parsel/pulls/comments/35858578"},"html":{"href":"https://github.com/scrapy/parsel/pull/4#discussion_r35858578"},"pull_request":{"href":"https://api.github.com/repos/scrapy/parsel/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/scrapy/parsel/pulls/4","id":40851453,"html_url":"https://github.com/scrapy/parsel/pull/4","diff_url":"https://github.com/scrapy/parsel/pull/4.diff","patch_url":"https://github.com/scrapy/parsel/pull/4.patch","issue_url":"https://api.github.com/repos/scrapy/parsel/issues/4","number":4,"state":"open","locked":false,"title":"Wrap-up selectors package extraction","user":{"login":"eliasdorneles","id":37565,"avatar_url":"https://avatars.githubusercontent.com/u/37565?v=3","gravatar_id":"","url":"https://api.github.com/users/eliasdorneles","html_url":"https://github.com/eliasdorneles","followers_url":"https://api.github.com/users/eliasdorneles/followers","following_url":"https://api.github.com/users/eliasdorneles/following{/other_user}","gists_url":"https://api.github.com/users/eliasdorneles/gists{/gist_id}","starred_url":"https://api.github.com/users/eliasdorneles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eliasdorneles/subscriptions","organizations_url":"https://api.github.com/users/eliasdorneles/orgs","repos_url":"https://api.github.com/users/eliasdorneles/repos","events_url":"https://api.github.com/users/eliasdorneles/events{/privacy}","received_events_url":"https://api.github.com/users/eliasdorneles/received_events","type":"User","site_admin":false},"body":"Hey folks!\r\n\r\nSo, this is the result of the work in the sprints at Europython, @dangra, @kmike and @bbotella helped me to wrap up the selectors module extraction from Scrapy, and made sure it's working with Python 3.\r\n\r\nWe decided on the name **parsel** -- thanks @Granitas for the nice suggestion :+1: =)\r\n\r\nNext things to do are update the docs and fix the docs build.\r\n\r\nI was hoping @kmike and @dangra would give it a final review, and then after the docs update I believe we can release to PyPI.\r\n\r\nWhat do you think?\r\nThanks everyone for the help, I had a great time doing this. :)","created_at":"2015-07-26T10:47:19Z","updated_at":"2015-07-30T10:43:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b3cc61ea887d0692909d90eaefe448c4c64cde05","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scrapy/parsel/pulls/4/commits","review_comments_url":"https://api.github.com/repos/scrapy/parsel/pulls/4/comments","review_comment_url":"https://api.github.com/repos/scrapy/parsel/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scrapy/parsel/issues/4/comments","statuses_url":"https://api.github.com/repos/scrapy/parsel/statuses/fa446916c83d14600e1653709d4160bbe4a83e37","head":{"label":"scrapy:wrapup-package-setup","ref":"wrapup-package-setup","sha":"fa446916c83d14600e1653709d4160bbe4a83e37","user":{"login":"scrapy","id":733635,"avatar_url":"https://avatars.githubusercontent.com/u/733635?v=3","gravatar_id":"","url":"https://api.github.com/users/scrapy","html_url":"https://github.com/scrapy","followers_url":"https://api.github.com/users/scrapy/followers","following_url":"https://api.github.com/users/scrapy/following{/other_user}","gists_url":"https://api.github.com/users/scrapy/gists{/gist_id}","starred_url":"https://api.github.com/users/scrapy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scrapy/subscriptions","organizations_url":"https://api.github.com/users/scrapy/orgs","repos_url":"https://api.github.com/users/scrapy/repos","events_url":"https://api.github.com/users/scrapy/events{/privacy}","received_events_url":"https://api.github.com/users/scrapy/received_events","type":"Organization","site_admin":false},"repo":{"id":34527721,"name":"parsel","full_name":"scrapy/parsel","owner":{"login":"scrapy","id":733635,"avatar_url":"https://avatars.githubusercontent.com/u/733635?v=3","gravatar_id":"","url":"https://api.github.com/users/scrapy","html_url":"https://github.com/scrapy","followers_url":"https://api.github.com/users/scrapy/followers","following_url":"https://api.github.com/users/scrapy/following{/other_user}","gists_url":"https://api.github.com/users/scrapy/gists{/gist_id}","starred_url":"https://api.github.com/users/scrapy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scrapy/subscriptions","organizations_url":"https://api.github.com/users/scrapy/orgs","repos_url":"https://api.github.com/users/scrapy/repos","events_url":"https://api.github.com/users/scrapy/events{/privacy}","received_events_url":"https://api.github.com/users/scrapy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scrapy/parsel","description":"Parsel lets you extract text from XML/HTML documents using XPath or CSS selectors","fork":false,"url":"https://api.github.com/repos/scrapy/parsel","forks_url":"https://api.github.com/repos/scrapy/parsel/forks","keys_url":"https://api.github.com/repos/scrapy/parsel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scrapy/parsel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scrapy/parsel/teams","hooks_url":"https://api.github.com/repos/scrapy/parsel/hooks","issue_events_url":"https://api.github.com/repos/scrapy/parsel/issues/events{/number}","events_url":"https://api.github.com/repos/scrapy/parsel/events","assignees_url":"https://api.github.com/repos/scrapy/parsel/assignees{/user}","branches_url":"https://api.github.com/repos/scrapy/parsel/branches{/branch}","tags_url":"https://api.github.com/repos/scrapy/parsel/tags","blobs_url":"https://api.github.com/repos/scrapy/parsel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scrapy/parsel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scrapy/parsel/git/refs{/sha}","trees_url":"https://api.github.com/repos/scrapy/parsel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scrapy/parsel/statuses/{sha}","languages_url":"https://api.github.com/repos/scrapy/parsel/languages","stargazers_url":"https://api.github.com/repos/scrapy/parsel/stargazers","contributors_url":"https://api.github.com/repos/scrapy/parsel/contributors","subscribers_url":"https://api.github.com/repos/scrapy/parsel/subscribers","subscription_url":"https://api.github.com/repos/scrapy/parsel/subscription","commits_url":"https://api.github.com/repos/scrapy/parsel/commits{/sha}","git_commits_url":"https://api.github.com/repos/scrapy/parsel/git/commits{/sha}","comments_url":"https://api.github.com/repos/scrapy/parsel/comments{/number}","issue_comment_url":"https://api.github.com/repos/scrapy/parsel/issues/comments{/number}","contents_url":"https://api.github.com/repos/scrapy/parsel/contents/{+path}","compare_url":"https://api.github.com/repos/scrapy/parsel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scrapy/parsel/merges","archive_url":"https://api.github.com/repos/scrapy/parsel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scrapy/parsel/downloads","issues_url":"https://api.github.com/repos/scrapy/parsel/issues{/number}","pulls_url":"https://api.github.com/repos/scrapy/parsel/pulls{/number}","milestones_url":"https://api.github.com/repos/scrapy/parsel/milestones{/number}","notifications_url":"https://api.github.com/repos/scrapy/parsel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scrapy/parsel/labels{/name}","releases_url":"https://api.github.com/repos/scrapy/parsel/releases{/id}","created_at":"2015-04-24T15:53:36Z","updated_at":"2015-07-30T01:01:52Z","pushed_at":"2015-07-29T22:08:14Z","git_url":"git://github.com/scrapy/parsel.git","ssh_url":"git@github.com:scrapy/parsel.git","clone_url":"https://github.com/scrapy/parsel.git","svn_url":"https://github.com/scrapy/parsel","homepage":"","size":332,"stargazers_count":6,"watchers_count":6,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":3,"forks":1,"open_issues":3,"watchers":6,"default_branch":"master"}},"base":{"label":"scrapy:master","ref":"master","sha":"0f2abadf231fcb278ffb23635f1f4420ac36115d","user":{"login":"scrapy","id":733635,"avatar_url":"https://avatars.githubusercontent.com/u/733635?v=3","gravatar_id":"","url":"https://api.github.com/users/scrapy","html_url":"https://github.com/scrapy","followers_url":"https://api.github.com/users/scrapy/followers","following_url":"https://api.github.com/users/scrapy/following{/other_user}","gists_url":"https://api.github.com/users/scrapy/gists{/gist_id}","starred_url":"https://api.github.com/users/scrapy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scrapy/subscriptions","organizations_url":"https://api.github.com/users/scrapy/orgs","repos_url":"https://api.github.com/users/scrapy/repos","events_url":"https://api.github.com/users/scrapy/events{/privacy}","received_events_url":"https://api.github.com/users/scrapy/received_events","type":"Organization","site_admin":false},"repo":{"id":34527721,"name":"parsel","full_name":"scrapy/parsel","owner":{"login":"scrapy","id":733635,"avatar_url":"https://avatars.githubusercontent.com/u/733635?v=3","gravatar_id":"","url":"https://api.github.com/users/scrapy","html_url":"https://github.com/scrapy","followers_url":"https://api.github.com/users/scrapy/followers","following_url":"https://api.github.com/users/scrapy/following{/other_user}","gists_url":"https://api.github.com/users/scrapy/gists{/gist_id}","starred_url":"https://api.github.com/users/scrapy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scrapy/subscriptions","organizations_url":"https://api.github.com/users/scrapy/orgs","repos_url":"https://api.github.com/users/scrapy/repos","events_url":"https://api.github.com/users/scrapy/events{/privacy}","received_events_url":"https://api.github.com/users/scrapy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scrapy/parsel","description":"Parsel lets you extract text from XML/HTML documents using XPath or CSS selectors","fork":false,"url":"https://api.github.com/repos/scrapy/parsel","forks_url":"https://api.github.com/repos/scrapy/parsel/forks","keys_url":"https://api.github.com/repos/scrapy/parsel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scrapy/parsel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scrapy/parsel/teams","hooks_url":"https://api.github.com/repos/scrapy/parsel/hooks","issue_events_url":"https://api.github.com/repos/scrapy/parsel/issues/events{/number}","events_url":"https://api.github.com/repos/scrapy/parsel/events","assignees_url":"https://api.github.com/repos/scrapy/parsel/assignees{/user}","branches_url":"https://api.github.com/repos/scrapy/parsel/branches{/branch}","tags_url":"https://api.github.com/repos/scrapy/parsel/tags","blobs_url":"https://api.github.com/repos/scrapy/parsel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scrapy/parsel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scrapy/parsel/git/refs{/sha}","trees_url":"https://api.github.com/repos/scrapy/parsel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scrapy/parsel/statuses/{sha}","languages_url":"https://api.github.com/repos/scrapy/parsel/languages","stargazers_url":"https://api.github.com/repos/scrapy/parsel/stargazers","contributors_url":"https://api.github.com/repos/scrapy/parsel/contributors","subscribers_url":"https://api.github.com/repos/scrapy/parsel/subscribers","subscription_url":"https://api.github.com/repos/scrapy/parsel/subscription","commits_url":"https://api.github.com/repos/scrapy/parsel/commits{/sha}","git_commits_url":"https://api.github.com/repos/scrapy/parsel/git/commits{/sha}","comments_url":"https://api.github.com/repos/scrapy/parsel/comments{/number}","issue_comment_url":"https://api.github.com/repos/scrapy/parsel/issues/comments{/number}","contents_url":"https://api.github.com/repos/scrapy/parsel/contents/{+path}","compare_url":"https://api.github.com/repos/scrapy/parsel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scrapy/parsel/merges","archive_url":"https://api.github.com/repos/scrapy/parsel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scrapy/parsel/downloads","issues_url":"https://api.github.com/repos/scrapy/parsel/issues{/number}","pulls_url":"https://api.github.com/repos/scrapy/parsel/pulls{/number}","milestones_url":"https://api.github.com/repos/scrapy/parsel/milestones{/number}","notifications_url":"https://api.github.com/repos/scrapy/parsel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scrapy/parsel/labels{/name}","releases_url":"https://api.github.com/repos/scrapy/parsel/releases{/id}","created_at":"2015-04-24T15:53:36Z","updated_at":"2015-07-30T01:01:52Z","pushed_at":"2015-07-29T22:08:14Z","git_url":"git://github.com/scrapy/parsel.git","ssh_url":"git@github.com:scrapy/parsel.git","clone_url":"https://github.com/scrapy/parsel.git","svn_url":"https://github.com/scrapy/parsel","homepage":"","size":332,"stargazers_count":6,"watchers_count":6,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":3,"forks":1,"open_issues":3,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scrapy/parsel/pulls/4"},"html":{"href":"https://github.com/scrapy/parsel/pull/4"},"issue":{"href":"https://api.github.com/repos/scrapy/parsel/issues/4"},"comments":{"href":"https://api.github.com/repos/scrapy/parsel/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/scrapy/parsel/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/scrapy/parsel/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scrapy/parsel/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/scrapy/parsel/statuses/fa446916c83d14600e1653709d4160bbe4a83e37"}}}}