{"action":"created","comment":{"url":"https://api.github.com/repos/bsc-s2/pykit/pulls/comments/234098691","pull_request_review_id":175668062,"id":234098691,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNDA5ODY5MQ==","diff_hunk":"@@ -25,6 +28,99 @@ def query_by_jinja2(conn_argkw, jinja2_argkw):\n         raise TypeError('expected MysqlConnectionPool, MySQLdb.Connection '\n                         'or an address(dict) but got {t}'.format(t=conn_argkw))\n \n+    return func, call_argkw\n+\n+\n+def validate_privileges(privs):\n+    if isinstance(privs, basestring):\n+        privs = privs.split(',')\n+\n+    all_privs = privilege.privileges\n+    rst = []\n+\n+    for p in privs:\n+        p = p.strip()\n+        assert p in all_privs, 'invalid privileges: {p} not in {ps}'.format(p=p, ps=all_privs)\n+\n+        rst.append(','.join(all_privs[p]))\n+\n+    return rst\n+\n+\n+def _normalize_priv(priv):\n+    if isinstance(priv, basestring):\n+        g = re.match('(.*)\\.(.*):(.*)', priv)\n+        if g is None or len(g.groups()) != 3:\n+            raise ValueError('invalid privileges: expected format <db>.<table>:priv, '\n+                             'but got: {p}'.format(p=priv))\n+\n+        yield {\n+            'db': g.groups()[0],\n+            'tb': g.groups()[1],\n+            'pri': ','.join(validate_privileges(g.groups()[2])),\n+        }\n+\n+    elif isinstance(priv, dict):\n+        for k, v in priv.items():\n+            if isinstance(k, basestring):\n+                db, table = k.split('.')\n+\n+            else:\n+                db, table = k\n+\n+            yield {\n+                'db': db,\n+                'tb': table,\n+                'pri': ','.join(validate_privileges(v)),\n+            }\n+\n+    else:\n+        raise ValueError('invalid privileges: expected str or dict, but got: {t}'.format(t=type(priv)))\n+\n+\n+def _normalize_users(users):\n+    rst = []\n+    for user in users:\n+        username = user.get('name') or ''\n+        host = user.get('host') or '%'\n+        pwd = user.get('password')\n+        state = user.get('state') or 'present'","path":"mysqlutil/mysql.py","position":79,"original_position":79,"commit_id":"7ed5740eb97dae02cfdc207254b153e820cf8424","original_commit_id":"7ed5740eb97dae02cfdc207254b153e820cf8424","user":{"login":"liubaohai","id":26271283,"node_id":"MDQ6VXNlcjI2MjcxMjgz","avatar_url":"https://avatars2.githubusercontent.com/u/26271283?v=4","gravatar_id":"","url":"https://api.github.com/users/liubaohai","html_url":"https://github.com/liubaohai","followers_url":"https://api.github.com/users/liubaohai/followers","following_url":"https://api.github.com/users/liubaohai/following{/other_user}","gists_url":"https://api.github.com/users/liubaohai/gists{/gist_id}","starred_url":"https://api.github.com/users/liubaohai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liubaohai/subscriptions","organizations_url":"https://api.github.com/users/liubaohai/orgs","repos_url":"https://api.github.com/users/liubaohai/repos","events_url":"https://api.github.com/users/liubaohai/events{/privacy}","received_events_url":"https://api.github.com/users/liubaohai/received_events","type":"User","site_admin":false},"body":"这里是想着处理None的情况。你建议呢，这种情况还处理吗？","created_at":"2018-11-16T06:08:59Z","updated_at":"2018-11-16T06:08:59Z","html_url":"https://github.com/bsc-s2/pykit/pull/437#discussion_r234098691","pull_request_url":"https://api.github.com/repos/bsc-s2/pykit/pulls/437","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/bsc-s2/pykit/pulls/comments/234098691"},"html":{"href":"https://github.com/bsc-s2/pykit/pull/437#discussion_r234098691"},"pull_request":{"href":"https://api.github.com/repos/bsc-s2/pykit/pulls/437"}},"in_reply_to_id":234095318},"pull_request":{"url":"https://api.github.com/repos/bsc-s2/pykit/pulls/437","id":231408352,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMxNDA4MzUy","html_url":"https://github.com/bsc-s2/pykit/pull/437","diff_url":"https://github.com/bsc-s2/pykit/pull/437.diff","patch_url":"https://github.com/bsc-s2/pykit/pull/437.patch","issue_url":"https://api.github.com/repos/bsc-s2/pykit/issues/437","number":437,"state":"open","locked":false,"title":"add setup_user function","user":{"login":"liubaohai","id":26271283,"node_id":"MDQ6VXNlcjI2MjcxMjgz","avatar_url":"https://avatars2.githubusercontent.com/u/26271283?v=4","gravatar_id":"","url":"https://api.github.com/users/liubaohai","html_url":"https://github.com/liubaohai","followers_url":"https://api.github.com/users/liubaohai/followers","following_url":"https://api.github.com/users/liubaohai/following{/other_user}","gists_url":"https://api.github.com/users/liubaohai/gists{/gist_id}","starred_url":"https://api.github.com/users/liubaohai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liubaohai/subscriptions","organizations_url":"https://api.github.com/users/liubaohai/orgs","repos_url":"https://api.github.com/users/liubaohai/repos","events_url":"https://api.github.com/users/liubaohai/events{/privacy}","received_events_url":"https://api.github.com/users/liubaohai/received_events","type":"User","site_admin":false},"body":"### (做了啥)\r\n\r\n- 实现mysqlutil setup_user功能\r\n\r\n### (实现意图)\r\n\r\n\r\nFix: #424 \r\n","created_at":"2018-11-16T03:55:09Z","updated_at":"2018-11-16T06:08:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a5c158ab16aac5b8663cfec263fe3512f0ee4575","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/bsc-s2/pykit/pulls/437/commits","review_comments_url":"https://api.github.com/repos/bsc-s2/pykit/pulls/437/comments","review_comment_url":"https://api.github.com/repos/bsc-s2/pykit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bsc-s2/pykit/issues/437/comments","statuses_url":"https://api.github.com/repos/bsc-s2/pykit/statuses/7ed5740eb97dae02cfdc207254b153e820cf8424","head":{"label":"bsc-s2:lbh.mysql","ref":"lbh.mysql","sha":"7ed5740eb97dae02cfdc207254b153e820cf8424","user":{"login":"bsc-s2","id":36946445,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2OTQ2NDQ1","avatar_url":"https://avatars3.githubusercontent.com/u/36946445?v=4","gravatar_id":"","url":"https://api.github.com/users/bsc-s2","html_url":"https://github.com/bsc-s2","followers_url":"https://api.github.com/users/bsc-s2/followers","following_url":"https://api.github.com/users/bsc-s2/following{/other_user}","gists_url":"https://api.github.com/users/bsc-s2/gists{/gist_id}","starred_url":"https://api.github.com/users/bsc-s2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bsc-s2/subscriptions","organizations_url":"https://api.github.com/users/bsc-s2/orgs","repos_url":"https://api.github.com/users/bsc-s2/repos","events_url":"https://api.github.com/users/bsc-s2/events{/privacy}","received_events_url":"https://api.github.com/users/bsc-s2/received_events","type":"Organization","site_admin":false},"repo":{"id":75464992,"node_id":"MDEwOlJlcG9zaXRvcnk3NTQ2NDk5Mg==","name":"pykit","full_name":"bsc-s2/pykit","private":false,"owner":{"login":"bsc-s2","id":36946445,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2OTQ2NDQ1","avatar_url":"https://avatars3.githubusercontent.com/u/36946445?v=4","gravatar_id":"","url":"https://api.github.com/users/bsc-s2","html_url":"https://github.com/bsc-s2","followers_url":"https://api.github.com/users/bsc-s2/followers","following_url":"https://api.github.com/users/bsc-s2/following{/other_user}","gists_url":"https://api.github.com/users/bsc-s2/gists{/gist_id}","starred_url":"https://api.github.com/users/bsc-s2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bsc-s2/subscriptions","organizations_url":"https://api.github.com/users/bsc-s2/orgs","repos_url":"https://api.github.com/users/bsc-s2/repos","events_url":"https://api.github.com/users/bsc-s2/events{/privacy}","received_events_url":"https://api.github.com/users/bsc-s2/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/bsc-s2/pykit","description":"a collection of toolkit lib for distributed system development in python","fork":false,"url":"https://api.github.com/repos/bsc-s2/pykit","forks_url":"https://api.github.com/repos/bsc-s2/pykit/forks","keys_url":"https://api.github.com/repos/bsc-s2/pykit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bsc-s2/pykit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bsc-s2/pykit/teams","hooks_url":"https://api.github.com/repos/bsc-s2/pykit/hooks","issue_events_url":"https://api.github.com/repos/bsc-s2/pykit/issues/events{/number}","events_url":"https://api.github.com/repos/bsc-s2/pykit/events","assignees_url":"https://api.github.com/repos/bsc-s2/pykit/assignees{/user}","branches_url":"https://api.github.com/repos/bsc-s2/pykit/branches{/branch}","tags_url":"https://api.github.com/repos/bsc-s2/pykit/tags","blobs_url":"https://api.github.com/repos/bsc-s2/pykit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bsc-s2/pykit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bsc-s2/pykit/git/refs{/sha}","trees_url":"https://api.github.com/repos/bsc-s2/pykit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bsc-s2/pykit/statuses/{sha}","languages_url":"https://api.github.com/repos/bsc-s2/pykit/languages","stargazers_url":"https://api.github.com/repos/bsc-s2/pykit/stargazers","contributors_url":"https://api.github.com/repos/bsc-s2/pykit/contributors","subscribers_url":"https://api.github.com/repos/bsc-s2/pykit/subscribers","subscription_url":"https://api.github.com/repos/bsc-s2/pykit/subscription","commits_url":"https://api.github.com/repos/bsc-s2/pykit/commits{/sha}","git_commits_url":"https://api.github.com/repos/bsc-s2/pykit/git/commits{/sha}","comments_url":"https://api.github.com/repos/bsc-s2/pykit/comments{/number}","issue_comment_url":"https://api.github.com/repos/bsc-s2/pykit/issues/comments{/number}","contents_url":"https://api.github.com/repos/bsc-s2/pykit/contents/{+path}","compare_url":"https://api.github.com/repos/bsc-s2/pykit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bsc-s2/pykit/merges","archive_url":"https://api.github.com/repos/bsc-s2/pykit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bsc-s2/pykit/downloads","issues_url":"https://api.github.com/repos/bsc-s2/pykit/issues{/number}","pulls_url":"https://api.github.com/repos/bsc-s2/pykit/pulls{/number}","milestones_url":"https://api.github.com/repos/bsc-s2/pykit/milestones{/number}","notifications_url":"https://api.github.com/repos/bsc-s2/pykit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bsc-s2/pykit/labels{/name}","releases_url":"https://api.github.com/repos/bsc-s2/pykit/releases{/id}","deployments_url":"https://api.github.com/repos/bsc-s2/pykit/deployments","created_at":"2016-12-03T09:38:38Z","updated_at":"2018-11-14T08:44:21Z","pushed_at":"2018-11-16T03:55:10Z","git_url":"git://github.com/bsc-s2/pykit.git","ssh_url":"git@github.com:bsc-s2/pykit.git","clone_url":"https://github.com/bsc-s2/pykit.git","svn_url":"https://github.com/bsc-s2/pykit","homepage":null,"size":3826,"stargazers_count":16,"watchers_count":16,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"archived":false,"open_issues_count":8,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":7,"open_issues":8,"watchers":16,"default_branch":"master"}},"base":{"label":"bsc-s2:master","ref":"master","sha":"9046be0f73e351d5dcba6b758c8102e85d980c77","user":{"login":"bsc-s2","id":36946445,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2OTQ2NDQ1","avatar_url":"https://avatars3.githubusercontent.com/u/36946445?v=4","gravatar_id":"","url":"https://api.github.com/users/bsc-s2","html_url":"https://github.com/bsc-s2","followers_url":"https://api.github.com/users/bsc-s2/followers","following_url":"https://api.github.com/users/bsc-s2/following{/other_user}","gists_url":"https://api.github.com/users/bsc-s2/gists{/gist_id}","starred_url":"https://api.github.com/users/bsc-s2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bsc-s2/subscriptions","organizations_url":"https://api.github.com/users/bsc-s2/orgs","repos_url":"https://api.github.com/users/bsc-s2/repos","events_url":"https://api.github.com/users/bsc-s2/events{/privacy}","received_events_url":"https://api.github.com/users/bsc-s2/received_events","type":"Organization","site_admin":false},"repo":{"id":75464992,"node_id":"MDEwOlJlcG9zaXRvcnk3NTQ2NDk5Mg==","name":"pykit","full_name":"bsc-s2/pykit","private":false,"owner":{"login":"bsc-s2","id":36946445,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2OTQ2NDQ1","avatar_url":"https://avatars3.githubusercontent.com/u/36946445?v=4","gravatar_id":"","url":"https://api.github.com/users/bsc-s2","html_url":"https://github.com/bsc-s2","followers_url":"https://api.github.com/users/bsc-s2/followers","following_url":"https://api.github.com/users/bsc-s2/following{/other_user}","gists_url":"https://api.github.com/users/bsc-s2/gists{/gist_id}","starred_url":"https://api.github.com/users/bsc-s2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bsc-s2/subscriptions","organizations_url":"https://api.github.com/users/bsc-s2/orgs","repos_url":"https://api.github.com/users/bsc-s2/repos","events_url":"https://api.github.com/users/bsc-s2/events{/privacy}","received_events_url":"https://api.github.com/users/bsc-s2/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/bsc-s2/pykit","description":"a collection of toolkit lib for distributed system development in python","fork":false,"url":"https://api.github.com/repos/bsc-s2/pykit","forks_url":"https://api.github.com/repos/bsc-s2/pykit/forks","keys_url":"https://api.github.com/repos/bsc-s2/pykit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bsc-s2/pykit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bsc-s2/pykit/teams","hooks_url":"https://api.github.com/repos/bsc-s2/pykit/hooks","issue_events_url":"https://api.github.com/repos/bsc-s2/pykit/issues/events{/number}","events_url":"https://api.github.com/repos/bsc-s2/pykit/events","assignees_url":"https://api.github.com/repos/bsc-s2/pykit/assignees{/user}","branches_url":"https://api.github.com/repos/bsc-s2/pykit/branches{/branch}","tags_url":"https://api.github.com/repos/bsc-s2/pykit/tags","blobs_url":"https://api.github.com/repos/bsc-s2/pykit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bsc-s2/pykit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bsc-s2/pykit/git/refs{/sha}","trees_url":"https://api.github.com/repos/bsc-s2/pykit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bsc-s2/pykit/statuses/{sha}","languages_url":"https://api.github.com/repos/bsc-s2/pykit/languages","stargazers_url":"https://api.github.com/repos/bsc-s2/pykit/stargazers","contributors_url":"https://api.github.com/repos/bsc-s2/pykit/contributors","subscribers_url":"https://api.github.com/repos/bsc-s2/pykit/subscribers","subscription_url":"https://api.github.com/repos/bsc-s2/pykit/subscription","commits_url":"https://api.github.com/repos/bsc-s2/pykit/commits{/sha}","git_commits_url":"https://api.github.com/repos/bsc-s2/pykit/git/commits{/sha}","comments_url":"https://api.github.com/repos/bsc-s2/pykit/comments{/number}","issue_comment_url":"https://api.github.com/repos/bsc-s2/pykit/issues/comments{/number}","contents_url":"https://api.github.com/repos/bsc-s2/pykit/contents/{+path}","compare_url":"https://api.github.com/repos/bsc-s2/pykit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bsc-s2/pykit/merges","archive_url":"https://api.github.com/repos/bsc-s2/pykit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bsc-s2/pykit/downloads","issues_url":"https://api.github.com/repos/bsc-s2/pykit/issues{/number}","pulls_url":"https://api.github.com/repos/bsc-s2/pykit/pulls{/number}","milestones_url":"https://api.github.com/repos/bsc-s2/pykit/milestones{/number}","notifications_url":"https://api.github.com/repos/bsc-s2/pykit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bsc-s2/pykit/labels{/name}","releases_url":"https://api.github.com/repos/bsc-s2/pykit/releases{/id}","deployments_url":"https://api.github.com/repos/bsc-s2/pykit/deployments","created_at":"2016-12-03T09:38:38Z","updated_at":"2018-11-14T08:44:21Z","pushed_at":"2018-11-16T03:55:10Z","git_url":"git://github.com/bsc-s2/pykit.git","ssh_url":"git@github.com:bsc-s2/pykit.git","clone_url":"https://github.com/bsc-s2/pykit.git","svn_url":"https://github.com/bsc-s2/pykit","homepage":null,"size":3826,"stargazers_count":16,"watchers_count":16,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"archived":false,"open_issues_count":8,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":7,"open_issues":8,"watchers":16,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bsc-s2/pykit/pulls/437"},"html":{"href":"https://github.com/bsc-s2/pykit/pull/437"},"issue":{"href":"https://api.github.com/repos/bsc-s2/pykit/issues/437"},"comments":{"href":"https://api.github.com/repos/bsc-s2/pykit/issues/437/comments"},"review_comments":{"href":"https://api.github.com/repos/bsc-s2/pykit/pulls/437/comments"},"review_comment":{"href":"https://api.github.com/repos/bsc-s2/pykit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bsc-s2/pykit/pulls/437/commits"},"statuses":{"href":"https://api.github.com/repos/bsc-s2/pykit/statuses/7ed5740eb97dae02cfdc207254b153e820cf8424"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"liubaohai"}}