Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No serverpy #324

Merged
merged 13 commits into from
May 6, 2014
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: aspen --network_address=:$PORT --www_root=doc/ --project_root=doc/.aspen
web: python -m aspen --www_root=doc/ --project_root=doc/.aspen
4 changes: 0 additions & 4 deletions aspen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@
dist = pkg_resources.get_distribution('aspen')
__version__ = dist.version
WINDOWS = sys.platform[:3] == 'win'
NETWORK_ENGINES = ['cheroot']

for entrypoint in pkg_resources.iter_entry_points(group='aspen.network_engines'):
NETWORK_ENGINES.append(entrypoint.name)

BUILTIN_RENDERERS = [ 'stdlib_format'
, 'stdlib_percent'
Expand Down
11 changes: 9 additions & 2 deletions aspen/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@
a higher performance WSGI server like Gunicorn, uwsgi, Spawning,
or the like.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from aspen import log_dammit
from aspen.website import Website
from wsgiref.simple_server import make_server



if __name__ == '__main__':
make_server('0.0.0.0', 8080, Website()).serve_forever()
website = Website()
server = make_server('0.0.0.0', 8080, website)
log_dammit("Greetings, program! Welcome to port 8080.")
server.serve_forever()
160 changes: 0 additions & 160 deletions aspen/algorithms/server.py

This file was deleted.

23 changes: 3 additions & 20 deletions aspen/algorithms/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
import traceback

import aspen
from aspen import dispatcher, resources, sockets
from aspen import dispatcher, resources
from aspen.http.request import Request
from aspen.http.response import Response
from aspen.sockets.socket import Socket
from aspen import typecasting
from first import first as _first

Expand Down Expand Up @@ -67,24 +66,8 @@ def apply_typecasters_to_path(website, request):
typecasting.apply_typecasters(website.typecasters, request.line.uri.path)


def get_response_for_socket(request):
socket = sockets.get(request)
if socket is None:
# This is not a socket request.
response = None
elif isinstance(socket, Response):
# Actually, this is a handshake request.
response = socket
else:
assert isinstance(socket, Socket) # sanity check
# This is a socket ... request?
response = socket.respond(request)
return {'response': response}


def get_resource_for_request(request, response):
if response is None:
return {'resource': resources.get(request)}
def get_resource_for_request(request):
return {'resource': resources.get(request)}


def get_response_for_resource(request, resource=None):
Expand Down
44 changes: 0 additions & 44 deletions aspen/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
import errno
import mimetypes
import os
import socket
import sys
import traceback
import pkg_resources
from collections import defaultdict

import aspen
import aspen.logging
from aspen import execution
from aspen.configuration import parse
from aspen.configuration.exceptions import ConfigurationError
from aspen.configuration.options import OptionParser, DEFAULT
Expand All @@ -35,10 +33,6 @@

KNOBS = \
{ 'configuration_scripts': (lambda: [], parse.list_)
, 'network_engine': ('cheroot', parse.network_engine)
, 'network_address': ( (('0.0.0.0', 8080), socket.AF_INET)
, parse.network_address
)
, 'project_root': (None, parse.identity)
, 'logging_threshold': (0, int)
, 'www_root': (None, parse.identity)
Expand Down Expand Up @@ -256,7 +250,6 @@ def safe_getcwd(errorstr):
"or --www_root on the command line.")

self.www_root = os.path.realpath(self.www_root)
os.chdir(self.www_root)

# load renderers
self.renderer_factories = {}
Expand Down Expand Up @@ -290,40 +283,6 @@ def safe_getcwd(errorstr):
if not mimetypes.inited:
mimetypes.init()

# network_engine

## Load modules
ENGINES = {}
for entrypoint in pkg_resources.iter_entry_points(group='aspen.network_engines'):
ENGINES[entrypoint.name] = entrypoint.load()

if self.network_engine in ENGINES:
# found in a module
Engine = ENGINES[self.network_engine].Engine
else:
# look for a built-in one
try:
capture = {}
python_syntax = 'from aspen.network_engines.%s_ import Engine'
exec python_syntax % self.network_engine in capture
Engine = capture['Engine']
except ImportError:
# ANSI colors:
# http://stackoverflow.com/questions/287871/
# http://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes
# XXX consider http://pypi.python.org/pypi/colorama
msg = "\033[1;31mImportError loading the %s network engine:\033[0m"
aspen.log_dammit(msg % self.network_engine)
raise
self.network_engine = Engine(self.network_engine, self)

# network_address, network_sockfam, network_port
self.network_address, self.network_sockfam = self.network_address
if self.network_sockfam == socket.AF_INET:
self.network_port = self.network_address[1]
else:
self.network_port = None

self.run_config_scripts()
self.show_renderers()

Expand Down Expand Up @@ -399,9 +358,6 @@ def run_config_scripts(self):
else:
# problems with default config files are okay, but get logged
aspen.log(msg)
else:
aspen.log_dammit("Loading configuration file '%s' (possibly changing settings)" % filepath)
execution.if_changes(filepath)



Expand Down
1 change: 0 additions & 1 deletion aspen/configuration/mime.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
application/json json
application/x-socket.io sock
image/x-icon ico
text/plain py

Expand Down
12 changes: 0 additions & 12 deletions aspen/configuration/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,6 @@ def OptionParser():
"$ASPEN_PROJECT_ROOT/configure-aspen.py")
, default=DEFAULT
)
basic.add_option( "-a", "--network_address"
, help=("the IPv4, IPv6, or Unix address to bind to "
"[0.0.0.0:8080]")
, default=DEFAULT
)
basic.add_option( "-e", "--network_engine"
, help=( "the HTTP engine to use, one of "
+ "{%s}" % ','.join(aspen.NETWORK_ENGINES)
+ " [%s]" % aspen.NETWORK_ENGINES[0]
)
, default=DEFAULT
)
basic.add_option( "-l", "--logging_threshold"
, help=("a small integer; 1 will suppress most of aspen's "
"internal logging, 2 will suppress all it [0]")
Expand Down
Loading