chrso - the leanest (perhaps), meanest (if you look at it right) URL shortener written with Flask in the entire world (maybe...).
Replacement to Flask’s flash() for “magic” functionality in chr. If you want to use the real flash, use _flash() or flask.flash itself.
flash(“SOMETHING”, “error”) if things go wrong flash(“SOMETHING”, “success”) if things go right
Note
It’s kind of expected for this to be empty - the main file is just Flask related CRUD.
Shorten a long URL and add it to our database.
Parameters: |
|
---|---|
Returns: | False if url add failed, (slug, delete) otherwise |
Grab the key usable for deleting a URL.
Parameters: | ident – an identifier for the URL we want info about. |
---|
Find out whether the given ident (URL, usually) exists.
Parameters: | ident – an identifier for the URL we want info about. |
---|
Add a ‘hit’ to the database for a given URL. If the given URL is a “burn after reading” url, it will be expunged by this function. If the given URL has statistics turned off, this won’t do anything unless we’re removing a burn after reading URL.
Parameters: |
|
---|
Find all the corresponding hits for a given ident.
Parameters: | ident – an identifier for the URL we want to get hits for. |
---|
Get the long URL from a shortened ident.
Parameters: | ident – an identifier for the URL we want info about. |
---|
This is just a convenience function so rather than putting schema.thing.format(blah) everywhere, we just schema.thing(blah)
Remove a shortened URL from our database.
Parameters: | ident – an identifier for the URL we want to remove. |
---|
Get the numerical row id for an ident.
Parameters: | ident – an identifier for the URL we want info about. |
---|
Find out whether or not the given URL is a burn after reading URL.
Parameters: | ident – an identifier for the URL we want info about. |
---|
Pull a bunch of statistics about the given ident. Click statistics, useragents, long URL, all the good stuff.
Parameters: |
|
---|
Note: Taken from the public domain (namely: Stack Overflow), so this isn’t my documentation.
Converts any integer into a base [BASE] number. I have chosen 62 as it is meant to represent the integers using all the alphanumeric characters, [no special characters] = {0..9}, {A..Z}, {a..z}
I plan on using this to shorten the representation of possibly long ids, a la url shorteners
saturate() takes the base 62 key, as a string, and turns it back into an integer dehydrate() takes an integer and turns it into the base 62 string
Turn an integer [integer] into a base [BASE] number in string representation
Handles negatives by prefixing with a special character [NEGATIVE_BUFFER] and using the positive.
Turn the base [BASE] number [key] into an integer Handles negatives by returning the negative.
Turns an integer [integer] into digit in base [BASE] as a character representation.
Turns a digit [char] in character representation from the number system with base [BASE] into an integer.
Borrowed this from werkzeug commits since it’s not on PyPI yet: https://github.com/mitsuhiko/werkzeug/commit/cdf680222af293a2c118d8d52eecfd7b0c566e14
This middleware can be applied to add HTTP proxy support to an application that was not designed with HTTP proxies in mind. It sets REMOTE_ADDR, HTTP_HOST from X-Forwarded headers.
If you have more than one proxy server in front of your app, set num_proxies accordingly.
Do not use this middleware in non-proxy setups for security reasons.
The original values of REMOTE_ADDR and HTTP_HOST are stored in the WSGI environment as werkzeug.proxy_fix.orig_remote_addr and werkzeug.proxy_fix.orig_http_host.
Parameters: |
|
---|
Selects the new remote addr from the given list of ips in X-Forwarded-For. By default it picks the one that the num_proxies proxy server provides. Before 0.9 it would always pick the first.
New in version 0.8.