本文整理汇总了Python中posixpath.urljoin函数的典型用法代码示例。如果您正苦于以下问题:Python urljoin函数的具体用法?Python urljoin怎么用?Python urljoin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了urljoin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, investor_id, api_key, api_version='v1',
host='api.lendingclub.com', path='/api/investor'):
"""Connection to LendingClub API.
Each client requires an `investor_id` and `api_key`. All other
arguments are optional.
Args:
investor_id (int): The accounts Investor Id this can be found on the
Account Summary page on the LendingClub website after loging in.
api_key (str): Account authorization token found under Settings.
api_version (str, optional): api version endpoint.
host (str, optional): Host name of api endpoint.
path (str, optional): Base path of api endpoint.
"""
self._last_update = None
self._host = host
investor_id = str(investor_id)
self._investor_id = investor_id
self._base_path = urljoin(path, api_version)
self._acct_path = urljoin(self._base_path, 'accounts', investor_id)
self._loan_path = urljoin(self._base_path, 'loans')
self._default_headers = {'Authorization': api_key,
'Accept': 'application/json',
'Content-type': 'application/json'}
ssl_ctx = create_default_context(Purpose.SERVER_AUTH)
self._conn = HTTPSConnection(host, context=ssl_ctx)
self._conn.set_debuglevel(10)
self._conn.connect()
示例2: main
def main():
# 获取参数
xArg = sys.argv[1:]
# 参数个数目前为4个
args_nums = len(xArg)
if args_nums != 4:
print 'input args num error'
return
# 获取处理文件时间和文件类型
Ftime = xArg[0]
Ftype1 = xArg[1]
Ftype2 = xArg[2]
Frate = xArg[3]
# 解析配置文件
group = '%s-%s' % (Ftype1, Ftype2)
I_DIR = Cfg[group]['I_DIR']
O_DIR = Cfg[group]['O_DIR']
date_s, date_e = ymd2date(Ftime)
I_FILE = urljoin(I_DIR, group + '_' + Frate + '.txt')
O_FILE = urljoin(I_DIR, group + '_' + Frate)
DATA = ReadFile(I_FILE, date_s, date_e)
print DATA
DictTitle = {'xlabel': 'Site CO2', 'ylabel': 'Sate CO2', 'title': '%s-%s' % (Ftype1, Ftype2)}
ds_PUB_LIB.draw_Scatter(DATA['SiteCo2'], DATA['SateCo2'], O_FILE, DictTitle, '', '')
示例3: __init__
def __init__(self, host="http://127.0.0.1:7796/", key=None, verify=False):
self.host = host
self.api = urljoin(host, 'preql/q')
self.update = urljoin(host, 'preql/update')
self.error_params = ["SynthDB.connect('{}')".format(self.host), "No instance of SynthDB found at {}".format(self.host), self.host]
self.key = key
self.verify = verify
self.delim = '\t'
示例4: main
def main():
# 获取参数
xArg = sys.argv[1:]
# 参数个数目前为3个
args_nums = len(xArg)
if args_nums != 2:
print ' args nums error'
return
# 获取处理文件时间和文件类型
Ftime = xArg[0]
Ftype = xArg[1]
# 解析配置文件
I_DIR = Cfg[Ftype]['I_DIR']
O_DIR = Cfg[Ftype]['O_DIR']
SiteList = urljoin(O_DIR, Ftype, 'SiteList.txt')
if os.path.exists(SiteList):
fp = open(SiteList, 'r')
SiteList = fp.readlines()
fp.close()
else:
print u'站点列表文件不存在'
return
for siteLine in SiteList:
if siteLine.strip() == '':
continue
siteName = siteLine.strip().split()[0]
start_time = siteLine.strip().split()[3].replace('-', '')
end_time = siteLine.strip().split()[4].replace('-','')
Ftime = start_time + '-' + end_time
print siteName, start_time, end_time
date_s, date_e = ymd2date(Ftime)
while date_s <= date_e:
ymd = date_s.strftime('%Y%m%d')
FULL_I_DIR = urljoin(I_DIR, Ftype, siteName)
# 输出文件在站点名下,按日输出,每天一个文件
O_FILE = urljoin(O_DIR, Ftype, siteName, ymd[:4], ymd + '.txt')
# 实例化WDCGG类
tccon = TCCON()
# 对类的全局变量赋值
tccon.YMD = date_s
tccon.SiteName = siteName
# 开始处理
tccon.FindFile(FULL_I_DIR)
tccon.ReadFile()
tccon.Filter()
print ymd,len(tccon.FileLine), len(tccon.FileData)
tccon.Write(O_FILE)
date_s = date_s + relativedelta(days=1)
示例5: main
def main():
# 获取参数
xArg = sys.argv[1:]
# 参数个数目前为2个
args_nums = len(xArg)
if args_nums != 2:
print ' args nums error'
return
# 获取处理文件时间和文件类型
Ftime = xArg[0]
Ftype = xArg[1]
# 解析配置文件
I_DIR = Cfg[Ftype]['I_DIR']
O_DIR = Cfg[Ftype]['O_DIR']
SiteList = urljoin(O_DIR, Ftype, 'SiteList.txt')
if os.path.exists(SiteList):
fp = open(SiteList, 'r')
SiteList = fp.readlines()
fp.close()
else:
print u'站点列表文件不存在'
return
for siteLine in SiteList:
if siteLine.strip() == '':
continue
date_s, date_e = ymd2date(Ftime)
siteName = siteLine.strip().split()[0]
print siteName
while date_s <= date_e:
ymd = date_s.strftime('%Y%m%d')
FULL_I_DIR = urljoin(I_DIR, Ftype, siteName)
O_FILE = urljoin(O_DIR, Ftype, siteName, ymd[:4], ymd + '.txt')
# 实例化GGA类
gga = GGA()
# 类中的全局变量赋值
gga.YMD = date_s
gga.SiteName = siteName
# 开始提取文件
gga.FindFile(FULL_I_DIR)
gga.ReadFile()
gga.Filter()
gga.Write(O_FILE)
print ymd, len(gga.FileData)
date_s = date_s + relativedelta(days=1)
示例6: show_hours
def show_hours(date_s, Ftype):
IDIR = Cfg[Ftype]['I_DIR']
ODIR = Cfg[Ftype]['O_DIR_H']
AERA = Cfg[Ftype]['L2S']
TimeList = []
DictData = {}
for i in range(24):
dateT1 = date_s + relativedelta(hours=i)
TimeList.append(dateT1)
for aera in AERA.keys():
Line = []
shortname = Cfg[Ftype]['L2S'][aera].decode('utf-8')
ymd = date_s.strftime('%Y%m%d')
FileName = urljoin(IDIR, aera, 'hours', ymd + '.txt')
print FileName
if os.path.isfile(FileName) and os.path.getsize(FileName) != 0:
ary = np.loadtxt(FileName, dtype=dtype, skiprows=1).reshape((-1,))
else:
for i in range(24):
t_str = '%s %s %f %f %f %d' % (ymd, '00:00:00', np.nan, np.nan, np.nan, 9999)
Line.append([each.strip() for each in t_str.split()])
ary = np.core.records.fromarrays(np.array(Line).transpose(),
names=','.join(dname_Nan),
formats=','.join(dtype_Nan))
DictData[shortname] = ary
# print DictData
if not os.path.isdir(ODIR):
os.makedirs(ODIR)
# 平均值
DictMean = {}
color_dict = {}
for eachkey in DictData.keys():
DictMean[eachkey] = DictData[eachkey]['mean']
print 'TimeList', len(TimeList), eachkey, len(DictMean[eachkey])
DictVar = {}
for eachkey in DictData.keys():
DictVar[eachkey] = DictData[eachkey]['var']
print 'TimeList', len(TimeList), eachkey, len(DictVar[eachkey])
DictTitle1 = {'xlabel': 'x %s' % ymd, 'ylabel': 'mean', 'title': 'gga'}
DictTitle2 = {'xlabel': 'x %s' % ymd, 'ylabel': 'Var', 'title': 'gga'}
# ymd = time.strftime('%Y%m%d', time.localtime())
Outimg1 = urljoin(ODIR, ymd + '_mean')
Outimg2 = urljoin(ODIR, ymd + '_var')
ds_PUB_LIB.draw_time_fig(TimeList, DictMean, Outimg1, DictTitle1, 'H')
ds_PUB_LIB.draw_time_fig(TimeList, DictVar, Outimg2, DictTitle2, 'H')
示例7: show_day
def show_day(Ftype, Ftime):
IDIR = Cfg[Ftype]['I_DIR']
ODIR = Cfg[Ftype]['O_DIR_D']
AERA = Cfg[Ftype]['L2S']
TimeList = []
DictData = {}
date_s, date_e = ymd2date(Ftime)
while date_s <= date_e:
TimeList.append(date_s)
date_s = date_s + relativedelta(days=1)
for aera in AERA.keys():
shortname = Cfg[Ftype]['L2S'][aera].decode('utf-8')
print shortname
FileList = []
date_s, date_e = ymd2date(Ftime)
while date_s <= date_e:
ymd = date_s.strftime('%Y%m%d')
FileName = urljoin(IDIR, aera, 'days', ymd + '.txt')
FileList.append(FileName)
date_s = date_s + relativedelta(days=1)
data = combine_day(FileList)
DictData[shortname] = data
if not os.path.isdir(ODIR):
os.makedirs(ODIR)
print DictData
# 平均值
DictMean = {}
for eachkey in DictData.keys():
DictMean[eachkey] = DictData[eachkey]['mean']
print 'TimeList', len(TimeList), eachkey, len(DictMean[eachkey])
print len(TimeList), len(DictData[eachkey])
# 偏差
DictVar = {}
for eachkey in DictData.keys():
DictVar[eachkey] = DictData[eachkey]['var']
print 'TimeList', len(TimeList), eachkey, len(DictVar[eachkey])
DictTitle1 = {'xlabel': 'x %s' % ymd, 'ylabel': 'mean', 'title': 'gga'}
DictTitle2 = {'xlabel': 'x %s' % ymd, 'ylabel': 'Var', 'title': 'gga'}
# ymd = time.strftime('%Y%m%d', time.localtime())
Outimg1 = urljoin(ODIR, ymd + '_mean')
Outimg2 = urljoin(ODIR, ymd + '_var')
ds_PUB_LIB.draw_time_fig(TimeList, DictMean, Outimg1, DictTitle1, 'D')
ds_PUB_LIB.draw_time_fig(TimeList, DictVar, Outimg2, DictTitle2, 'D')
示例8: retrive_save_document
def retrive_save_document(self, analysis_id):
combo_resource_url = urljoin(BACKEND_HOST, "api/v1/analysiscombo/{}/?format=json".format(analysis_id))
retrive_headers = {'Authorization': 'ApiKey {}:{}'.format(API_USER,API_KEY)}
logger.debug("Fetching resource from {}".format(combo_resource_url))
r = False
while not r:
try:
r = requests.get(combo_resource_url, headers = retrive_headers)
except requests.exceptions.ConnectionError:
logger.debug("Got a requests.exceptions.ConnectionError exception, will try again in {} seconds".format(SLEEP_TIME_ERROR))
time.sleep(SLEEP_TIME_ERROR)
response = r.json()
logger.debug(response)
#now files for locations
for x in response["locations"]:
if x['content_id'] != None:
download_url = urljoin(BACKEND_HOST, "api/v1/location/", x['content_id'], "file/")
new_fs_id = self.fetch_save_file(download_url)
#now change id in repsonse
x['location_id'] = new_fs_id
# now for samples
for x in response["samples"]:
download_url = urljoin(BACKEND_HOST, "api/v1/sample/", x['sample_id'], "file/")
new_fs_id = self.fetch_save_file(download_url)
#now change id in repsonse
x['sample_id'] = new_fs_id
# same for pcaps
for x in response["pcaps"]:
if x['content_id'] is None:
continue
download_url = urljoin(BACKEND_HOST, "api/v1/pcap/", x['content_id'], "file/")
new_fs_id = self.fetch_save_file(download_url)
#now change id in repsonse
x['content_id'] = new_fs_id
#for vt,andro etc. eoint sample_id to gridfs id
# check for issues in this
for x in response["virustotal"]:
x['sample_id'] = search_samples_dict_list(x['sample_id'],response["samples"])
for x in response["honeyagent"]:
x['sample_id'] = search_samples_dict_list(x['sample_id'],response["samples"])
for x in response["androguard"]:
x['sample_id'] = search_samples_dict_list(x['sample_id'],response["samples"])
for x in response["peepdf"]:
x['sample_id'] = search_samples_dict_list(x['sample_id'],response["samples"])
#remove id from all samples and pcaps
for x in response["samples"]:
x.pop("_id")
frontend_analysis_id = db.analysiscombo.insert(response)
return frontend_analysis_id
示例9: main
def main():
# 获取参数
xArg = sys.argv[1:]
# 参数个数目前为1个
args_nums = len(xArg)
if args_nums != 1:
print ' args nums error'
return
# 获取处理文件时间和文件类型
Ftype = xArg[0]
# 解析配置文件
I_DIR = Cfg[Ftype]['I_DIR']
O_DIR = Cfg[Ftype]['O_DIR']
SiteList = urljoin(O_DIR, Ftype, 'SiteList.txt')
if os.path.exists(SiteList):
fp = open(SiteList, 'r')
SiteList = fp.readlines()
fp.close()
else:
print u'站点列表文件不存在'
return
for siteLine in SiteList:
if siteLine.strip() == '':
continue
siteName = siteLine.strip().split()[0]
# 根据站点开始 结束时间 来处理数据,手动时可注释掉
start_time = siteLine.strip().split()[3].replace('-', '')
end_time = siteLine.strip().split()[4].replace('-','')
Ftime = start_time + '-' + end_time
print siteName, start_time, end_time
date_s, date_e = ymd2date(Ftime)
siteName = siteLine.strip().split()[0]
FULL_I_DIR = urljoin(I_DIR, Ftype, siteName)
oFile = urljoin(O_DIR, Ftype, siteName, 'time_series.txt')
tccon = TCCON()
tccon.FindFile(FULL_I_DIR)
tccon.ReadFile()
tccon.Combine_S(date_s, date_e)
tccon.Write_S(oFile)
print oFile
示例10: request
def request(session, base_path, method, path, **kwargs):
"""Construct a :class:`requests.Request` object and send it.
:param requests.Session session:
:param str base_path:
:param str method: Method for the :class:`requests.Request` object.
:param str path: (optional) The path to join with :attr:`CouchDB.url`.
:param kwargs: (optional) Arguments that :meth:`requests.Session.request` takes.
:rtype: requests.Response
"""
# Prepare the params dictionary
if ('params' in kwargs) and isinstance(kwargs['params'], dict):
params = kwargs['params'].copy()
for key, val in iteritems(params):
# Handle titlecase booleans
if isinstance(val, bool):
params[key] = json.dumps(val)
kwargs['params'] = params
if compat.urlparse(path).scheme:
# Support absolute URLs
url = path
else:
url = urljoin(base_path, path).strip('/')
r = session.request(method, url, **kwargs)
# Raise exception on a bad status code
if not (200 <= r.status_code < 300):
utils.raise_http_exception(r)
return r
示例11: insert_att
def insert_att(doc_id, doc_rev, att_id, att, att_type, **kwargs):
"""Create or update an existing attachment.
http://docs.couchdb.org/en/stable/api/document/attachments.html#put--db-docid-attname
:param str doc_id: The attachment document.
:param doc_rev: (optional) The document revision.
:param str att_id: The attachment name.
:param att: The dictionary, bytes, or file-like object to insert.
:param str att_type: The attachment MIME type.
:param kwargs: (optional) Arguments that :meth:`requests.Session.request` takes.
:rtype: (str, str, dict)
"""
if doc_rev:
if ('params' not in kwargs) or (not isinstance(kwargs['params'], dict)):
kwargs['params'] = {}
kwargs['params']['rev'] = doc_rev
if ('headers' not in kwargs) or (not isinstance(kwargs['headers'], dict)):
kwargs['headers'] = {}
path = urljoin(utils.encode_document_id(doc_id), utils.encode_attachment_id(att_id))
kwargs['headers']['Content-Type'] = att_type
kwargs['data'] = att
return 'PUT', path, kwargs
示例12: actions
def actions(self, appfolder, controller, skipped, skip_auth=False):
"""
Generator.
Parse codelines from controller code and yield '<controller>/<action>' strings.
Args:
appfolder: application folder
controller: name of the controller (without .py) ['<controller>/*' will be converted into 'controller']
skipped: list of actions we want to skip/ignore them
skip_auth: if True, all @auth. decorated actions will be skipped too (useful for unlogged user)
"""
controller = controller.split('/')[0] # <controller> or <controller/*> can be used
codelines = self.get_controller_codelines(appfolder, controller)
skip_next = False
for ln in codelines:
ln = ln.rstrip() # - \n
if ln[:4] == 'def ': # function without parameters, maybe Web2py action
if not skip_next and ln[-3:] == '():':
action = ln[4:-3].strip()
if action[:2] != '__': # Web2py action
url = urljoin(controller, action)
if url not in skipped:
yield url
skip_next = False
elif skip_auth and ln[:6] == '@auth.' or re.match('^#\s*ajax$', ln): # unlogged user + need authorize --or-- # ajax
skip_next = True
示例13: controllers
def controllers(appfolder):
"""
yields names of all controllers (without .py) except off appadmin
"""
for controller in os.listdir(urljoin(appfolder, 'controllers')):
if controller[-3:] == '.py' and not controller == 'appadmin.py':
yield controller[:-3]
示例14: set_piazza
def set_piazza(course_id, piazza_id):
"""Uses the backend API to add a course to the course list"""
course_id = str(course_id)
ret = post(urljoin(URL, course_id, 'course/setpiazza/'), data={'piazza_cid': piazza_id})
if ret.status_code != 200:
raise ValueError('Unable to add piazza id %s' % piazza_id)
return ret
示例15: set_temporary_password
def set_temporary_password(self, client_id, client_secret, username, new_password):
""" Changes password on behalf of the user with client credentials
Args:
client_id: The oauth client id that this code was generated for
client_secret: The secret for the client_id above
user_id: the user id to act on
new_password: the users desired password
Raises:
UAAError: there was an error changing the password
Returns:
boolean: Success/failure
"""
list_filter = 'userName eq "{0}"'.format(username)
userList = self.client_users(client_id, client_secret, list_filter=list_filter)
if len(userList['resources']) > 0:
user_id = userList['resources'][0]['id']
token = self._get_client_token(client_id, client_secret)
self._request(
urljoin('/Users', user_id, 'password'),
'PUT',
body={
'password': new_password
},
headers={
'Authorization': 'Bearer ' + token
}
)
return True
return False