Skip to content

Commit

Permalink
build: Using werkzeug library (#264)
Browse files Browse the repository at this point in the history
* Using werkzeug library

* Updating build templates

* Added a venv

* Fixed indentation

* Changed to editable install

* Installing werkzeug directly

* Updated dependencies based on version

* Adding werkzeug in tests pipelines

* Updated tests pipeline

* Added pyproject.toml

* Updated build files

* Added missing dependency

* Updated verion in pyproject

* Updated http_wsgi

* Fixed http test error

* Minor fixes and refactoring

* Flake8 fixes
  • Loading branch information
gavin-aguiar authored Nov 21, 2024
1 parent 48a5758 commit 39363d8
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 9,120 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
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

0 comments on commit 39363d8

Please sign in to comment.