本文整理汇总了Python中subprocess.Popen.encode方法的典型用法代码示例。如果您正苦于以下问题:Python Popen.encode方法的具体用法?Python Popen.encode怎么用?Python Popen.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subprocess.Popen
的用法示例。
在下文中一共展示了Popen.encode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import encode [as 别名]
def put(self, arg):
filename = base64.urlsafe_b64encode(hashlib.sha256(self.request.body).digest()).decode('utf-8')
with open(os.path.join('files',filename),"wb") as f:
f.write(self.request.body)
attrs = xattr.xattr(f)
mimetype = Popen(["file", "-b","--mime-type", f.name], stdout=PIPE).communicate()[0].decode('utf8').strip()
attrs['user.Content-Type'] = mimetype.encode('utf-8')
attrs['user.filename'] = arg.encode('utf-8')
self.write('http://h45h.com/{}\n'.format(filename))
示例2: post
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import encode [as 别名]
def post(self, arg):
file_body = self.request.arguments.get('data')[0]
if not file_body:
self.finish()
return
filename = base64.urlsafe_b64encode(hashlib.sha256(file_body).digest()).decode('utf-8')
with open(os.path.join('files', filename), "wb") as f:
f.write(file_body)
f.flush()
attrs = xattr.xattr(f)
mimetype = Popen(["file", "-b","--mime-type", f.name], stdout=PIPE).communicate()[0].decode('utf8').strip()
attrs['user.Content-Type'] = mimetype.encode('utf-8')
self.write('<html><body><a href="http://h45h.com/{}"></body></html>{}'.format(filename,filename))
示例3: receive
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import encode [as 别名]
def receive(cfg_name):
# Init loggers
error_logger = utils.spawn_logger(cfg_name, 'error')
info_logger = utils.spawn_logger(cfg_name, 'info')
# Dictionary from request.data, from json to native
payload = json.loads(request.data)
# For cases when exception raised before on_error defined from `config`
on_error = lambda *args: None
try:
cfg = getattr(__import__('config.%s' % cfg_name, globals(), locals(), level=-1), cfg_name)
# Hooks
ref_not_fit = getattr(cfg, 'ref_not_fit', lambda *args: None)
on_command = getattr(cfg, 'on_command', lambda *args: None)
on_error = getattr(cfg, 'on_error', lambda *args: None)
# Config variables
path = utils.get_variable(cfg,
'PATH',
'',
lambda p: not p or not os.path.exists(p),
'PATH does not exists')
refs = utils.get_variable(cfg,
'REFS',
[r'.*'],
lambda r: not isinstance(r, list),
'REFS must be a list')
commands = utils.get_variable(cfg,
'COMMANDS',
[],
lambda c: not isinstance(c, list),
'Define COMMANDS variable, else nothing happens')
for ref in refs:
refExpr = re.compile(ref, re.IGNORECASE)
if refExpr.match(payload['ref']) is None:
# Log message about ref does not feet and exit
ref_not_fit(ref, payload)
info_logger.info('Ref does not fit')
return ''
for command in commands:
# Variables from payload, access as repository[name]
command.format(**payload)
on_command(command, payload)
# Execute current command and log out and errors
out, err = Popen(command,
shell=True,
cwd=os.path.join(PATH, cfg.PATH),
# close_fds=True,
stdout=PIPE,
stderr=PIPE).communicate()
if out:
try:
info_logger.info(out.encode('utf8'))
except UnicodeDecodeError:
pass
if err:
try:
error_logger.error(err.encode('utf8'))
except UnicodeDecodeError:
pass
except Exception, e:
on_error(e, payload)
error_logger.error(str(e))
示例4: urltoimg
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import encode [as 别名]
def urltoimg(url):
stdout = Popen("bin/phantomjs screencapture.js "+url, stdout=PIPE, shell=True).stdout.read()
print str(datetime.now())+' - filename stored(stdout phantomjs): '+stdout
sys.stdout.flush()
return 'capture-'+stdout.encode('utf-8').strip()+'.png'