Skip to content
Merged
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
38 changes: 32 additions & 6 deletions openprocurement_client/client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import logging
from functools import wraps
from io import FileIO
from os import path
from urlparse import parse_qs, urlparse

from iso8601 import parse_date

from munch import munchify
from restkit import BasicAuth, request, Resource

from restkit import BasicAuth, Resource, request
from restkit.errors import ResourceNotFound

from retrying import retry

from simplejson import dumps, loads
from urlparse import parse_qs, urlparse
import logging
from openprocurement_client.exceptions import InvalidResponse, NoToken

from .exceptions import InvalidResponse, NoToken

logger = logging.getLogger(__name__)

Expand All @@ -18,7 +26,23 @@ def verify_file(fn):
@wraps(fn)
def wrapper(self, file_, *args, **kwargs):
if isinstance(file_, str):
file_ = open(file_, 'rb')
# Using FileIO here instead of open()
# to be able to override the filename
# which is later used when uploading the file.
#
# Explanation:
#
# 1) Restkit reads the filename
# from "name" attribute of a file-like object,
# there is no other way to specify a filename;
#
# 2) The attribute may contain the full path to file,
# which does not work well as a filename;
#
# 3) The attribute is readonly when using open(),
# unlike FileIO object.
file_ = FileIO(file_, 'rb')
file_.name = path.basename(file_.name)
if hasattr(file_, 'read'):
# A file-like object must have 'read' method
return fn(self, file_, *args, **kwargs)
Expand Down Expand Up @@ -140,6 +164,7 @@ def _delete_resource_item(self, url, headers={}):
return munchify(loads(response_item.body_string()))
raise InvalidResponse


class TendersClient(APIBaseClient):
"""client for tenders"""

Expand All @@ -148,7 +173,7 @@ def __init__(self, key,
api_version='2.0',
params=None,
resource='tenders'):
super(TendersClient, self).__init__(key, host_url,api_version, resource, params)
super(TendersClient, self).__init__(key, host_url, api_version, resource, params)

###########################################################################
# GET ITEMS LIST API METHODS
Expand Down Expand Up @@ -546,6 +571,7 @@ def delete_lot(self, tender, lot):
)
###########################################################################


class Client(TendersClient):
"""client for tenders for backward compatibility"""

Expand Down