Skip to content

Commit

Permalink
Use posixpath instead of os.path where appropriate
Browse files Browse the repository at this point in the history
This guarantees that join() will be performed using forward slashes.
  • Loading branch information
nOOb3167 committed Jun 18, 2021
1 parent 07b9d44 commit 84d8a8c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions giftless/storage/amazon_s3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
import posixpath
from typing import Any, BinaryIO, Dict, Iterable, Optional

import boto3 # type: ignore
Expand Down Expand Up @@ -112,7 +112,7 @@ def _get_blob_path(self, prefix: str, oid: str) -> str:
storage_prefix = self.path_prefix[1:]
else:
storage_prefix = self.path_prefix
return os.path.join(storage_prefix, prefix, oid)
return posixpath.join(storage_prefix, prefix, oid)

def _s3_object(self, prefix, oid):
return self.s3.Object(self.bucket_name, self._get_blob_path(prefix, oid))
4 changes: 2 additions & 2 deletions giftless/storage/azure.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import base64
import logging
import os
import posixpath
from collections import namedtuple
from datetime import datetime, timedelta, timezone
from typing import Any, BinaryIO, Dict, Iterable, List, Optional
Expand Down Expand Up @@ -163,7 +163,7 @@ def _get_blob_path(self, prefix: str, oid: str) -> str:
storage_prefix = self.path_prefix[1:]
else:
storage_prefix = self.path_prefix
return os.path.join(storage_prefix, prefix, oid)
return posixpath.join(storage_prefix, prefix, oid)

def _get_signed_url(self, prefix: str, oid: str, expires_in: int, filename: Optional[str] = None,
disposition: Optional[str] = None, **permissions: bool) -> str:
Expand Down
4 changes: 2 additions & 2 deletions giftless/storage/google_cloud.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import base64
import io
import json
import os
import posixpath
from datetime import timedelta
from typing import Any, BinaryIO, Dict, Optional

Expand Down Expand Up @@ -90,7 +90,7 @@ def _get_blob_path(self, prefix: str, oid: str) -> str:
storage_prefix = self.path_prefix[1:]
else:
storage_prefix = self.path_prefix
return os.path.join(storage_prefix, prefix, oid)
return posixpath.join(storage_prefix, prefix, oid)

def _get_signed_url(self, prefix: str, oid: str, expires_in: int, http_method: str = 'GET',
filename: Optional[str] = None, disposition: Optional[str] = None) -> str:
Expand Down
6 changes: 3 additions & 3 deletions giftless/transfer/basic_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
implement the `ExternalStorage` interface defined here.
"""

import os
import posixpath
from typing import Any, Dict, Optional

from giftless.storage import ExternalStorage, exc
Expand All @@ -27,7 +27,7 @@ def __init__(self, storage: ExternalStorage, default_action_lifetime: int):
self.action_lifetime = default_action_lifetime

def upload(self, organization: str, repo: str, oid: str, size: int, extra: Optional[Dict[str, Any]] = None) -> Dict:
prefix = os.path.join(organization, repo)
prefix = posixpath.join(organization, repo)
response = {"oid": oid,
"size": size}

Expand All @@ -50,7 +50,7 @@ def upload(self, organization: str, repo: str, oid: str, size: int, extra: Optio

def download(self, organization: str, repo: str, oid: str, size: int,
extra: Optional[Dict[str, Any]] = None) -> Dict:
prefix = os.path.join(organization, repo)
prefix = posixpath.join(organization, repo)
response = {"oid": oid,
"size": size}

Expand Down
10 changes: 5 additions & 5 deletions giftless/transfer/basic_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
interface through which additional streaming backends can be implemented.
"""

import os
import posixpath
from typing import Any, Dict, Optional

from flask import Response, request, url_for
Expand Down Expand Up @@ -41,7 +41,7 @@ def verify(self, organization, repo):

self._check_authorization(organization, repo, Permission.READ_META, oid=payload['oid'])

prefix = os.path.join(organization, repo)
prefix = posixpath.join(organization, repo)
if not self.storage.verify_object(prefix, payload['oid'], payload['size']):
raise InvalidPayload("Object does not exist or size does not match")
return Response(status=200)
Expand Down Expand Up @@ -79,7 +79,7 @@ def get(self, organization, repo, oid):
"""Get an file open file stream from local storage
"""
self._check_authorization(organization, repo, Permission.READ, oid=oid)
path = os.path.join(organization, repo)
path = posixpath.join(organization, repo)

filename = request.args.get('filename')
filename = safe_filename(filename)
Expand Down Expand Up @@ -118,7 +118,7 @@ def upload(self, organization: str, repo: str, oid: str, size: int, extra: Optio
response = {"oid": oid,
"size": size}

prefix = os.path.join(organization, repo)
prefix = posixpath.join(organization, repo)
if not self.storage.exists(prefix, oid) or self.storage.get_size(prefix, oid) != size:
response['actions'] = {
"upload": {
Expand All @@ -142,7 +142,7 @@ def download(self, organization: str, repo: str, oid: str, size: int,
response = {"oid": oid,
"size": size}

prefix = os.path.join(organization, repo)
prefix = posixpath.join(organization, repo)
if not self.storage.exists(prefix, oid):
response['error'] = {
"code": 404,
Expand Down
6 changes: 3 additions & 3 deletions giftless/transfer/multipart.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Multipart Transfer Adapter
"""

import os
import posixpath
from typing import Any, Dict, Optional

from giftless.storage import MultipartStorage, exc
Expand All @@ -21,7 +21,7 @@ def __init__(self, storage: MultipartStorage, default_action_lifetime: int, max_
self.action_lifetime = default_action_lifetime

def upload(self, organization: str, repo: str, oid: str, size: int, extra: Optional[Dict[str, Any]] = None) -> Dict:
prefix = os.path.join(organization, repo)
prefix = posixpath.join(organization, repo)
response = {"oid": oid,
"size": size}

Expand All @@ -45,7 +45,7 @@ def upload(self, organization: str, repo: str, oid: str, size: int, extra: Optio

def download(self, organization: str, repo: str, oid: str, size: int,
extra: Optional[Dict[str, Any]] = None) -> Dict:
prefix = os.path.join(organization, repo)
prefix = posixpath.join(organization, repo)
response = {"oid": oid,
"size": size}

Expand Down

0 comments on commit 84d8a8c

Please sign in to comment.