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

build: Using werkzeug library #264

Merged
merged 17 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion azure/functions/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import threading
import typing

from azure.functions._thirdparty.werkzeug.datastructures import Headers
from werkzeug.datastructures import Headers

T = typing.TypeVar('T')

Expand Down
22 changes: 10 additions & 12 deletions azure/functions/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import types
import typing

from werkzeug import formparser as _wk_parser
from werkzeug import http as _wk_http
from werkzeug.datastructures import (Headers, FileStorage, MultiDict,
ImmutableMultiDict)

from . import _abc
from ._thirdparty.werkzeug import datastructures as _wk_datastructures
from ._thirdparty.werkzeug import formparser as _wk_parser
from ._thirdparty.werkzeug import http as _wk_http
from ._thirdparty.werkzeug.datastructures import Headers


class BaseHeaders(collections.abc.Mapping):
Expand Down Expand Up @@ -174,8 +175,8 @@ def __init__(self,
self.__route_params = types.MappingProxyType(route_params or {})
self.__body_bytes = body
self.__form_parsed = False
self.__form = None
self.__files = None
self.__form: MultiDict[str, str]
self.__files: MultiDict[str, FileStorage]

@property
def url(self):
Expand Down Expand Up @@ -222,12 +223,9 @@ def _parse_form_data(self):
content_length = len(body)
mimetype, options = _wk_http.parse_options_header(content_type)
parser = _wk_parser.FormDataParser(
_wk_parser.default_stream_factory,
options.get('charset') or 'utf-8',
'replace',
None,
None,
_wk_datastructures.ImmutableMultiDict,
_wk_parser.default_stream_factory, max_form_memory_size=None,
max_content_length=None,
cls=ImmutableMultiDict
)

body_stream = io.BytesIO(body)
Expand Down
9 changes: 6 additions & 3 deletions azure/functions/_http_wsgi.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from typing import Dict, List, Optional, Any
import logging
from io import BytesIO, StringIO
from os import linesep
from typing import Dict, List, Optional, Any
from urllib.parse import ParseResult, urlparse, unquote_to_bytes
from wsgiref.headers import Headers

from ._abc import Context
from ._http import HttpRequest, HttpResponse
from ._thirdparty.werkzeug._compat import string_types, wsgi_encoding_dance


def wsgi_encoding_dance(value):
return value.encode().decode("latin1")


class WsgiRequest:
Expand Down Expand Up @@ -98,7 +101,7 @@ def to_environ(self, errors_buffer: StringIO) -> Dict[str, Any]:

# Ensure WSGI string fits in IOS-8859-1 code points
for k, v in environ.items():
if isinstance(v, string_types):
if isinstance(v, (str,)):
environ[k] = wsgi_encoding_dance(v)

# Remove None values
Expand Down
28 changes: 0 additions & 28 deletions azure/functions/_thirdparty/werkzeug/LICENSE.rst

This file was deleted.

Empty file.
219 changes: 0 additions & 219 deletions azure/functions/_thirdparty/werkzeug/_compat.py

This file was deleted.

Loading
Loading