32 lines
805 B
Python
32 lines
805 B
Python
import urllib
|
|
|
|
from functools import wraps
|
|
|
|
|
|
def parse_namespace_repository(repository):
|
|
parts = repository.rstrip('/').split('/', 1)
|
|
if len(parts) < 2:
|
|
namespace = 'library'
|
|
repository = parts[0]
|
|
else:
|
|
(namespace, repository) = parts
|
|
repository = urllib.quote_plus(repository)
|
|
return (namespace, repository)
|
|
|
|
|
|
def parse_repository_name(f):
|
|
@wraps(f)
|
|
def wrapper(repository, *args, **kwargs):
|
|
(namespace, repository) = parse_namespace_repository(repository)
|
|
return f(namespace, repository, *args, **kwargs)
|
|
return wrapper
|
|
|
|
|
|
def format_robot_username(parent_username, robot_shortname):
|
|
return '%s+%s' % (parent_username, robot_shortname)
|
|
|
|
def parse_robot_username(robot_username):
|
|
if not '+' in robot_username:
|
|
return None
|
|
|
|
return robot_username.split('+', 2)
|