From f6af7beeaa8fda72df800cb27d8e4669bae77cf9 Mon Sep 17 00:00:00 2001 From: selurvedu Date: Fri, 17 Jun 2016 19:34:23 +0000 Subject: [PATCH 1/2] Fix minor formatting issues reported by Flake8 --- openprocurement_client/client.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/openprocurement_client/client.py b/openprocurement_client/client.py index baa6d68..4c19b75 100644 --- a/openprocurement_client/client.py +++ b/openprocurement_client/client.py @@ -1,13 +1,19 @@ +import logging from functools import wraps +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__) @@ -140,6 +146,7 @@ def _delete_resource_item(self, url, headers={}): return munchify(loads(response_item.body_string())) raise InvalidResponse + class TendersClient(APIBaseClient): """client for tenders""" @@ -148,7 +155,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 @@ -546,6 +553,7 @@ def delete_lot(self, tender, lot): ) ########################################################################### + class Client(TendersClient): """client for tenders for backward compatibility""" From 46daadb47e36f9068de5f7bb79325b6da076c6af Mon Sep 17 00:00:00 2001 From: selurvedu Date: Fri, 17 Jun 2016 19:36:00 +0000 Subject: [PATCH 2/2] Provide basename of file instead of full path This makes op.client upload a file with an normal filename instead of a full file path. --- openprocurement_client/client.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/openprocurement_client/client.py b/openprocurement_client/client.py index 4c19b75..48118f0 100644 --- a/openprocurement_client/client.py +++ b/openprocurement_client/client.py @@ -1,5 +1,7 @@ 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 @@ -24,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)