Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Use six.moves.urlparse #3108

Merged
merged 1 commit into from
Apr 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions synapse/config/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
from synapse.appservice import ApplicationService
from synapse.types import UserID

import urllib
import yaml
import logging

from six import string_types
from six.moves.urllib import parse as urlparse

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -105,7 +105,7 @@ def _load_appservice(hostname, as_info, config_filename):
)

localpart = as_info["sender_localpart"]
if urllib.quote(localpart) != localpart:
if urlparse.quote(localpart) != localpart:
raise ValueError(
"sender_localpart needs characters which are not URL encoded."
)
Expand Down
3 changes: 1 addition & 2 deletions synapse/http/matrixfederationclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
import random
import sys
import urllib
import urlparse

from six.moves.urllib import parse as urlparse

logger = logging.getLogger(__name__)
outbound_logger = logging.getLogger("synapse.http.outbound")
Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/client/v1/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import simplejson as json
import urllib
import urlparse
from six.moves.urllib import parse as urlparse

import logging
from saml2 import BINDING_HTTP_POST
Expand Down
9 changes: 5 additions & 4 deletions synapse/rest/client/v1/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
parse_json_object_from_request, parse_string, parse_integer
)

from six.moves.urllib import parse as urlparse

import logging
import urllib
import simplejson as json

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -433,7 +434,7 @@ def on_GET(self, request, room_id):
as_client_event = "raw" not in request.args
filter_bytes = request.args.get("filter", None)
if filter_bytes:
filter_json = urllib.unquote(filter_bytes[-1]).decode("UTF-8")
filter_json = urlparse.unquote(filter_bytes[-1]).decode("UTF-8")
event_filter = Filter(json.loads(filter_json))
else:
event_filter = None
Expand Down Expand Up @@ -718,8 +719,8 @@ def __init__(self, hs):
def on_PUT(self, request, room_id, user_id):
requester = yield self.auth.get_user_by_req(request)

room_id = urllib.unquote(room_id)
target_user = UserID.from_string(urllib.unquote(user_id))
room_id = urlparse.unquote(room_id)
target_user = UserID.from_string(urlparse.unquote(user_id))

content = parse_json_object_from_request(request)

Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/media/v1/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import logging
import urllib
import urlparse
from six.moves.urllib import parse as urlparse

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/media/v1/media_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

import cgi
import logging
import urlparse
from six.moves.urllib import parse as urlparse

logger = logging.getLogger(__name__)

Expand Down
14 changes: 7 additions & 7 deletions tests/rest/client/v1/test_rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from synapse.types import UserID

import json
import urllib
from six.moves.urllib import parse as urlparse

from ....utils import MockHttpResource, setup_test_homeserver
from .utils import RestTestCase
Expand Down Expand Up @@ -766,7 +766,7 @@ def test_invalid_puts(self):
@defer.inlineCallbacks
def test_rooms_members_self(self):
path = "/rooms/%s/state/m.room.member/%s" % (
urllib.quote(self.room_id), self.user_id
urlparse.quote(self.room_id), self.user_id
)

# valid join message (NOOP since we made the room)
Expand All @@ -786,7 +786,7 @@ def test_rooms_members_self(self):
def test_rooms_members_other(self):
self.other_id = "@zzsid1:red"
path = "/rooms/%s/state/m.room.member/%s" % (
urllib.quote(self.room_id), self.other_id
urlparse.quote(self.room_id), self.other_id
)

# valid invite message
Expand All @@ -802,7 +802,7 @@ def test_rooms_members_other(self):
def test_rooms_members_other_custom_keys(self):
self.other_id = "@zzsid1:red"
path = "/rooms/%s/state/m.room.member/%s" % (
urllib.quote(self.room_id), self.other_id
urlparse.quote(self.room_id), self.other_id
)

# valid invite message with custom key
Expand Down Expand Up @@ -859,7 +859,7 @@ def tearDown(self):
@defer.inlineCallbacks
def test_invalid_puts(self):
path = "/rooms/%s/send/m.room.message/mid1" % (
urllib.quote(self.room_id))
urlparse.quote(self.room_id))
# missing keys or invalid json
(code, response) = yield self.mock_resource.trigger(
"PUT", path, '{}'
Expand Down Expand Up @@ -894,7 +894,7 @@ def test_invalid_puts(self):
@defer.inlineCallbacks
def test_rooms_messages_sent(self):
path = "/rooms/%s/send/m.room.message/mid1" % (
urllib.quote(self.room_id))
urlparse.quote(self.room_id))

content = '{"body":"test","msgtype":{"type":"a"}}'
(code, response) = yield self.mock_resource.trigger("PUT", path, content)
Expand All @@ -911,7 +911,7 @@ def test_rooms_messages_sent(self):

# m.text message type
path = "/rooms/%s/send/m.room.message/mid2" % (
urllib.quote(self.room_id))
urlparse.quote(self.room_id))
content = '{"body":"test2","msgtype":"m.text"}'
(code, response) = yield self.mock_resource.trigger("PUT", path, content)
self.assertEquals(200, code, msg=str(response))
Expand Down
5 changes: 2 additions & 3 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

import hashlib
from inspect import getcallargs
import urllib
import urlparse
from six.moves.urllib import parse as urlparse

from mock import Mock, patch
from twisted.internet import defer, reactor
Expand Down Expand Up @@ -234,7 +233,7 @@ def trigger(self, http_method, path, content, mock_request, federation_auth=Fals
if matcher:
try:
args = [
urllib.unquote(u).decode("UTF-8")
urlparse.unquote(u).decode("UTF-8")
for u in matcher.groups()
]

Expand Down