Skip to content

Commit

Permalink
[AIRFLOW-4386] Remove urlparse and replace it with urllib.parse (#5154)
Browse files Browse the repository at this point in the history
* [AIRFLOW-4386] Remove urlparse and replace it with urllib.parse

* Replace remaining imports

* Update test_utils.py
  • Loading branch information
kaxil authored and XD-DENG committed Apr 23, 2019
1 parent 831c29c commit c95810d
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 41 deletions.
3 changes: 1 addition & 2 deletions airflow/contrib/example_dags/example_gcp_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"""

import os
from urllib.parse import urlsplit

import airflow
from airflow import models
Expand All @@ -41,8 +42,6 @@
GoogleCloudStorageBucketCreateAclEntryOperator, \
GoogleCloudStorageObjectCreateAclEntryOperator

from six.moves.urllib.parse import urlsplit

# [START howto_operator_cloudsql_arguments]
GCP_PROJECT_ID = os.environ.get('GCP_PROJECT_ID', 'example-project')
INSTANCE_NAME = os.environ.get('GCSQL_MYSQL_INSTANCE_NAME', 'test-mysql')
Expand Down
3 changes: 1 addition & 2 deletions airflow/contrib/example_dags/example_gcp_sql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
import os
import subprocess
from os.path import expanduser

from six.moves.urllib.parse import quote_plus
from urllib.parse import quote_plus

import airflow
from airflow import models
Expand Down
2 changes: 1 addition & 1 deletion airflow/contrib/hooks/gcp_sql_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

from googleapiclient.errors import HttpError
from subprocess import Popen, PIPE
from six.moves.urllib.parse import quote_plus
from urllib.parse import quote_plus

import requests
from googleapiclient.discovery import build
Expand Down
7 changes: 1 addition & 6 deletions airflow/contrib/hooks/gcs_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import shutil

from google.cloud import storage
from urllib.parse import urlparse

from airflow.contrib.hooks.gcp_api_base_hook import GoogleCloudBaseHook
from airflow.exceptions import AirflowException
Expand Down Expand Up @@ -554,12 +555,6 @@ def _parse_gcs_url(gsurl):
Given a Google Cloud Storage URL (gs://<bucket>/<blob>), returns a
tuple containing the corresponding bucket and blob.
"""
# Python 3
try:
from urllib.parse import urlparse
# Python 2
except ImportError:
from urlparse import urlparse

parsed_url = urlparse(gsurl)
if not parsed_url.netloc:
Expand Down
2 changes: 1 addition & 1 deletion airflow/contrib/utils/mlengine_operator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from airflow.contrib.operators.dataflow_operator import DataFlowPythonOperator
from airflow.exceptions import AirflowException
from airflow.operators.python_operator import PythonOperator
from six.moves.urllib.parse import urlsplit
from urllib.parse import urlsplit


def create_evaluate_ops(task_prefix,
Expand Down
10 changes: 2 additions & 8 deletions airflow/utils/log/gcs_task_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
import os

from cached_property import cached_property
from urllib.parse import urlparse

from airflow import configuration
from airflow.exceptions import AirflowException
from airflow.utils.log.logging_mixin import LoggingMixin
from airflow.utils.log.file_task_handler import FileTaskHandler
from airflow.utils.log.logging_mixin import LoggingMixin


class GCSTaskHandler(FileTaskHandler, LoggingMixin):
Expand Down Expand Up @@ -167,13 +168,6 @@ def parse_gcs_url(gsurl):
Given a Google Cloud Storage URL (gs://<bucket>/<blob>), returns a
tuple containing the corresponding bucket and blob.
"""
# Python 3
try:
from urllib.parse import urlparse
# Python 2
except ImportError:
from urlparse import urlparse

parsed_url = urlparse(gsurl)
if not parsed_url.netloc:
raise AirflowException('Please provide a bucket name')
Expand Down
10 changes: 5 additions & 5 deletions airflow/www/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
#
import logging
import socket
from typing import Any

from flask import Flask
from flask_appbuilder import AppBuilder, SQLA
from flask_caching import Cache
from flask_wtf.csrf import CSRFProtect
from six.moves.urllib.parse import urlparse
from werkzeug.wsgi import DispatcherMiddleware
from typing import Any
from urllib.parse import urlparse
from werkzeug.contrib.fixers import ProxyFix
from werkzeug.wsgi import DispatcherMiddleware

from airflow import settings
from airflow import configuration as conf
from airflow import settings
from airflow.logging_config import configure_logging
from airflow.www.static_config import configure_manifest_files
from airflow.utils.json import AirflowJsonEncoder
from airflow.www.static_config import configure_manifest_files

app = None # type: Any
appbuilder = None
Expand Down
2 changes: 1 addition & 1 deletion airflow/www/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from flask_appbuilder.models.sqla.interface import SQLAInterface
import flask_appbuilder.models.sqla.filters as fab_sqlafilters
import sqlalchemy as sqla
from six.moves.urllib.parse import urlencode
from urllib.parse import urlencode

from airflow import configuration
from airflow.models import BaseOperator
Expand Down
17 changes: 7 additions & 10 deletions tests/contrib/hooks/test_gcp_mlengine_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,17 @@
# under the License.

import json
import mock
import unittest

try: # python 2
from urlparse import urlparse, parse_qsl
except ImportError: # python 3
from urllib.parse import urlparse, parse_qsl

from airflow.contrib.hooks import gcp_mlengine_hook as hook
from googleapiclient.errors import HttpError
import mock
import requests
from google.auth.exceptions import GoogleAuthError
from googleapiclient.discovery import build_from_document
from googleapiclient.errors import HttpError
from googleapiclient.http import HttpMockSequence
from google.auth.exceptions import GoogleAuthError
import requests
from urllib.parse import urlparse, parse_qsl

from airflow.contrib.hooks import gcp_mlengine_hook as hook

cml_available = True
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import time

from six.moves.urllib.parse import urlsplit
from urllib.parse import urlsplit

from tests.contrib.utils.base_gcp_system_test_case import RetrieveVariables
from tests.contrib.utils.gcp_authenticator import GcpAuthenticator, GCP_CLOUDSQL_KEY
Expand Down
7 changes: 3 additions & 4 deletions tests/www/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
# specific language governing permissions and limitations
# under the License.

import unittest
from datetime import datetime
from urllib.parse import parse_qs

from bs4 import BeautifulSoup
import mock
from six.moves.urllib.parse import parse_qs
from bs4 import BeautifulSoup

from airflow.www import utils

import unittest


class UtilsTest(unittest.TestCase):
def test_empty_variable_should_not_be_hidden(self):
Expand Down

0 comments on commit c95810d

Please sign in to comment.