本文整理汇总了Python中tiddlyweb.web.util.server_base_url函数的典型用法代码示例。如果您正苦于以下问题:Python server_base_url函数的具体用法?Python server_base_url怎么用?Python server_base_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了server_base_url函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: register
def register(environ, start_response):
domain = get_domain(environ["HTTP_HOST"])
query = environ["tiddlyweb.query"]
name = query.get("name", [None])[0]
company = query.get("company", [None])[0]
country = query.get("country", [None])[0]
email = query.get("email", [None])[0]
if not (name and company and email):
# The form has not been filled out
raise HTTP302(server_base_url(environ) + "/pages/register.html")
to_address = environ["tiddlyweb.config"].get("wikidata.register_address", "[email protected]")
subject = "Registration Request"
body = """
name: %s
email: %s
company: %s
country: %s
""" % (
name,
email,
company,
country,
)
try:
send_email(to_address, subject=subject, body=body, from_="[email protected]" + domain)
except socket.error:
logging.debug("failed to send: %s:%s:%s", to_address, subject, body)
raise HTTP303(server_base_url(environ) + "/pages/registered.html")
开发者ID:jayfresh,项目名称:wiki-data,代码行数:28,代码来源:__init__.py
示例2: get_home
def get_home(environ, start_response):
user = environ['tiddlyweb.usersign']
if user['name'] == 'GUEST' or 'MEMBER' not in user['roles']:
raise HTTP302(server_base_url(environ) + '/')
else:
raise HTTP302(server_base_url(environ) + '/'
+ encode_name(user['name']))
开发者ID:cdent,项目名称:tiddlyhoster,代码行数:7,代码来源:__init__.py
示例3: logout
def logout(environ, start_response):
"""
Expire the tiddlyweb_user cookie when a POST is received.
"""
redirect = environ['tiddlyweb.query'].get('tiddlyweb_redirect', [None])[0]
if redirect:
uri = server_base_url(environ) + redirect.encode('UTF-8')
else:
uri = environ.get('HTTP_REFERER',
server_base_url(environ) +
environ['tiddlyweb.config'].get('logout_uri', '/'))
path = environ.get('tiddlyweb.config', {}).get('server_prefix', '')
cookie = Cookie.SimpleCookie()
cookie['tiddlyweb_user'] = ''
cookie['tiddlyweb_user']['path'] = '%s/' % path
if 'MSIE' in environ.get('HTTP_USER_AGENT', ''):
cookie['tiddlyweb_user']['expires'] = time.strftime(
'%a, %d-%m-%y %H:%M:%S GMT', time.gmtime(time.time() - 600000))
else:
cookie['tiddlyweb_user']['max-age'] = '0'
cookie_output = cookie.output(header='')
start_response('303 See Other', [
('Set-Cookie', cookie_output),
('Expires', time.strftime(
'%a, %d %b %Y %H:%M:%S GMT', time.gmtime(time.time() - 600000))),
('Cache-Control', 'no-store'),
('Location', uri),
])
return [uri]
开发者ID:tiddlyweb,项目名称:tiddlywebplugins.logout,代码行数:32,代码来源:logout.py
示例4: _create_user
def _create_user(environ, start_response, creation=0, expiration=0, role='tier1'):
domain = get_domain(environ['HTTP_HOST'])
if creation == 0:
creation = time.time()
store = environ['tiddlyweb.store']
query = environ['tiddlyweb.query']
name = query.get('name', [None])[0]
email = query.get('email', [None])[0]
company = query.get('company', [None])[0]
country = query.get('country', [None])[0]
if not (name and email):
# The form has not been filled out
return _user_form(environ, start_response, role=role, message='Missing Data!',
formdata={'name': name, 'email': email,
'company': company, 'country': country})
user = User(email)
try:
user = store.get(user)
# User exists!
return _user_form(environ, start_response, role=role, message='That account already exists!',
formdata={'name': name, 'email': email,
'company': company, 'country': country})
except NoUserError:
password = _random_pass()
user.set_password(password)
user.add_role(role)
store.put(user)
bag_name = environ['tiddlyweb.config'].get('magicuser.bag', 'MAGICUSER')
ensure_bag(bag_name, store, policy_dict={
'read': ['NONE'], 'write': ['NONE'],
'create': ['NONE'], 'manage': ['NONE']})
tiddler = Tiddler(email, bag_name)
tiddler.fields['country'] = country
tiddler.fields['company'] = company
tiddler.fields['name'] = name
# Set the creation and expiration times.
now = time.time()
tiddler.fields['creation'] = '%s' % creation
tiddler.fields['expiry'] = '%s' % expiration
store.put(tiddler)
to_address = email
subject = domain+" user info"
body = """
Here's your info:
Username: %s
Password: %s
""" % (email, password)
query_string = '?email=%s' % to_address
try:
send_email(to_address, subject=subject, body=body, from_='[email protected]'+domain)
query_string += '&success=1&role=%s' % role
raise HTTP303(server_base_url(environ)+'/pages/new_account'+query_string)
except socket.error:
logging.debug('failed to send: %s:%s:%s', to_address, subject, body)
query_string += '&failure=1&role=%s' % role
raise HTTP302(server_base_url(environ)+'/pages/new_account'+query_string)
开发者ID:cdent,项目名称:wiki-data,代码行数:58,代码来源:__init__.py
示例5: _return_to
def _return_to(self, environ, redirect, link, usersign):
"""
Generate the URL to which the user should return to after
visiting their OpenID server.
"""
return '%s/challenge/openid?nonce=%s&tiddlyweb_redirect=%s&openid_server=%s&usersign=%s' \
% (web.server_base_url(environ), self._nonce(), redirect, link, usersign)
开发者ID:angeluseve,项目名称:tiddlyweb,代码行数:7,代码来源:openid.py
示例6: get_tiddler_edit
def get_tiddler_edit(environ, start_response):
usersign = environ['tiddlyweb.usersign']
store = environ['tiddlyweb.store']
title = environ['tiddlyweb.query'].get('title', [''])[0]
bag_name = environ['tiddlyweb.query'].get('bag', [''])[0]
username = usersign['name']
if not 'MEMBER' in usersign['roles']:
raise HTTP404('bad edit')
if not title and not bag_name:
tiddler = get_profile(store, usersign, username)
page_title = 'Edit Profile'
return_url = '%s/home' % server_base_url(environ)
elif not title:
tiddler = Tiddler('', bag_name)
page_title = 'Edit New Tiddler'
return_url = ''
else:
tiddler = Tiddler(title, bag_name)
page_title = 'Edit %s' % title
return_url = tiddler_url(environ, tiddler)
try:
tiddler = store.get(tiddler)
except StoreError:
pass
bag = Bag(tiddler.bag)
bag = store.get(bag)
bag.policy.allows(usersign, 'write')
data = {}
data['tiddler'] = tiddler
data['return_url'] = return_url
data['title'] = page_title
return send_template(environ, 'profile_edit.html', data)
开发者ID:cdent,项目名称:tiddlyhoster,代码行数:35,代码来源:__init__.py
示例7: make_ticklist
def make_ticklist(environ, start_response):
"""
Record routes the user would like to climb.
"""
store = environ['tiddlyweb.store']
current_user = environ['tiddlyweb.usersign']['name']
gym = get_route_value(environ, 'gym')
tick_wishes = environ['tiddlyweb.query'].get('addroute', [])
routes = _get_gym_routes(environ, gym)
for route in routes:
route.bag = current_user
if route.title in tick_wishes:
route.tags = ['tickwish']
route.fields['gym'] = gym
store.put(route)
else:
try:
tiddler = store.get(route)
tiddler.tags.remove('tickwish')
store.put(tiddler)
except (StoreError, ValueError):
pass
raise HTTP303(server_base_url(environ)
+ '/gyms/%s/ticklist' % encode_name(gym))
开发者ID:cdent,项目名称:nitor,代码行数:26,代码来源:__init__.py
示例8: record_climbs
def record_climbs(environ, start_response):
"""
Record a climb that has been accomplished.
"""
query = environ['tiddlyweb.query']
store = environ['tiddlyweb.store']
current_user = environ['tiddlyweb.usersign']['name']
gym = get_route_value(environ, 'gym')
routes = query['route']
dones = query['doneroute']
for index, value in enumerate(dones):
if value != '':
route_title = routes[index]
tiddler = Tiddler(route_title, current_user)
try:
tiddler = store.get(tiddler)
except StoreError:
pass
if value in CLEAN_CLIMB:
try:
tiddler.tags.remove('tickwish')
except ValueError:
pass
tiddler.fields['climbtype'] = value
tiddler.fields['gym'] = gym
tiddler.tags.append('climb')
store.put(tiddler)
raise HTTP303(server_base_url(environ) + environ['REQUEST_URI'])
开发者ID:cdent,项目名称:nitor,代码行数:31,代码来源:__init__.py
示例9: _handle_response
def _handle_response(self, environ, start_response):
oidconsumer = consumer.Consumer({}, None)
host = server_base_url(environ)
url = urlparse.urljoin(host, '%s/challenge/%s' % (
environ['tiddlyweb.config']['server_prefix'],
CHALLENGER_NAME))
query = {}
for key in environ['tiddlyweb.query']:
query[key] = environ['tiddlyweb.query'][key][0]
info = oidconsumer.complete(query, url)
display_identifier = info.getDisplayIdentifier()
if info.status == consumer.FAILURE and display_identifier:
return self._render_form(environ, start_response,
openid=display_identifier,
message='Verification of %s failed with: %s' % (
display_identifier, info.message))
elif info.status == consumer.SUCCESS:
return self._success(environ, start_response, info)
elif info.status == consumer.CANCEL:
return self._render_form(environ, start_response,
message='You cancelled, try again with something else?')
elif info.status == consumer.SETUP_NEEDED:
if info.setup_url:
message = '<a href=%s>Setup needed at openid server.</a>' % info.setup_url
else:
message = 'More information needed at server'
return self._render_form(environ, start_response,
message=message)
else:
return self._render_form(environ, start_response,
message='Unable to process. Unknown error')
开发者ID:jdlrobson,项目名称:tiddlyweb-plugins,代码行数:33,代码来源:openid2.py
示例10: submit
def submit(environ, start_response):
"""
Take POSTed input, put it in a Tiddler and save
it into the store, and redirect back to the user
page.
"""
user = environ['tiddlyweb.usersign']['name']
if user == 'GUEST':
raise UserRequiredError, 'real user required to twote'
recent_recipe = _check_recipe('recent', environ, user)
all_recipe = _check_recipe('all', environ, user)
tiddler = _make_tiddler(environ, user)
bag = control.determine_bag_for_tiddler(all_recipe, tiddler)
tiddler.bag = bag.name
store = environ['tiddlyweb.store']
original_title = tiddler.title
tester_tiddler = Tiddler(original_title, bag=bag.name)
addendum = 2
while 1:
try:
tester_tiddler = store.get(tester_tiddler)
new_title = '%s-%s' % (original_title, addendum)
tiddler.title = new_title
tester_tiddler.title = new_title
addendum += 1
except NoTiddlerError:
store.put(tiddler)
break
raise HTTP302, '%s/twoter/%s' % (server_base_url(environ), urllib.quote(user))
开发者ID:moveek,项目名称:tiddlyweb-plugins,代码行数:35,代码来源:twoter.py
示例11: spowt
def spowt(environ, start_response):
username = environ['tiddlyweb.usersign']['name']
if username == 'GUEST':
template = template_env.get_template('spowt.html')
return template.generate()
else:
raise HTTP302('%s/spowt2/%s' % (server_base_url(environ), urllib.quote(username)))
开发者ID:FND,项目名称:tiddlyweb-plugins-1,代码行数:7,代码来源:spowt2.py
示例12: get_tiddler_edit
def get_tiddler_edit(environ, start_response):
usersign = environ["tiddlyweb.usersign"]
store = environ["tiddlyweb.store"]
title = environ["tiddlyweb.query"].get("title", [""])[0]
bag_name = environ["tiddlyweb.query"].get("bag", [""])[0]
username = usersign["name"]
if not "MEMBER" in usersign["roles"]:
raise HTTP404("bad edit")
if not title and not bag_name:
tiddler = get_profile(store, usersign, username)
page_title = "Edit Profile"
return_url = "%s/home" % server_base_url(environ)
elif not title:
tiddler = Tiddler("", bag_name)
page_title = "Edit New Tiddler"
return_url = ""
else:
tiddler = Tiddler(title, bag_name)
page_title = "Edit %s" % title
return_url = tiddler_url(environ, tiddler)
try:
tiddler = store.get(tiddler)
except StoreError:
pass
bag = Bag(tiddler.bag)
bag = store.get(bag)
bag.policy.allows(usersign, "write")
data = {}
data["tiddler"] = tiddler
data["return_url"] = return_url
data["title"] = page_title
return send_template(environ, "profile_edit.html", data)
开发者ID:pmario,项目名称:tiddlyhoster,代码行数:35,代码来源:__init__.py
示例13: home
def home(environ, start_response):
"""
If we go to the base of the wiki route, redirect to the FrontPage.
"""
config = environ["tiddlyweb.config"]
location = "%s%s/%s" % (server_base_url(environ), _route_base(config), _front_page(config))
raise HTTP302(location)
开发者ID:cdent,项目名称:tiddlytoys,代码行数:7,代码来源:__init__.py
示例14: tiddler_as
def tiddler_as(self, tiddler):
host = '%s/' % server_base_url(self.environ) # TODO: normalize?
title, bag = [encode_name(name) for name in (tiddler.title, tiddler.bag)]
namespaces = {
'': host,
'tweb': 'http://tiddlyweb.com/'
}
subject = ':bags/%s/%s' % (bag, title)
rdf_data = {
subject: {
'rdf:type': ['tweb:tiddler'],
'tweb:bag': [':bags/%s' % bag]
}
}
for field, value in tiddler.fields.items():
try:
prefix, suffix = field.split(':')
# TODO: use collections.defaultdict
rdf_data[subject] = rdf_data.get(subject) or {}
rdf_data[subject][field] = rdf_data[subject].get(field) or []
rdf_data[subject][field].append(value)
except ValueError: # not RDF-related
pass
return to_turtle(namespaces, rdf_data)
开发者ID:FND,项目名称:tiddlywebplugins.rdf,代码行数:28,代码来源:__init__.py
示例15: _tiddler_as_div
def _tiddler_as_div(self, tiddler):
"""
Read in the tiddler from a div.
"""
recipe_name = ''
if tiddler.recipe:
recipe_name = tiddler.recipe
try:
host = server_base_url(self.environ)
except KeyError:
host = ''
host = '%s/' % host
if tiddler.type and tiddler.type != 'None':
tiddler_output = self._binary_tiddler(tiddler)
else:
tiddler_output = tiddler.text
return ('<div title="%s" server.title="%s" server.page.revision="%s" '
'modifier="%s" server.workspace="bags/%s" '
'server.type="tiddlyweb" server.host="%s" '
'server.recipe="%s" server.bag="%s" server.permissions="%s" '
'modified="%s" created="%s" tags="%s" %s>\n'
'<pre>%s</pre>\n</div>\n'
% (tiddler.title, tiddler.title, tiddler.revision,
tiddler.modifier, tiddler.bag, host, recipe_name,
tiddler.bag, self._tiddler_permissions(tiddler),
tiddler.modified, tiddler.created,
self.tags_as(tiddler.tags),
self._tiddler_fields(tiddler.fields),
self._html_encode(tiddler_output)))
开发者ID:angeluseve,项目名称:tiddlyweb,代码行数:31,代码来源:wiki.py
示例16: create_app
def create_app(environ, start_response):
"""
At the provider, register a client and provide them with
an id, secret, etc.
This is not part of the oAuth spec, but is fairly standard
form for what is usually called "creating an app".
On success redirects to the info page for the app.
"""
query = environ['tiddlyweb.query']
current_user = environ['tiddlyweb.usersign']['name']
data = {}
for key in ['name', 'app_url', 'callback_url', 'logo']:
if key in query:
data[key] = query[key][0]
data['owner'] = current_user
try:
app_tiddler = create(**data)
except TypeError as exc:
raise HTTP400('Invalid form submission: %s' % exc)
# let a store error raise to a 500 (for now)
app_tiddler = store_app(environ, app_tiddler)
raise HTTP303(server_base_url(environ)
+ '/_oauth/appinfo?app=%s' % app_tiddler.title)
开发者ID:cdent,项目名称:tiddlywebplugins.oauth,代码行数:28,代码来源:client.py
示例17: _manage_update_routes
def _manage_update_routes(environ, gym):
"""
Update routes with new information.
"""
store = environ['tiddlyweb.store']
query = environ['tiddlyweb.query']
existing_titles = query.get('title', [])
count = len(existing_titles)
index = 0
delete = query.get('delete', [])
lead_route = query.get(LEAD_FIELD, [])
while index < count:
title = existing_titles[index]
tiddler = Tiddler(title, '%s_climbs' % gym)
try:
tiddler = store.get(tiddler)
if title in delete:
original_bag = tiddler.bag
tiddler.bag = '%s_archive' % gym
store.put(tiddler)
tiddler.bag = original_bag
store.delete(tiddler)
index += 1
continue
except StoreError:
pass
changed = False
for key in ROUTE_FIELDS:
value = query.get(key, [''])[index]
if tiddler.fields[key] != value:
tiddler.fields[key] = value
changed = True
if LEAD_FIELD in tiddler.fields and title not in lead_route:
del tiddler.fields[LEAD_FIELD]
changed = True
elif title in lead_route and LEAD_FIELD not in tiddler.fields:
tiddler.fields[LEAD_FIELD] = '1'
changed = True
if changed:
store.put(tiddler)
index += 1
try:
title = query.get('title', [])[index]
except IndexError:
title = str(uuid4())
tiddler = Tiddler(title, '%s_climbs' % gym)
new_route = False
if 'new_one' in lead_route:
tiddler.fields[LEAD_FIELD] = '1'
for key in ROUTE_FIELDS:
value = query.get(key, [''])[index]
if value == '':
continue
new_route = True
tiddler.fields[key] = value
if new_route:
store.put(tiddler)
raise HTTP303(server_base_url(environ) + '/manager/%s' % gym)
开发者ID:cdent,项目名称:nitor,代码行数:59,代码来源:__init__.py
示例18: _manage_create_news
def _manage_create_news(environ, gym):
store = environ['tiddlyweb.store']
news = environ['tiddlyweb.query'].get('news', [''])[0]
tiddler = Tiddler(str(uuid4()), '%s_news' % gym)
tiddler.text = news
tiddler.type = TIDDLER_TYPE
store.put(tiddler)
raise HTTP303(server_base_url(environ) + '/manager/%s' % gym)
开发者ID:FND,项目名称:nitor,代码行数:8,代码来源:__init__.py
示例19: _get_config
def _get_config(self):
json = {"workspace": self._get_container(),
"host": server_base_url(self.environ)}
return '''\
<script id="tiddlywikiconfig" type="application/json">
%s
</script>
''' % (simplejson.dumps(json))
开发者ID:cdent,项目名称:otw,代码行数:8,代码来源:serialization.py
示例20: _manage_update_gym
def _manage_update_gym(environ, gym):
"""
Update the gym information.
"""
tiddler = Tiddler(gym, GYMS_BAG)
_update_gym_info(environ, tiddler)
raise HTTP303(server_base_url(environ) + '/manager/%s' % gym)
开发者ID:cdent,项目名称:nitor,代码行数:8,代码来源:__init__.py
注:本文中的tiddlyweb.web.util.server_base_url函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论