Skip to content

Commit 3100656

Browse files
feat(apiclient): allow to specify additional libraries via setUserAgent
1 parent 202ed3e commit 3100656

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

hexonet/apiconnector/apiclient.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,18 @@ def getUserAgent(self):
133133
self.__ua = "%s (%s; %s; rv:%s) python/%s" % (pid, pf, arch, self.getVersion(), pyv)
134134
return self.__ua
135135

136-
def setUserAgent(self, pid, rv):
136+
def setUserAgent(self, pid, rv, modules=[]):
137137
"""
138138
Possibility to customize default user agent to fit your needs by given string and revision
139139
"""
140+
s = " "
141+
mods = ""
142+
if len(modules) > 0:
143+
mods += " " + s.join(modules)
140144
pyv = platform.python_version()
141145
pf = platform.system()
142146
arch = platform.architecture()[0]
143-
self.__ua = "%s (%s; %s; rv:%s) python-sdk/%s python/%s" % (pid, pf, arch, rv, self.getVersion(), pyv)
147+
self.__ua = "%s (%s; %s; rv:%s)%s python-sdk/%s python/%s" % (pid, pf, arch, rv, mods, self.getVersion(), pyv)
144148
return self
145149

146150
def getVersion(self):

tests/test_apiclient.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ def test_apiclientmethods():
141141
assert isinstance(cl2, AC) is True
142142
assert cl.getUserAgent() == ua
143143

144+
mods = ["reg/2.6.2", "ssl/7.2.2", "dc/8.2.2"]
145+
ua = "%s (%s; %s; rv:%s) %s %s/%s python/%s" % (pid, pf, arch, rv, " ".join(mods), pid2, cl.getVersion(), pyv)
146+
cl2 = cl.setUserAgent(pid, rv, mods)
147+
assert isinstance(cl2, AC) is True
148+
assert cl.getUserAgent() == ua
149+
144150
# #.setURL()
145151
tmp = ISPAPI_CONNECTION_URL_PROXY
146152
url = cl.setURL(tmp).getURL()

0 commit comments

Comments
 (0)