Skip to content

Instantly share code, notes, and snippets.

@lapshinmr
Created October 7, 2020 10:23
Show Gist options
  • Select an option

  • Save lapshinmr/564d0581bf86f562943b09e9112c2c3b to your computer and use it in GitHub Desktop.

Select an option

Save lapshinmr/564d0581bf86f562943b09e9112c2c3b to your computer and use it in GitHub Desktop.

Revisions

  1. lapshinmr created this gist Oct 7, 2020.
    25 changes: 25 additions & 0 deletions reqparse.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    def validate_argument_dict(dict_arg, dict_expected):
    for key, value in dict_arg.items():
    if key not in dict_expected:
    raise ValueError(f'Wrong key {key}')
    type_expected = type(dict_expected[key])
    if not isinstance(value, type_expected):
    raise ValueError(f'Wrong value type for the {key}. {type_expected} is expected.')
    return dict_arg

    PD_EXPECTED = {
    'passport_last_name': '',
    'passport_first_name': '',
    'passport_middle_name': '',
    'passport_number': '',
    'passport_issue_date': '', # YYYY-MM-DD
    'passport_birth_date': '', # YYYY-MM-DD
    'passport_tin_number': '',
    'country_code': '',
    'phone': '',
    'email': '',
    }

    pd = partial(validate_argument_dict, dict_expected=self.PD_EXPECTED)
    parser = reqparse.RequestParser()
    parser.add_argument('passport_last_name', required=True, type=pd, default=dict())