import urlparse

from furl import furl as Furl
from environs import Env

##### This is the beginning of the plugin code #####

def furl_parser(value):
    return Furl(value)

def urlparse_parser(value):
    return urlparse.urlparse(value)

def setup(env):
    env.add_parser('furl', furl_parser)
    env.add_parser('purl', urlparse_parser)

##### End of the plugin code #####

os.environ['GITHUB_URL'] = 'https://github.com/sloria/environs'

# Our application activates the plugin using the setup function

env = Env()
setup(env)

# We now have the 'furl' and 'purl' methods available

github_furl = env.furl('GITHUB_URL')
github_purl = env.purl('GITHUB_URL')
env = Env()


@env.parser_for("furl")
def url_parser(value: str) -> Url:
    return Url(value)


with env.prefixed("PT_"):
    address = env.str("ADDRESS", "0.0.0.0")  # nosec
    port = env.int("PORT", 5000)
    debug = env.bool("DEBUG", False)
    static_handler = env.bool("ENABLE_STATIC_HANDLER", True)
    blog_path = env.path("BLOG_PATH", "./blog")
    public_url = env.furl("PUBLIC_URL", DEFAULT_PUBLIC_URL)
    blog_static_url = env.furl("BLOG_STATIC_URL", DEFAULT_BLOG_STATIC_URL)
    fq_url = env.furl("FQ_URL", f"http://localhost:{port}")

    # Disabled by default because rate limit can be hit relatively easily
    # during development
    enable_github = env.bool("ENABLE_GITHUB", False)
    github_user = env.str("GITHUB_USER", "PhilipTrauner")
    # Disabled by default because credentials are necessary
    enable_spotify = env.bool("ENABLE_SPOTIFY", False)
    spotify_user = env.str("SPOTIFY_USER", "philip.trauner")
    spotify_client_id = env.str("SPOTIFY_CLIENT_ID", None)
    spotify_client_secret = env.str("SPOTIFY_CLIENT_SECRET", None)

app = Sanic(NAME)
Exemple #3
0
##### This is the beginning of the plugin code #####


def furl_parser(value):
    return Furl(value)


def urlparse_parser(value):
    return URL(value)


def setup(env):
    env.add_parser("furl", furl_parser)
    env.add_parser("yurl", urlparse_parser)


##### End of the plugin code #####


os.environ["GITHUB_URL"] = "https://github.com/sloria/environs"

# Our application activates the plugin using the setup function

env = Env()
setup(env)

# We now have the 'furl' and 'yurl' methods available

github_furl = env.furl("GITHUB_URL")
github_yurl = env.yurl("GITHUB_URL")
##### This is the beginning of the plugin code #####


def furl_parser(value):
    return Furl(value)


def urlparse_parser(value):
    return URL(value)


def setup(env):
    env.add_parser("furl", furl_parser)
    env.add_parser("yurl", urlparse_parser)


##### End of the plugin code #####

os.environ["GITHUB_URL"] = "https://github.com/sloria/environs"

# Our application activates the plugin using the setup function

env = Env()
setup(env)

# We now have the 'furl' and 'yurl' methods available

github_furl = env.furl("GITHUB_URL")
github_yurl = env.yurl("GITHUB_URL")