Skip to content
Open
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
11 changes: 6 additions & 5 deletions bingads/service_client.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from suds.client import Client, Factory, WebFault, ObjectCache # noqa
from suds.client import Client, Factory, WebFault # noqa

from .headerplugin import HeaderPlugin
from .authorization import *
from .service_info import SERVICE_INFO_DICT
from .manifest import USER_AGENT
from .util import DictCache
from getpass import getuser
from tempfile import gettempdir
from os import path
Expand Down Expand Up @@ -31,10 +32,9 @@ def __init__(self, service, version, authorization_data=None, environment='produ
self._refresh_oauth_tokens_automatically = True
self._version = ServiceClient._format_version(version)

# TODO This is a temp fix for set default suds temp folder with user info, suds development branch has already fixed it.
# Use in-memory cache by default.
if 'cache' not in suds_options:
location = path.join(gettempdir(), 'suds', getuser())
suds_options['cache'] = ObjectCache(location, days=1)
suds_options['cache'] = DictCache()
# set cachingpolicy to 1 to reuse WSDL cache files, otherwise will only reuse XML files
if 'cachingpolicy' not in suds_options:
suds_options['cachingpolicy'] = 1
Expand Down Expand Up @@ -292,7 +292,8 @@ def name(self):


_CAMPAIGN_MANAGEMENT_SERVICE_V12 = Client(
'file:///' + pkg_resources.resource_filename('bingads', 'v12/proxies/campaign_management_service.xml')
'file:///' + pkg_resources.resource_filename('bingads', 'v12/proxies/campaign_management_service.xml'),
cache=DictCache()
)
_CAMPAIGN_OBJECT_FACTORY_V12 = _CAMPAIGN_MANAGEMENT_SERVICE_V12.factory
# TODO Better to push suds-jurko accept this caching
Expand Down
12 changes: 12 additions & 0 deletions bingads/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import time
from bingads.exceptions import TimeoutException
from suds.client import WebFault
from suds.cache import Cache


class DictCache(dict, Cache):
# .get and .clear work as intended

purge = dict.__delitem__

def put(self, id_, obj):
self[id_] = obj
return obj


class _TimeHelper(object):
"""
Expand Down