Skip to content Navigation Menu Toggle navigation Sign in Appearance settings PlatformAI CODE CREATIONGitHub CopilotWrite better code with AIGitHub Copilot appDirect agents from issue to mergeMCP RegistryNewIntegrate external toolsDEVELOPER WORKFLOWSActionsAutomate any workflowCodespacesInstant dev environmentsIssuesPlan and track workCode ReviewManage code changesAPPLICATION SECURITYGitHub Advanced SecurityFind and fix vulnerabilitiesCode securitySecure your code as you buildSecret protectionStop leaks before they startEXPLOREWhy GitHubDocumentationBlogChangelogMarketplaceView all featuresSolutionsBY COMPANY SIZEEnterprisesSmall and medium teamsStartupsNonprofitsBY USE CASEApp ModernizationDevSecOpsDevOpsCI/CDView all use casesBY INDUSTRYHealthcareFinancial servicesManufacturingGovernmentView all industriesView all solutionsResourcesEXPLORE BY TOPICAISoftware DevelopmentDevOpsSecurityView all topicsEXPLORE BY TYPECustomer storiesEvents & webinarsEbooks & reportsBusiness insightsGitHub SkillsSUPPORT & SERVICESDocumentationCustomer supportCommunity forumTrust centerPartnersView all resourcesOpen SourceCOMMUNITYGitHub SponsorsFund open source developersPROGRAMSSecurity LabMaintainer CommunityAcceleratorGitHub StarsArchive ProgramREPOSITORIESTopicsTrendingCollectionsEnterpriseENTERPRISE SOLUTIONSEnterprise platformAI-powered developer platformAVAILABLE ADD-ONSGitHub Advanced SecurityEnterprise-grade security featuresCopilot for BusinessEnterprise-grade AI featuresPremium SupportEnterprise-grade 24/7 supportPricing Search or jump to... Search code, repositories, users, issues, pull requests... Search Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. Include my email address so I can be contacted Saved searches Use saved searches to filter your results more quickly Name Query To see all available qualifiers, see our documentation. Sign in Sign up Appearance settings Resetting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} Uh oh! There was an error while loading. Please reload this page. marshmallow-code / webargs Public Uh oh! There was an error while loading. Please reload this page. Notifications You must be signed in to change notification settings Fork 165 Star 1.4k Code Issues 4 Pull requests 0 Actions Projects Wiki Security and quality 0 Insights Additional navigation options Code Issues Pull requests Actions Projects Wiki Security and quality Insights FilesExpand file tree devBreadcrumbswebargs/src/webargs/bottleparser.pyCopy pathBlameMore file actionsBlameMore file actions Latest commit HistoryHistoryHistory100 lines (77 loc) · 3.17 KB devBreadcrumbswebargs/src/webargs/bottleparser.pyCopy pathTopFile metadata and controlsCodeBlame100 lines (77 loc) · 3.17 KBRawCopy raw fileDownload raw fileOpen symbols panelEdit and raw actions123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100"""Bottle request argument parsing module. Example: :: from bottle import route, run from marshmallow import fields from webargs.bottleparser import use_args hello_args = {"name": fields.Str(load_default="World")} @route("/", method="GET", apply=use_args(hello_args)) def index(args): return "Hello " + args["name"] if __name__ == "__main__": run(debug=True)""" import bottle from webargs import core class BottleParser(core.Parser[bottle.Request]): """Bottle.py request argument parser.""" def _handle_invalid_json_error(self, error, req, *args, **kwargs): raise bottle.HTTPError( status=400, body={"json": ["Invalid JSON body."]}, exception=error ) def _raw_load_json(self, req): """Read a json payload from the request.""" try: data = req.json except AttributeError: return core.missing except bottle.HTTPError as err: if err.body == "Invalid JSON": self._handle_invalid_json_error(err, req) else: raise # unfortunately, bottle does not distinguish between an empty body, "", # and a body containing the valid JSON value null, "null" # so these can't be properly disambiguated # as our best-effort solution, treat None as missing and ignore the # (admittedly unusual) "null" case # see: https://github.com/bottlepy/bottle/issues/1160 if data is None: return core.missing return data def load_querystring(self, req, schema): """Return query params from the request as a MultiDictProxy.""" return self._makeproxy(req.query, schema) def load_form(self, req, schema): """Return form values from the request as a MultiDictProxy.""" # For consistency with other parsers' behavior, don't attempt to # parse if content-type is mismatched. # TODO: Make this check more specific if core.is_json(req.content_type): return core.missing return self._makeproxy(req.forms, schema) def load_headers(self, req, schema): """Return headers from the request as a MultiDictProxy.""" return self._makeproxy(req.headers, schema) def load_cookies(self, req, schema): """Return cookies from the request.""" return req.cookies def load_files(self, req, schema): """Return files from the request as a MultiDictProxy.""" return self._makeproxy(req.files, schema) def handle_error(self, error, req, schema, *, error_status_code, error_headers): """Handles errors during parsing. Aborts the current request with a 400 error. """ status_code = error_status_code or self.DEFAULT_VALIDATION_STATUS raise bottle.HTTPError( status=status_code, body=error.messages, headers=error_headers, exception=error, ) def get_default_request(self): """Override to use bottle's thread-local request object by default.""" return bottle.request parser = BottleParser()use_args = parser.use_argsuse_kwargs = parser.use_kwargs You can’t perform that action at this time.