Skip to content

Commit

Permalink
Using werkzeug library
Browse files Browse the repository at this point in the history
  • Loading branch information
gavin-aguiar committed Nov 15, 2024
1 parent 48a5758 commit da5a649
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 9,049 deletions.
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
30 changes: 17 additions & 13 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 multidict._multidict import MultiDict
from werkzeug import formparser as _wk_parser
from werkzeug import http as _wk_http
from werkzeug.datastructures import Headers, FileStorage

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] = None
self.__files:MultiDict[str, FileStorage] = None

@property
def url(self):
Expand Down Expand Up @@ -216,18 +217,21 @@ def get_json(self) -> typing.Any:
def _parse_form_data(self):
if self.__form_parsed:
return

"""
stream_factory: TStreamFactory | None = None,
max_form_memory_size: int | None = None,
max_content_length: int | None = None,
cls: type[MultiDict[str, t.Any]] | None = None,
silent: bool = True,
*,
max_form_parts: int | None = None,
"""
body = self.get_body()
content_type = self.headers.get('Content-Type', '')
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
)

body_stream = io.BytesIO(body)
Expand Down
9 changes: 7 additions & 2 deletions azure/functions/_http_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

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


def wsgi_encoding_dance(value):
if isinstance(value, str):
return value.encode("latin-1")
return value


class WsgiRequest:
Expand Down Expand Up @@ -98,7 +103,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

0 comments on commit da5a649

Please sign in to comment.