adding translations and transifex third party tool
[pub/Android/ownCloud.git] / third_party / transifex-client / txclib / processors.py
1 # -*- coding: utf-8 -*-
2
3 """
4 Module for API-related calls.
5 """
6
7 import urlparse
8
9
10 def hostname_tld_migration(hostname):
11 """
12 Migrate transifex.net to transifex.com.
13
14 :param hostname: The hostname to migrate (if needed).
15 :returns: A hostname with the transifex.com domain (if needed).
16 """
17 parts = urlparse.urlparse(hostname)
18 if parts.hostname.endswith('transifex.net'):
19 hostname = hostname.replace('transifex.net', 'transifex.com', 1)
20 return hostname
21
22
23 def hostname_ssl_migration(hostname):
24 """
25 Migrate Transifex hostnames to use HTTPS.
26
27 :param hostname: The hostname to migrate (if needed).
28 :returns: A https hostname (if needed).
29 """
30 parts = urlparse.urlparse(hostname)
31 is_transifex = (
32 parts.hostname[-14:-3] == '.transifex.' or
33 parts.hostname == 'transifex.net' or
34 parts.hostname == 'transifex.com'
35 )
36 is_https = parts.scheme == 'https'
37 if is_transifex and not is_https:
38 if not parts.scheme:
39 hostname = 'https:' + hostname
40 else:
41 hostname = hostname.replace(parts.scheme, 'https', 1)
42 return hostname
43
44
45 def visit_hostname(hostname):
46 """
47 Have a chance to visit a hostname before actually using it.
48
49 :param hostname: The original hostname.
50 :returns: The hostname with the necessary changes.
51 """
52 for processor in [hostname_ssl_migration, hostname_tld_migration, ]:
53 hostname = processor(hostname)
54 return hostname