Automated Documentation

chrso

chrso - the leanest (perhaps), meanest (if you look at it right) URL shortener written with Flask in the entire world (maybe...).

chrso.main

chrso.main.flash(message, type_=None)

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.

chrso.url

chrso.url.add(long_, statistics, burn, short=None, ua=None, ip=None, ptime=None, delete=None)

Shorten a long URL and add it to our database.

Parameters:
  • long – the long URL we’re wishing to shorten
  • statistics – should we bother enabling statistics for the shortened URL? {0,1} or {True,False} please
  • burn – should this be a “burn after reading” URL?
  • short – an optional custom URL
  • ua – the user-agent of the person the URL was shortened by.
  • ip – the IP address the URL was shortened by
  • ptime – the time of the shorten (time.time() is used if omitted)
  • delete – the deletion key that can be used to remove the url by the user.
Returns:

False if url add failed, (slug, delete) otherwise

chrso.url.delete_key(ident)

Grab the key usable for deleting a URL.

Parameters:ident – an identifier for the URL we want info about.
chrso.url.exists(ident)

Find out whether the given ident (URL, usually) exists.

Parameters:ident – an identifier for the URL we want info about.
chrso.url.hit(ident, ua=None, ip=None, ptime=None)

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:
  • ident – an identifier for the URL we want to add a hit to.
  • ua – the user-agent of the user
  • ip – the IP of the user
  • ptime – the time the hit occured (None means current time)
chrso.url.hits(ident)

Find all the corresponding hits for a given ident.

Parameters:ident – an identifier for the URL we want to get hits for.
chrso.url.long(ident)

Get the long URL from a shortened ident.

Parameters:ident – an identifier for the URL we want info about.
chrso.url.partial_format(part)

This is just a convenience function so rather than putting schema.thing.format(blah) everywhere, we just schema.thing(blah)

chrso.url.remove(ident)

Remove a shortened URL from our database.

Parameters:ident – an identifier for the URL we want to remove.
chrso.url.row_id(ident)

Get the numerical row id for an ident.

Parameters:ident – an identifier for the URL we want info about.
chrso.url.should_burn(ident)

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.
chrso.url.stats(ident, clip=35)

Pull a bunch of statistics about the given ident. Click statistics, useragents, long URL, all the good stuff.

Parameters:
  • ident – an identifier for the URL we want to get stats for.
  • clip – the length to “clip” down long URLs to. (so they can be displayed to end-users cleanly)

chrso.base62

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

chrso.base62.dehydrate(integer)

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.

chrso.base62.saturate(key)

Turn the base [BASE] number [key] into an integer Handles negatives by returning the negative.

chrso.base62.true_chr(integer)

Turns an integer [integer] into digit in base [BASE] as a character representation.

chrso.base62.true_ord(char)

Turns a digit [char] in character representation from the number system with base [BASE] into an integer.

chrso.proxyfix

Borrowed this from werkzeug commits since it’s not on PyPI yet: https://github.com/mitsuhiko/werkzeug/commit/cdf680222af293a2c118d8d52eecfd7b0c566e14

class chrso.proxyfix.ProxyFix(app, num_proxies=1)

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:
  • app – the WSGI application
  • num_proxies – the number of proxy servers in front of the app.
get_remote_addr(forwarded_for)

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.

Project Versions

Table Of Contents

Previous topic

Usage

Next topic

chr api documentation

This Page