1 # -*- coding: utf-8 -*-
4 Module for API-related calls.
10 def hostname_tld_migration(hostname
):
12 Migrate transifex.net to transifex.com.
14 :param hostname: The hostname to migrate (if needed).
15 :returns: A hostname with the transifex.com domain (if needed).
17 parts
= urlparse
.urlparse(hostname
)
18 if parts
.hostname
.endswith('transifex.net'):
19 hostname
= hostname
.replace('transifex.net', 'transifex.com', 1)
23 def hostname_ssl_migration(hostname
):
25 Migrate Transifex hostnames to use HTTPS.
27 :param hostname: The hostname to migrate (if needed).
28 :returns: A https hostname (if needed).
30 parts
= urlparse
.urlparse(hostname
)
32 parts
.hostname
[-14:-3] == '.transifex.' or
33 parts
.hostname
== 'transifex.net' or
34 parts
.hostname
== 'transifex.com'
36 is_https
= parts
.scheme
== 'https'
37 if is_transifex
and not is_https
:
39 hostname
= 'https:' + hostname
41 hostname
= hostname
.replace(parts
.scheme
, 'https', 1)
45 def visit_hostname(hostname
):
47 Have a chance to visit a hostname before actually using it.
49 :param hostname: The original hostname.
50 :returns: The hostname with the necessary changes.
52 for processor
in [hostname_ssl_migration
, hostname_tld_migration
, ]:
53 hostname
= processor(hostname
)