Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web.HTTP: Python3 and 2 support(3 as high priority) #703

Merged
merged 3 commits into from
Apr 28, 2020

Conversation

tsuyoshicho
Copy link
Contributor

Python3でのclientを実装しました。

(ただ、Pythonに詳しくないので、自信があまりありません orz)

動作自体は確認できているのですが...

テスト用コード片

let HTTP = g:V.import('Web.HTTP')

let url = 'https://www.google.com'
let res = HTTP.request('GET', url, {
          \ 'client'      : ['curl'],
          \})
echo res
let HTTP = g:V.import('Web.HTTP')

let url = 'https://www.google.com'
let res = HTTP.request('GET', url, {
          \ 'client'      : ['wget'],
          \})
echo res
let HTTP = g:V.import('Web.HTTP')

let url = 'https://www.google.com'
let res = HTTP.request('GET', url, {
          \ 'client'      : ['python'],
          \})
echo res
let HTTP = g:V.import('Web.HTTP')

let url = 'https://www.google.com'
let res = HTTP.request('GET', url, {
          \ 'client'      : ['python2'],
          \})
echo res
let HTTP = g:V.import('Web.HTTP')

let url = 'https://www.google.com'
let res = HTTP.request('GET', url, {
          \ 'client'      : ['python3'],
          \})
echo res
import urllib.request

class CustomHTTPRedirectHandler(urllib.request.HTTPRedirectHandler):
    def __init__(self, max_redirect):
        self.max_redirect = max_redirect

    def redirect_request(self, req, fp, code, msg, headers, newurl):
        if self.max_redirect == 0:
            return None
        if 0 < self.max_redirect:
            self.max_redirect -= 1
        header_list = filter(None, str(headers).split("\r\n"))
        responses.extend([[[status(code, msg)] + header_list, fp.read()]])
        return urllib.request.HTTPRedirectHandler.redirect_request(self, req, fp, code, msg, headers, newurl)

director = urllib.request.build_opener(CustomHTTPRedirectHandler(1))

req = urllib.request.Request('https://www.google.com')

res = director.open(req)

print(res)
print(vars(res))

各クライアント動作、pythonの内部動作とレスポンスのオブジェクトの確認のものです。

@tsuyoshicho
Copy link
Contributor Author

tsuyoshicho commented Dec 22, 2019

(レビューワーは一旦は設定しましたが、妥当かなど不明なので、あまり気にせず見れるときに見ていただければ、と思います)

@tsuyoshicho
Copy link
Contributor Author

rel #702

Copy link
Member

@ujihisa ujihisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, thanks a lot! Eventually we can drop the python2 support, but yes let's first add python3 and keep both for a while.

@ujihisa
Copy link
Member

ujihisa commented Jan 18, 2020

@thinca @mattn ping

@tsuyoshicho
Copy link
Contributor Author

This point is working blocker to y0za/vim-reading-vimrc
(default work python2, but in some env Python2 has recently been uninstalled)

Copy link
Member

@thinca thinca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ざっとしか見れてないですが…。
見るの遅くなってすいません 🙇

@tsuyoshicho
Copy link
Contributor Author

いえ、ありがとうございます。

@tsuyoshicho
Copy link
Contributor Author

tsuyoshicho commented Apr 26, 2020

@mattn さん、お二方からapprove頂けたので、特に指摘がなければこのコメントの1日後(2020/04/28 18:00 (JST))にマージするつもりです。

また、マージ後Changesの更新も行います。
(遅れすぎるのはアレかな、というのと作りで改善点(不備でない)であればマージ後に別にやる手はあるかな、と思っています)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants