8000 quora-python/forms.py at master · renxing/quora-python · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
< 74D2 script type="application/json" data-target="react-app.embeddedData">{"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":"migrations","path":"migrations","contentType":"directory"},{"name":"static","path":"static","contentType":"directory"},{"name":"templates","path":"templates","contentType":"directory"},{"name":".gitignore","path":".gitignore","contentType":"file"},{"name":"INSTALL","path":"INSTALL","contentType":"file"},{"name":"README.textile","path":"README.textile","contentType":"file"},{"name":"app.py","path":"app.py","contentType":"file"},{"name":"filter.py","path":"filter.py","contentType":"file"},{"name":"forms.py","path":"forms.py","contentType":"file"},{"name":"handlers.py","path":"handlers.py","contentType":"file"},{"name":"markdown.py","path":"markdown.py","contentType":"file"},{"name":"models.py","path":"models.py","contentType":"file"},{"name":"run_app","path":"run_app","contentType":"file"},{"name":"session.py","path":"session.py","contentType":"file"},{"name":"utils.py","path":"utils.py","contentType":"file"}],"totalCount":15}},"fileTreeProcessingTime":11.499874,"foldersToFetch":[],"incompleteFileTree":false,"repo":{"id":2089434,"defaultBranch":"master","name":"quora-python","ownerLogin":"renxing","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2011-07-22T16:07:08.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/8431?v=4","public":true,"private":false,"isOrgOwned":false},"codeLineWrapEnabled":false,"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"master","listCacheKey":"v0:1613671658.3022668","canEdit":false,"refType":"branch","currentOid":"e1fc1fef717150e0e99fbbc3bb8ed487b44ef902"},"path":"forms.py","currentUser":null,"blob":{"rawLines":["# coding: utf-8","import re","import logging ","import urlparse","import formencode","from formencode import htmlfill, validators","","","class BaseForm(formencode.Schema):"," \"\"\""," by Felinx Lee "," https://bitbucket.org/felinx/poweredsites/src/8448db5ba387/poweredsites/forms/base.py"," \"\"\""," allow_extra_fields = True"," filter_extra_fields = True",""," _xsrf = validators.PlainText(not_empty=True, max=32)",""," def __init__(self, handler, form_id = None):",""," self._parmas = {}"," self._values = {}"," self._form_errors = {}"," self.form_id = form_id"," arguments = {}",""," # re-parse qs, keep_blankvalues for formencode to validate"," # so formencode not_empty setting work."," request = handler.request"," content_type = request.headers.get(\"Content-Type\", \"\")",""," if request.method == \"POST\":"," if content_type.startswith(\"application/x-www-form-urlencoded\"):"," arguments = urlparse.parse_qs(request.body, keep_blank_values=1)",""," for k, v in arguments.iteritems():"," if len(v) == 1:"," self._parmas[k] = v[0]"," else:"," # keep a list of values as list (or set)"," self._parmas[k] = v",""," self._handler = handler"," self._result = True",""," def validate(self):"," try:"," self._values = self.to_python(self._parmas)"," self._result = True"," self.__after__()"," except formencode.Invalid, error:"," self._values = error.value"," self._form_errors = error.error_dict or {}"," self._result = False",""," # map values to define form propertys and decode utf8"," for k in self._values.keys():"," exec(\"self.%s = self._values[\\\"%s\\\"].decode('utf8')\" % (k,k)) ",""," return self._result",""," # add custom error msg"," def add_error(self, attr, msg):"," self._result = False"," self._form_errors[attr] = msg",""," def render(self, template_name, **kwargs):"," html = self._handler.render_string(template_name, **kwargs)",""," if not self._result:"," html = htmlfill.render(html,"," defaults=self._values,"," errors=self._form_errors,"," encoding=\"utf8\")",""," self._handler.finish(html)",""," # post process hook"," def __after__(self):"," pass","","","","","","class LoginForm(BaseForm):"," login = validators.String(not_empty=True,strip=True)"," password = validators.String(not_empty=True)","","class RegisterForm(BaseForm):"," login = validators.String(not_empty=True,strip=True,min=4,max=20)"," email = validators.Email(not_empty=True,strip=True)"," name = validators.String(not_empty=True,strip=True)"," password = validators.String(not_empty=True)"," password_confirm = validators.String(not_empty=True)"," chained_validators = [validators.FieldsMatch('password', 'password_confirm')]","","class SettingsForm(BaseForm):"," email = validators.Email(not_empty=True,strip=True)"," name = validators.String(not_empty=True,strip=True)"," blog = validators.URL(not_empty=True,strip=True)"," bio = validators.String(not_empty=True,max=300)"," ","class AskForm(BaseForm):"," title = validators.String(not_empty=True,min=5,max=255,strip=True)"," body = validators.String()"," tags = validators.String(strip=True)","","class AnswerForm(BaseForm):"," answer_body = validators.String(not_empty=True,min=2,strip=True)"],"stylingDirectives":null,"colorizedLines":null,"csv":null,"csvError":null,"dependabotInfo":{"showConfigurationBanner":false,"configFilePath":null,"networkDependabotPath":"/renxing/quora-python/network/updates","dismissConfigurationNoticePath":"/settings/dismiss-notice/dependabot_configuration_notice","configurationNoticeDismissed":null},"displayName":"forms.py","displayUrl":"https://github.com/renxing/quora-python/blob/master/forms.py?raw=true","headerInfo":{"blobSize":"3.38 KB","deleteTooltip":"You must be signed in to make or propose changes","editTooltip":"You must be signed in to make or propose changes","ghDesktopPath":"https://desktop.github.com","isGitLfs":false,"onBranch":true,"shortPath":"396b6ed","siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2Frenxing%2Fquora-python%2Fblob%2Fmaster%2Fforms.py","isCSV":false,"isRichtext":false,"toc":null,"lineInfo":{"truncatedLoc":"112","truncatedSloc":"84"},"mode":"file"},"image":false,"isCodeownersFile":null,"isPlain":false,"isValidLegacyIssueTemplate":false,"issueTemplate":null,"discussionTemplate":null,"language":"Python","languageID":303,"large":false,"planSupportInfo":{"repoIsFork":null,"repoOwnedByCurrentUser":null,"requestFullPath":"/renxing/quora-python/blob/master/forms.py","showFreeOrgGatedFeatureMessage":null,"showPlanSupportBanner":null,"upgradeDataAttributes":null,"upgradePath":null},"publishBannersInfo":{"dismissActionNoticePath":"/settings/dismiss-notice/publish_action_from_dockerfile","releasePath":"/renxing/quora-python/releases/new?marketplace=true","showPublishActionBanner":false},"rawBlobUrl":"https://github.com/renxing/quora-python/raw/refs/heads/master/forms.py","renderImageOrRaw":false,"richText":null,"renderedFileInfo":null,"shortPath":null,"symbolsEnabled":true,"tabSize":8,"topBannersInfo":{"overridingGlobalFundingFile":false,"globalPreferredFundingPath":null,"showInvalidCitationWarning":false,"citationHelpUrl":"https://docs.github.com/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files","actionsOnboardingTip":null},"truncated":false,"viewable":true,"workflowRedirectUrl":null,"symbols":{"timed_out":false,"not_analyzed":false,"symbols":[{"name":"BaseForm","kind":"class","ident_start":129,"ident_end":137,"extent_start":123,"extent_end":2398,"fully_qualified_name":"BaseForm","ident_utf16":{"start":{"line_number":8,"utf16_col":6},"end":{"line_number":8,"utf16_col":14}},"extent_utf16":{"start":{"line_number":8,"utf16_col":0},"end":{"line_number":79,"utf16_col":12}}},{"name":"allow_extra_fields","kind":"constant","ident_start":287,"ident_end":305,"extent_start":287,"extent_end":312,"fully_qualified_name":"BaseForm.allow_extra_fields","ident_utf16":{"start":{"line_number":13,"utf16_col":4},"end":{"line_number":13,"utf16_col":22}},"extent_utf16":{"start":{"line_number":13,"utf16_col":4},"end":{"line_number":13,"utf16_col":29}}},{"name":"filter_extra_fields","kind":"constant","ident_start":317,"ident_end":336,"extent_start":317,"extent_end":343,"fully_qualified_name":"BaseForm.filter_extra_fields","ident_utf16":{"start":{"line_number":14,"utf16_col":4},"end":{"line_number":14,"utf16_col":23}},"extent_utf16":{"start":{"line_number":14,"utf16_col":4},"end":{"line_number":14,"utf16_col":30}}},{"name":"_xsrf","kind":"constant","ident_start":349,"ident_end":354,"extent_start":349,"extent_end":401,"fully_qualified_name":"BaseForm._xsrf","ident_utf16":{"start":{"line_number":16,"utf16_col":4},"end":{"line_number":16,"utf16_col":9}},"extent_utf16":{"start":{"line_number":16,"utf16_col":4},"end":{"line_number":16,"utf16_col":56}}},{"name":"__init__","kind":"function","ident_start":411,"ident_end":419,"extent_start":407,"extent_end":1281,"fully_qualified_name":"BaseForm.__init__","ident_utf16":{"start":{"line_number":18,"utf16_col":8},"end":{"line_number":18,"utf16_col":16}},"extent_utf16":{"start":{"line_number":18,"utf16_col":4},"end":{"line_number":43,"utf16_col":27}}},{"name":"validate","kind":"function","ident_start":1291,"ident_end":1299,"extent_start":1287,"extent_end":1810,"fully_qualified_name":"BaseForm.validate","ident_utf16":{"start":{"line_number":45,"utf16_col":8},"end":{"line_number":45,"utf16_col":16}},"extent_utf16":{"start":{"line_number":45,"utf16_col":4},"end":{"line_number":59,"utf16_col":27}}},{"name":"add_error","kind":"function","ident_start":1847,"ident_end":1856,"extent_start":1843,"extent_end":1941,"fully_qualified_name":"BaseForm.add_error","ident_utf16":{"start":{"line_number":62,"utf16_col":8},"end":{"line_number":62,"utf16_col":17}},"extent_utf16":{"start":{"line_number":62,"utf16_col":4},"end":{"line_number":64,"utf16_col":37}}},{"name":"render","kind":"function","ident_start":1951,"ident_end":1957,"extent_start":1947,"extent_end":2335,"fully_qualified_name":"BaseForm.render","ident_utf16":{"start":{"line_number":66,"utf16_col":8},"end":{"line_number":66,"utf16_col":14}},"extent_utf16":{"start":{"line_number":66,"utf16_col":4},"end":{"line_number":75,"utf16_col":34}}},{"name":"__after__","kind":"function","ident_start":2369,"ident_end":2378,"extent_start":2365,"extent_end":2398,"fully_qualified_name":"BaseForm.__after__","ident_utf16":{"start":{"line_number":78,"utf16_col":8},"end":{"line_number":78,"utf16_col":17}},"extent_utf16":{"start":{"line_number":78,"utf16_col":4},"end":{"line_number":79,"utf16_col":12}}},{"name":"LoginForm","kind":"class","ident_start":2410,"ident_end":2419,"extent_start":2404,"extent_end":2536,"fully_qualified_name":"LoginForm","ident_utf16":{"start":{"line_number":85,"utf16_col":6},"end":{"line_number":85,"utf16_col":15}},"extent_utf16":{"start":{"line_number":85,"utf16_col":0},"end":{"line_number":87,"utf16_col":48}}},{"name":"login","kind":"constant","ident_start":2435,"ident_end":2440,"extent_start":2435,"extent_end":2487,"fully_qualified_name":"LoginForm.login","ident_utf16":{"start":{"line_number":86,"utf16_col":4},"end":{"line_number":86,"utf16_col":9}},"extent_utf16":{"start":{"line_number":86,"utf16_col":4},"end":{"line_number":86,"utf16_col":56}}},{"name":"password","kind":"constant","ident_start":2492,"ident_end":2500,"extent_start":2492,"extent_end":2536,"fully_qualified_name":"LoginForm.password","ident_utf16":{"start":{"line_number":87,"utf16_col":4},"end":{"line_number":87,"utf16_col":12}},"extent_utf16":{"start":{"line_number":87,"utf16_col":4},"end":{"line_number":87,"utf16_col":48}}},{"name":"RegisterForm","kind":"class","ident_start":2544,"ident_end":2556,"extent_start":2538,"extent_end":2937,"fully_qualified_name":"RegisterForm","ident_utf16":{"start":{"line_number":89,"utf16_col":6},"end":{"line_number":89,"utf16_col":18}},"extent_utf16":{"start":{"line_number":89,"utf16_col":0},"end":{"line_number":95,"utf16_col":81}}},{"name":"login","kind":"constant","ident_start":2572,"ident_end":2577,"extent_start":2572,"extent_end":2637,"fully_qualified_name":"RegisterForm.login","ident_utf16":{"start":{"line_number":90,"utf16_col":4},"end":{"line_number":90,"utf16_col":9}},"extent_utf16":{"start":{"line_number":90,"utf16_col":4},"end":{"line_number":90,"utf16_col":69}}},{"name":"email","kind":"constant","ident_start":2642,"ident_end":2647,"extent_start":2642,"extent_end":2693,"fully_qualified_name":"RegisterForm.email","ident_utf16":{"start":{"line_number":91,"utf16_col":4},"end":{"line_number":91,"utf16_col":9}},"extent_utf16":{"start":{"line_number":91,"utf16_col":4},"end":{"line_number":91,"utf16_col":55}}},{"name":"name","kind":"constant","ident_start":2698,"ident_end":2702,"extent_start":2698,"extent_end":2749,"fully_qualified_name":"RegisterForm.name","ident_utf16":{"start":{"line_number":92,"utf16_col":4},"end":{"line_number":92,"utf16_col":8}},"extent_utf16":{"start":{"line_number":92,"utf16_col":4},"end":{"line_number":92,"utf16_col":55}}},{"name":"password","kind":"constant","ident_start":2754,"ident_end":2762,"extent_start":2754,"extent_end":2798,"fully_qualified_name":"RegisterForm.password","ident_utf16":{"start":{"line_number":93,"utf16_col":4},"end":{"line_number":93,"utf16_col":12}},"extent_utf16":{"start":{"line_number":93,"utf16_col":4},"end":{"line_number":93,"utf16_col":48}}},{"name":"password_confirm","kind":"constant","ident_start":2803,"ident_end":2819,"extent_start":2803,"extent_end":2855,"fully_qualified_name":"RegisterForm.password_confirm","ident_utf16":{"start":{"line_number":94,"utf16_col":4},"end":{"line_number":94,"utf16_col":20}},"extent_utf16":{"start":{"line_number":94,"utf16_col":4},"end":{"line_number":94,"utf16_col":56}}},{"name":"chained_validators","kind":"constant","ident_start":2860,"ident_end":2878,"extent_start":2860,"extent_end":2937,"fully_qualified_name":"RegisterForm.chained_validators","ident_utf16":{"start":{"line_number":95,"utf16_col":4},"end":{"line_number":95,"utf16_col":22}},"extent_utf16":{"start":{"line_number":95,"utf16_col":4},"end":{"line_number":95,"utf16_col":81}}},{"name":"SettingsForm","kind":"class","ident_start":2945,"ident_end":2957,"extent_start":2939,"extent_end":3185,"fully_qualified_name":"SettingsForm","ident_utf16":{"start":{"line_number":97,"utf16_col":6},"end":{"line_number":97,"utf16_col":18}},"extent_utf16":{"start":{"line_number":97,"utf16_col":0},"end":{"line_number":101,"utf16_col":51}}},{"name":"email","kind":"constant","ident_start":2973,"ident_end":2978,"extent_start":2973,"extent_end":3024,"fully_qualified_name":"SettingsForm.email","ident_utf16":{"start":{"line_number":98,"utf16_col":4},"end":{"line_number":98,"utf16_col":9}},"extent_utf16":{"start":{"line_number":98,"utf16_col":4},"end":{"line_number":98,"utf16_col":55}}},{"name":"name","kind":"constant","ident_start":3029,"ident_end":3033,"extent_start":3029,"extent_end":3080,"fully_qualified_name":"SettingsForm.name","ident_utf16":{"start":{"line_number":99,"utf16_col":4},"end":{"line_number":99,"utf16_col":8}},"extent_utf16":{"start":{"line_number":99,"utf16_col":4},"end":{"line_number":99,"utf16_col":55}}},{"name":"blog","kind":"constant","ident_start":3085,"ident_end":3089,"extent_start":3085,"extent_end":3133,"fully_qualified_name":"SettingsForm.blog","ident_utf16":{"start":{"line_number":100,"utf16_col":4},"end":{"line_number":100,"utf16_col":8}},"extent_utf16":{"start":{"line_number":100,"utf16_col":4},"end":{"line_number":100,"utf16_col":52}}},{"name":"bio","kind":"constant","ident_start":3138,"ident_end":3141,"extent_start":3138,"extent_end":3185,"fully_qualified_name":"SettingsForm.bio","ident_utf16":{"start":{"line_number":101,"utf16_col":4},"end":{"line_number":101,"utf16_col":7}},"extent_utf16":{"start":{"line_number":101,"utf16_col":4},"end":{"line_number":101,"utf16_col":51}}},{"name":"AskForm","kind":"class","ident_start":3197,"ident_end":3204,"extent_start":3191,"extent_end":3358,"fully_qualified_name":"AskForm","ident_utf16":{"start":{"line_number":103,"utf16_col":6},"end":{"line_number":103,"utf16_col":13}},"extent_utf16":{"start":{"line_number":103,"utf16_col":0},"end":{"line_number":106,"utf16_col":40}}},{"name":"title","kind":"constant","ident_start":3220,"ident_end":3225,"extent_start":3220,"extent_end":3286,"fully_qualified_name":"AskForm.title","ident_utf16":{"start":{"line_number":104,"utf16_col":4},"end":{"line_number":104,"utf16_col":9}},"extent_utf16":{"start":{"line_number":104,"utf16_col":4},"end":{"line_number":104,"utf16_col":70}}},{"name":"body","kind":"constant","ident_start":3291,"ident_end":3295,"extent_start":3291,"extent_end":3317,"fully_qualified_name":"AskForm.body","ident_utf16":{"start":{"line_number":105,"utf16_col":4},"end":{"line_number":105,"utf16_col":8}},"extent_utf16":{"start":{"line_number":105,"utf16_col":4},"end":{"line_number":105,"utf16_col":30}}},{"name":"tags","kind":"constant","ident_start":3322,"ident_end":3326,"extent_start":3322,"extent_end":3358,"fully_qualified_name":"AskForm.tags","ident_utf16":{"start":{"line_number":106,"utf16_col":4},"end":{"line_number":106,"utf16_col":8}},"extent_utf16":{"start":{"line_number":106,"utf16_col":4},"end":{"line_number":106,"utf16_col":40}}},{"name":"AnswerForm","kind":"class","ident_start":3366,"ident_end":3376,"extent_start":3360,"extent_end":3456,"fully_qualified_name":"AnswerForm","ident_utf16":{"start":{"line_number":108,"utf16_col":6},"end":{"line_number":108,"utf16_col":16}},"extent_utf16":{"start":{"line_number":108,"utf16_col":0},"end":{"line_number":109,"utf16_col":68}}},{"name":"answer_body","kind":"constant","ident_start":3392,"ident_end":3403,"extent_start":3392,"extent_end":3456,"fully_qualified_name":"AnswerForm.answer_body","ident_utf16":{"start":{"line_number":109,"utf16_col":4},"end":{"line_number":109,"utf16_col":15}},"extent_utf16":{"start":{"line_number":109,"utf16_col":4},"end":{"line_number":109,"utf16_col":68}}}]}},"copilotInfo":null,"copilotAccessAllowed":false,"modelsAccessAllowed":false,"modelsRepoIntegrationEnabled":false,"csrf_tokens":{"/renxing/quora-python/branches":{"post":"17qxmMdSms_TiWqHFlUT-uSuSMjybRVupvvgQcspRfxV6VixDme-ggUPuuAPb9GHax4a81LFCt2E6moazlaJEA"},"/repos/preferences":{"post":"mA-IeL74fBWS_CC3H9AowpZFQsRTbSQIdJh2UproVTV3seWZSZOpguHcTE58kjVZ-12ObsfdB1ErIs93ITlyCA"}}},"title":"quora-python/forms.py at master · renxing/quora-python","appPayload":{"helpUrl":"https://docs.github.com","findFileWorkerPath":"/assets-cdn/worker/find-file-worker-7d7eb7c71814.js","findInFileWorkerPath":"/assets-cdn/worker/find-in-file-worker-1ae9fa256942.js","githubDevUrl":null,"enabled_features":{"code_nav_ui_events":false,"react_blob_overlay":false,"accessible_code_button":true,"github_models_repo_integration":false}}}
0