-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathURLPoster.m
69 lines (64 loc) · 2.39 KB
/
URLPoster.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
%% Copyright (c) 2014-2014, Yichao Yu <[email protected]>
%
% This library is free software; you can redistribute it and/or
% modify it under the terms of the GNU Lesser General Public
% License as published by the Free Software Foundation; either
% version 3.0 of the License, or (at your option) any later version.
% This library is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
% Lesser General Public License for more details.
% You should have received a copy of the GNU Lesser General Public
% License along with this library.
classdef URLPoster < handle
properties
url_str;
pyconn;
end
methods(Access = private)
function self = URLPoster(url_str)
self.url_str = url_str;
[path, ~, ~] = fileparts(mfilename('fullpath'));
pyglob = py.dict(pyargs('mat_srcpath', path));
try
py.exec('from URLPoster import URLPoster', pyglob);
catch
py.exec('import sys; sys.path.append(mat_srcpath)', pyglob);
py.exec('from URLPoster import URLPoster', pyglob);
end
pylocal = py.dict(pyargs('url', self.url_str));
self.pyconn = py.eval('URLPoster(url)', pyglob, pylocal);
end
end
methods
function post(self, data, files)
self.pyconn.post(py.dict(pyargs(data{:})), ...
py.dict(pyargs(files{:})));
end
function output = reply(self)
%% DO NOT REMOVE THE REPLY FUNCTION!!!!!!!!!!!!!!!!!!!!!!!!
%% YOU HAVE ABSOLUTELY NO IDEA WHAT YOU ARE DOING IF YOU EVER THINK
%% DOING THIS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
output = char(self.pyconn.reply());
end
end
properties(Constant, Access=private)
cache = containers.Map();
end
methods(Static)
function dropAll()
remove(URLPoster.cache, keys(URLPoster.cache));
end
function res = get(url)
cache = URLPoster.cache;
if isKey(cache, url)
res = cache(url);
if ~isempty(res) && isvalid(res)
return;
end
end
res = URLPoster(url);
cache(url) = res;
end
end
end