Repository: falconry/falcon

Issue:
Friendly status code names
Add friendly names for common status codes ala https://docs.python.org/3.0/library/http.client.html



Discussion:
Would love to help out with this. Do you want to completely convert `falcon.status_codes` from `HTTP_XXX` to this model or would you prefer to keep both?

@etscrivner Thanks! I think we ought to keep both, if nothing else for backwards-compat. Also, some people may prefer the more succinct, code-based names. We can always deprecate the codes later if it turns out most people have stopped using them.

we are already facing this issue 

using this in our code base :- 

```
def on_get(self, req, resp):
    resp.status = falcon.HTTP_300
```

and travis complaints :- 

************\* Module jumpgate.identity.drivers.sl.versions

E: 9,22: Module 'falcon' has no 'HTTP_300' member (no-member)

ERROR: InvocationError: '/home/travis/build/softlayer/jumpgate/.tox/pep8/bin/pylint -E jumpgate'

should i open a new bug? have the old status codes been deprecated?

@Neetuj That's odd; HTTP_300 has not been removed. In fact, this work item hasn't been started yet (at least I haven't seen any PRs referencing it). Maybe this is a false positive from pylint for some reason? 

Yes seems like so .. since i also did not see any work or check in related
to it.

On Thu, Jan 29, 2015 at 8:03 PM, Kurt Griffiths notifications@github.com
wrote:

> @Neetuj https://github.com/Neetuj That's odd; HTTP_300 has not been
> removed. In fact, this work item hasn't been started yet (at least I
> haven't seen any PRs referencing it). Maybe this is a false positive from
> pylint for some reason?
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/racker/falcon/issues/308#issuecomment-72141857.

@Neetuj Any update on this issue? Is there a way to reproduce the issue outside of Travis?

I am working on this at the Pycon sprints


Resolving patch:
diff --git a/falcon/status_codes.py b/falcon/status_codes.py
--- a/falcon/status_codes.py
+++ b/falcon/status_codes.py
@@ -14,53 +14,95 @@
 
 
 HTTP_100 = '100 Continue'
+HTTP_CONTINUE = '100 Continue'
 HTTP_101 = '101 Switching Protocols'
+HTTP_SWITCHING_PROTOCOLS = HTTP_101
 
 HTTP_200 = '200 OK'
+HTTP_OK = HTTP_200
 HTTP_201 = '201 Created'
+HTTP_CREATED = HTTP_201
 HTTP_202 = '202 Accepted'
+HTTP_ACCEPTED = HTTP_202
 HTTP_203 = '203 Non-Authoritative Information'
+HTTP_NON_AUTHORITATIVE_INFORMATION = HTTP_203
 HTTP_204 = '204 No Content'
+HTTP_NO_CONTENT = HTTP_204
 HTTP_205 = '205 Reset Content'
+HTTP_RESET_CONTENT = HTTP_205
 HTTP_206 = '206 Partial Content'
+HTTP_PARTIAL_CONTENT = HTTP_206
 HTTP_226 = '226 IM Used'
+HTTP_IM_USED = HTTP_226
 
-# TODO: 3xx
 HTTP_300 = '300 Multiple Choices'
+HTTP_MULTIPLE_CHOICES = HTTP_300
 HTTP_301 = '301 Moved Permanently'
+HTTP_MOVED_PERMANENTLY = HTTP_301
 HTTP_302 = '302 Found'
+HTTP_FOUND = HTTP_302
 HTTP_303 = '303 See Other'
+HTTP_SEE_OTHER = HTTP_303
 HTTP_304 = '304 Not Modified'
+HTTP_NOT_MODIFIED = HTTP_304
 HTTP_305 = '305 Use Proxy'
+HTTP_USE_PROXY = HTTP_305
 HTTP_307 = '307 Temporary Redirect'
+HTTP_TEMPORARY_REDIRECT = HTTP_307
 
 HTTP_400 = '400 Bad Request'
+HTTP_BAD_REQUEST = HTTP_400
 HTTP_401 = '401 Unauthorized'  # <-- Really means "unauthenticated"
+HTTP_UNAUTHORIZED = HTTP_401
 HTTP_402 = '402 Payment Required'
+HTTP_PAYMENT_REQUIRED = HTTP_402
 HTTP_403 = '403 Forbidden'  # <-- Really means "unauthorized"
+HTTP_FORBIDDEN = HTTP_403
 HTTP_404 = '404 Not Found'
+HTTP_NOT_FOUND = HTTP_404
 HTTP_405 = '405 Method Not Allowed'
+HTTP_METHOD_NOT_ALLOWED = HTTP_405
 HTTP_406 = '406 Not Acceptable'
+HTTP_NOT_ACCEPTABLE = HTTP_406
 HTTP_407 = '407 Proxy Authentication Required'
+HTTP_PROXY_AUTHENTICATION_REQUIRED = HTTP_407
 HTTP_408 = '408 Request Time-out'
+HTTP_REQUEST_TIMEOUT = HTTP_408
 HTTP_409 = '409 Conflict'
+HTTP_CONFLICT = HTTP_409
 HTTP_410 = '410 Gone'
+HTTP_GONE = HTTP_410
 HTTP_411 = '411 Length Required'
+HTTP_LENGTH_REQUIRED = HTTP_411
 HTTP_412 = '412 Precondition Failed'
+HTTP_PRECONDITION_FAILED = HTTP_412
 HTTP_413 = '413 Payload Too Large'
+HTTP_REQUEST_ENTITY_TOO_LARGE = HTTP_413
 HTTP_414 = '414 URI Too Long'
+HTTP_REQUEST_URI_TOO_LONG = HTTP_414
 HTTP_415 = '415 Unsupported Media Type'
+HTTP_UNSUPPORTED_MEDIA_TYPE = HTTP_415
 HTTP_416 = '416 Range Not Satisfiable'
+HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = HTTP_416
 HTTP_417 = '417 Expectation Failed'
+HTTP_EXPECTATION_FAILED = HTTP_417
 HTTP_418 = "418 I'm a teapot"
+HTTP_IM_A_TEAPOT = HTTP_418
 HTTP_426 = '426 Upgrade Required'
+HTTP_UPGRADE_REQUIRED = HTTP_426
 
 HTTP_500 = '500 Internal Server Error'
+HTTP_INTERNAL_SERVER_ERROR = HTTP_500
 HTTP_501 = '501 Not Implemented'
+HTTP_NOT_IMPLEMENTED = HTTP_501
 HTTP_502 = '502 Bad Gateway'
+HTTP_BAD_GATEWAY = HTTP_502
 HTTP_503 = '503 Service Unavailable'
+HTTP_SERVICE_UNAVAILABLE = HTTP_503
 HTTP_504 = '504 Gateway Time-out'
+HTTP_GATEWAY_TIMEOUT = HTTP_504
 HTTP_505 = '505 HTTP Version not supported'
+HTTP_HTTP_VERSION_NOT_SUPPORTED = HTTP_505
 
 # 70X - Inexcusable
 HTTP_701 = '701 Meh'


Test patch: