本文整理汇总了Python中webbrowser.open_new函数的典型用法代码示例。如果您正苦于以下问题:Python open_new函数的具体用法?Python open_new怎么用?Python open_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了open_new函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: openweb
def openweb(self, *args):
"""
Open wikipedia url
"""
url = self.main.url_to_open
if url:
webbrowser.open_new(url)
示例2: view_cdn_in_browser
def view_cdn_in_browser(self):
"""
Let's prove that we've successfully cached the object on the CDN by
opening {object_name} on the CDN: http://{bucket_name}.{alias}.netdna-cdn.com/{object_name}
"""
webbrowser.open_new("http://%s/%s" % (self.cdn_url, self.object_name))
示例3: reportBug
def reportBug(self, event):
# open the browser window to the New Issue tracker page
webbrowser.open_new("http://roundup.creativecommons.org/ccpublisher/[email protected]=item")
return
# load the dialog definition
xrc_resource = wx.xrc.XmlResource(os.path.join(
p6.api.getResourceDir(), 'dialogs.xrc'))
report = xrc_resource.LoadDialog(None, "DLG_BUGREPORT")
# connect the OK button
self.Bind(wx.EVT_BUTTON,
self.__reportBug,
id = wx.xrc.XRCID("CMD_OK")
)
# connect the Cancel button
self.Bind(wx.EVT_BUTTON,
lambda event: report.Close(),
id = wx.xrc.XRCID("CMD_CANCEL")
)
# display the dialog
self.__reportDlg = report
report.ShowModal()
示例4: setUpClass
def setUpClass(self):
super(BrowserCore, self).setUpClass()
self.harness_queue = multiprocessing.Queue()
self.harness_server = multiprocessing.Process(target=harness_server_func, args=(self.harness_queue,))
self.harness_server.start()
print '[Browser harness server on process %d]' % self.harness_server.pid
webbrowser.open_new('http://localhost:9999/run_harness')
示例5: fetch_train_tickets
def fetch_train_tickets(from_station, to_station, date=None, train_type=None):
"""get input data and print final result
:param train_type
:param from_station
:param to_station
:param date
:return: if data is invalidate then return False
"""
date = tickets_util.validate_raw_date(date)
if not isinstance(date, str):
print(common_util.make_colorful_font(date['message'], Fore.RED))
return date['result']
from_station_key = tickets_util.get_station_key(from_station)
to_station_key = tickets_util.get_station_key(to_station)
fetch_url = URL.format(date=date, from_station_key=from_station_key, to_station_key=to_station_key)
train_tickets = fetch_trains.TrainTickets(fetch_url)
tickets_result = train_tickets.fetch_tickets()
# with open('./data/tickets_data.json', encoding="utf-8") as f:
# tickets_result = json.loads(f.read())
if tickets_result['result']:
print_train_tickets(tickets_result['data'], train_type)
else:
print(common_util.make_colorful_font(tickets_result['message'], Fore.RED))
return False
determine_input = input('到官网购票? y/n ')
if determine_input == 'y':
webbrowser.open_new(OFFICIAL_WEB)
示例6: report_dispatcher
def report_dispatcher(args=sys.argv[1:]):
"""Parses command line and calls the different report functions
"""
command = command_handling(args, COMMAND_LOG)
# Parses command line arguments.
command_args = a.parse_and_check(command)
port = DEFAULT_PORT if not command_args.port else command_args.port
report_url = get_report_url(command_args)
if not command_args.no_server:
absolute_report_url = "http://%s:%s/%s" % (DEFAULT_HOST, port, report_url)
current_directory = os.getcwd()
os.chdir(os.path.join(HOME, SERVER_DIRECTORY))
httpd = None
try:
httpd = StoppableHTTPServer((DEFAULT_HOST, port), SimpleHTTPServer.SimpleHTTPRequestHandler)
thread.start_new_thread(httpd.serve, ())
except socket.error, exc:
print exc
# Open URL in new browser window
webbrowser.open_new(absolute_report_url)
# opens in default browser
if httpd:
raw_input(
"*********************************\n"
"Press <RETURN> to stop the server\n"
"*********************************\n"
)
os.chdir(current_directory)
if httpd:
httpd.stop()
示例7: get_new_vk_token
def get_new_vk_token():
SocketServer.TCPServer.allow_reuse_address = True
httpd = None
redirect_port = 20938
while httpd is None:
try:
httpd = SocketServer.TCPServer(("", redirect_port), HttpHandler)
print 'Server is running on port %d.' % redirect_port
except socket.error:
print 'Port %d is already in use. Trying next port.' % redirect_port
redirect_port += 1
parameters = {
'client_id': APP_ID,
'scope': 'audio',
'redirect_uri': 'http://localhost:%d' % redirect_port,
'display': 'page',
'v': 5.37,
'response_type': 'token'
}
auth_url = "https://oauth.vk.com/authorize?{}".format(urlencode(parameters))
webbrowser.open_new(auth_url)
httpd.handle_request()
httpd.handle_request()
token_object = dict()
token_object['access_token'] = TOKEN['#access_token'][0]
token_expires_in = int(TOKEN['expires_in'][0])
token_object['expiring_time'] = int(time.time()) + token_expires_in - 60
return token_object
示例8: getKey
def getKey(YD_APP_ID, YD_APP_SECRET, keyfile):
if os.path.isfile(keyfile):
return open(keyfile, 'r').read()
import webbrowser
webbrowser.open_new(
OAYR + 'authorize?response_type=code&client_id=' + YD_APP_ID)
YploadRequestHandler._code = None
httpd = BaseHTTPServer.HTTPServer(('', 8714), YploadRequestHandler)
httpd.handle_request()
if YploadRequestHandler._code:
code = YploadRequestHandler._code
else:
code = raw_input('Input your code: ').strip()
res = requests.post(OAYR + 'token', data=dict(
grant_type='authorization_code',
code=code,
client_id=YD_APP_ID, client_secret=YD_APP_SECRET
))
if res.status_code != 200:
raise Exception('Wrong code')
key = res.json['access_token']
with open(keyfile, 'w') as fl:
fl.write(key)
return key
示例9: publish
def publish(connection, document, bucket, theme, prefix=None, title=None):
bucket = connection.get_bucket(bucket)
key_name = document.name
if '.' in key_name:
key_name = key_name.rsplit('.', 1)[0] + '.html'
if '/' in key_name:
key_name = key_name.rsplit('/', 1)[1]
if prefix:
key_name = '%s/%s' % (prefix, key_name)
content = __template__ % {
'title': title if title else key_name,
'content': document.read(),
'theme': theme
}
key = bucket.new_key(key_name)
key.content_type = 'text/html'
key.set_contents_from_string(content)
key.set_canned_acl('public-read')
public_url = key.generate_url(0, query_auth=False, force_http=True)
os.system('echo "%s" | pbcopy' % public_url)
webbrowser.open_new(public_url)
示例10: prepare_run
def prepare_run(self, workspace):
'''Invoke the image_set_list pickling mechanism and save the pipeline'''
pipeline = workspace.pipeline
image_set_list = workspace.image_set_list
if pipeline.test_mode or self.from_old_matlab:
return True
if self.batch_mode.value:
self.enter_batch_mode(workspace)
return True
else:
path = self.save_pipeline(workspace)
if not cpprefs.get_headless():
import wx
wx.MessageBox(
"CreateBatchFiles saved pipeline to %s" % path,
caption="CreateBatchFiles: Batch file saved",
style=wx.OK | wx.ICON_INFORMATION)
if self.go_to_website:
try:
import webbrowser
import urllib
server_path = self.alter_path(os.path.dirname(path))
query = urllib.urlencode(dict(data_dir=server_path))
url = cpprefs.get_batchprofiler_url() + \
"/NewBatch.py?" + query
webbrowser.open_new(url)
except:
import traceback
traceback.print_exc()
return False
示例11: authorize
def authorize(self, account):
self.account = account
if account == "twitter":
self.api = self.TWITTER
elif account == "identi.ca":
self.api = self.IDENTICA
else:
self.api = self.GETGLUE
self.request_token = None
key = base64.b64decode(self.api["key"])
secret = base64.b64decode(self.api["secret"])
self.consumer = oauth.Consumer(key, secret)
client = oauth.Client(self.consumer, proxy_info=self.proxy_info)
resp, content = client.request(self.api["request_token"])
if resp["status"] != "200":
self.note_label.set_text(content)
return False
self.request_token = dict(urlparse.parse_qsl(content))
url = "%s?oauth_token=%s" % (self.api["authorization"], self.request_token["oauth_token"])
self.note_label.set_markup("Opening authorize link in default web browser.")
webbrowser.open_new(url)
return True
示例12: URL_click
def URL_click(event):
if not len(listbox.curselection()) == 0:
currentPackage = packageDescription()
for package in allPackages:
if package.name ==listbox.get(listbox.curselection()):
currentPackage = package
webbrowser.open_new(currentPackage.homepage)
示例13: make
def make(self):
helper_in_cwd = exists(join(self.dir, "googlecode_upload.py"))
if helper_in_cwd:
sys.path.insert(0, self.dir)
try:
import googlecode_upload
except ImportError:
raise MkError("couldn't import `googlecode_upload` (get it from http://support.googlecode.com/svn/trunk/scripts/googlecode_upload.py)")
if helper_in_cwd:
del sys.path[0]
ver = _get_version()
sdist_path = join(self.dir, "dist", "go-%s.zip" % ver)
status, reason, url = googlecode_upload.upload_find_auth(
sdist_path,
"go-tool", # project_name
"go %s source package" % ver, # summary
["Featured", "Type-Archive"]) # labels
if not url:
raise MkError("couldn't upload sdist to Google Code: %s (%s)"
% (reason, status))
self.log.info("uploaded sdist to `%s'", url)
project_url = "http://code.google.com/p/go-tool/"
import webbrowser
webbrowser.open_new(project_url)
示例14: on_decide_policy
def on_decide_policy(view, decision, dtype):
uri = decision.get_request().get_uri()
if uri.startswith("http") and not '127.0.0.1' in uri:
decision.ignore()
webbrowser.open_new(uri)
return True
return False
示例15: do_lexhtml
def do_lexhtml(self, subcmd, opts, lang, path):
"""${cmd_name}: lex the given file to styled HTML (for debugging)
${cmd_usage}
${cmd_option_list}
"""
from ludditelib.debug import lex_to_html
content = open(path, 'r').read()
html = lex_to_html(content, lang)
if opts.output == '-':
output_path = None
output_file = sys.stdout
else:
if opts.output:
output_path = opts.output
else:
output_path = path+".html"
if exists(output_path):
os.remove(output_path)
output_file = open(output_path, 'w')
if output_file:
output_file.write(html)
if output_path:
output_file.close()
if opts.browse:
if not output_path:
raise LudditeError("cannot open in browser if stdout used "
"for output")
import webbrowser
url = _url_from_local_path(output_path)
webbrowser.open_new(url)