LibreOffice plugin to pipe whole Writer documents through Google Translate, that ought to keep most of the page formatting.

⌈⌋ ⎇ branch:  PageTranslate


Check-in [72453b0947]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:faux: move params= to .get
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 72453b0947b2dafce9b9ae17fc165c6e461f705d
User & Date: mario 2022-10-23 05:51:10
Context
2022-10-23
05:51
rough privacy judgement check-in: ad382edca0 user: mario tags: trunk
05:51
faux: move params= to .get check-in: 72453b0947 user: mario tags: trunk
2022-10-22
22:17
compact via fixture check-in: 00e5bb6299 user: mario tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to pythonpath/httprequests.py.

1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
# encoding: utf-8
# api: python
##type: classes
# category: http
# title: request/fallback
# description: loads requests, or similuates API via urllib
# version: 0.7
# state: beta

# depends: python:requests (>= 2.5)
# config: -
# pylint: disable=invalid-name, missing-function-docstring, missing-module-docstring
#
# Wraps requests or fakes a http.get() implementation.
#









>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# encoding: utf-8
# api: python
##type: classes
# category: http
# title: request/fallback
# description: loads requests, or similuates API via urllib
# version: 0.7
# state: beta
# license: CC-0
# depends: python:requests (>= 2.5)
# config: -
# pylint: disable=invalid-name, missing-function-docstring, missing-module-docstring
#
# Wraps requests or fakes a http.get() implementation.
#

67
68
69
70
71
72
73
74
75
76
77
78


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
        if not hasattr(ssl, "create_default_context"):
            return
        context = ssl.create_default_context()
        context.check_hostname = False
        context.verify_mode = ssl.CERT_NONE
        self.ssl_args["context"] = context

    def get(self, url, **kwargs):
        """ urlopen """
        kwargs["headers"] = dict(
            list(self.headers.items()) + list(kwargs.get("headers", {}).items())
        )


        return FauxResponse(
            urlopen(
                Request(url, **kwargs), **self.ssl_args
            )
        )

    def post(self, url, data=None, params=None, json=None, **kwargs):
        """ POST just adds data= """
        if json:
            data = dumps(json).encode("utf-8")
        if params:
            data = urlencode(params).encode("utf-8")
        return self.get(url, data=data, **kwargs)


try:
    import requests
    http = requests.Session()
except ImportError:







|




>
>






|



|
|







68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
        if not hasattr(ssl, "create_default_context"):
            return
        context = ssl.create_default_context()
        context.check_hostname = False
        context.verify_mode = ssl.CERT_NONE
        self.ssl_args["context"] = context

    def get(self, url, params={}, **kwargs):
        """ urlopen """
        kwargs["headers"] = dict(
            list(self.headers.items()) + list(kwargs.get("headers", {}).items())
        )
        if params:
            url = url + "?&"[url.find("?")>0] + urlencode(params)
        return FauxResponse(
            urlopen(
                Request(url, **kwargs), **self.ssl_args
            )
        )

    def post(self, url, data=None, json=None, **kwargs):
        """ POST just adds data= """
        if json:
            data = dumps(json).encode("utf-8")
        elif data and isinstance(data, dict):
            data = urlencode(data).encode("utf-8")
        return self.get(url, data=data, **kwargs)


try:
    import requests
    http = requests.Session()
except ImportError:

Changes to test/httpfaux.py.

1
2
3
4
5
6
7
8
9
10
11
12




13
14
15
16
17
18
19
import pytest
from httprequests import FauxRequests

@pytest.fixture(scope="module")
def http():
    return FauxRequests()

def get(http):
    resp = http.get("https://example.org/")
    assert resp.status_code == 200
    assert resp.headers





def post(http):
    resp = http.post("https://httpbin.org/post", params={"a":"b", "c":"d"})
    assert resp.json()["form"]["a"] == "b"

def json(http):
    resp = http.get("https://httpbin.org/json")
    assert resp.json()












>
>
>
>

|





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pytest
from httprequests import FauxRequests

@pytest.fixture(scope="module")
def http():
    return FauxRequests()

def get(http):
    resp = http.get("https://example.org/")
    assert resp.status_code == 200
    assert resp.headers

def params(http):
    resp = http.get("https://httpbin.org/get", params={"key":"val"})
    assert resp.json()["args"]["key"] == "val"

def post(http):
    resp = http.post("https://httpbin.org/post", data={"a":"b", "c":"d"})
    assert resp.json()["form"]["a"] == "b"

def json(http):
    resp = http.get("https://httpbin.org/json")
    assert resp.json()