Repository: incubator-airflow
Updated Branches:
  refs/heads/master 39adc77f6 -> 78da52fee


[AIRFLOW-2739] Always read default configuration files as utf-8

Closes #3593 from cjgu/airflow-2739


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/78da52fe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/78da52fe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/78da52fe

Branch: refs/heads/master
Commit: 78da52fee477b0f7b2ee3481d32a06fca7a9841c
Parents: 39adc77
Author: Carl Johan Gustavsson <[email protected]>
Authored: Fri Jul 13 11:58:39 2018 +0200
Committer: Bolke de Bruin <[email protected]>
Committed: Fri Jul 13 11:58:39 2018 +0200

----------------------------------------------------------------------
 airflow/configuration.py | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/78da52fe/airflow/configuration.py
----------------------------------------------------------------------
diff --git a/airflow/configuration.py b/airflow/configuration.py
index e2089e5..2e05fde 100644
--- a/airflow/configuration.py
+++ b/airflow/configuration.py
@@ -101,15 +101,20 @@ def run_command(command):
     return output
 
 
-_templates_dir = os.path.join(os.path.dirname(__file__), 'config_templates')
-with open(os.path.join(_templates_dir, 'default_airflow.cfg')) as f:
-    DEFAULT_CONFIG = f.read()
+def _read_default_config_file(file_name):
+    templates_dir = os.path.join(os.path.dirname(__file__), 'config_templates')
+    file_path = os.path.join(templates_dir, file_name)
     if six.PY2:
-        DEFAULT_CONFIG = DEFAULT_CONFIG.decode('utf-8')
-with open(os.path.join(_templates_dir, 'default_test.cfg')) as f:
-    TEST_CONFIG = f.read()
-    if six.PY2:
-        TEST_CONFIG = TEST_CONFIG.decode('utf-8')
+        with open(file_path) as f:
+            config = f.read()
+            return config.decode('utf-8')
+    else:
+        with open(file_path, encoding='utf-8') as f:
+            return f.read()
+
+
+DEFAULT_CONFIG = _read_default_config_file('default_airflow.cfg')
+TEST_CONFIG = _read_default_config_file('default_test.cfg')
 
 
 class AirflowConfigParser(ConfigParser):
@@ -502,8 +507,7 @@ conf.read(AIRFLOW_CONFIG)
 
 
 if conf.getboolean('webserver', 'rbac'):
-    with open(os.path.join(_templates_dir, 'default_webserver_config.py')) as 
f:
-        DEFAULT_WEBSERVER_CONFIG = f.read()
+    DEFAULT_WEBSERVER_CONFIG = 
_read_default_config_file('default_webserver_config.py')
 
     WEBSERVER_CONFIG = AIRFLOW_HOME + '/webserver_config.py'
 

Reply via email to