本文整理汇总了Python中hyper.HTTP20Connection方法的典型用法代码示例。如果您正苦于以下问题:Python hyper.HTTP20Connection方法的具体用法?Python hyper.HTTP20Connection怎么用?Python hyper.HTTP20Connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hyper
的用法示例。
在下文中一共展示了hyper.HTTP20Connection方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_connection
# 需要导入模块: import hyper [as 别名]
# 或者: from hyper import HTTP20Connection [as 别名]
def _create_connection(self):
return HTTP20Connection(self.host, force_proto=self.force_proto)
示例2: open
# 需要导入模块: import hyper [as 别名]
# 或者: from hyper import HTTP20Connection [as 别名]
def open(self):
if self.request == 'hyper':
if self.http2:
self.__http = hyper.HTTP20Connection(self.host, self.port, proxy_host=self.realhost, proxy_port=self.realport, proxy_headers=self.proxy_headers)
else:
self.__http = hyper.HTTPConnection(self.host, self.port, proxy_host=self.realhost, proxy_port=self.realport, proxy_headers=self.proxy_headers)
elif self.request == 'httpx':
if self.http2:
self.__http = httpx.AsyncClient(base_url='%s://%s' % (self.scheme, self.host), http2=self.http2)
else:
self.__http = httpx.Client(base_url='%s://%s' % (self.scheme, self.host))
elif self.request == 'requests':
self.__http = requests.Session()
if self.using_proxy():
self.__http.proxies = urllib.request.getproxies()
elif self.request == 'requests-futures':
self.__http = FuturesSession()
if self.using_proxy():
self.__http.proxies = urllib.request.getproxies()
elif self.request == 'httplib2':
self.__http = httplib2.Http()
else:
if self.scheme == 'http':
self.__http = http_client.HTTPConnection(self.host, self.port)
elif self.scheme == 'https':
self.__http = http_client.HTTPSConnection(self.host, self.port)
if self.using_proxy():
self.__http.set_tunnel(self.realhost, self.realport, self.proxy_headers)
示例3: get_connection
# 需要导入模块: import hyper [as 别名]
# 或者: from hyper import HTTP20Connection [as 别名]
def get_connection(self):
self.conn = HTTP20Connection(self.APNs_PRODUCTION_SERVER,
force_proto="h2",
port=443, secure=True,
ssl_context=self.get_ssl_context())
示例4: create_connection
# 需要导入模块: import hyper [as 别名]
# 或者: from hyper import HTTP20Connection [as 别名]
def create_connection(self, base_url=None):
self.connection = HTTP20Connection(
host=base_url or self.host, secure=True, force_proto='h2'
)
示例5: h2_connect
# 需要导入模块: import hyper [as 别名]
# 或者: from hyper import HTTP20Connection [as 别名]
def h2_connect(s, ip, port, verify):
if s == True:
ctx = ssl.SSLContext()
ctx.set_alpn_protocols(['h2'])
if verify:
ctx.verify_mode = ssl.CERT_REQUIRED
ctx.load_default_certs()
else: ctx.verify_mode = ssl.CERT_NONE
conn = hyper.HTTP20Connection(ip, port=port, ssl_context=ctx)
elif s == False:
conn = hyper.HTTP20Connection(ip, port=port)
conn.connect()
return conn
# Function: main scan function. Starts up a number of processes which handle their own h2 connection and sends them entries to scan
示例6: init_connection
# 需要导入模块: import hyper [as 别名]
# 或者: from hyper import HTTP20Connection [as 别名]
def init_connection(self):
""" Opens and maintains the connection with AVS. This starts the thread that runs
for the duration of the object's life. Sends required requests to initialize
connection correctly. This should be called anytime the connection needs to be
reestablished.
"""
# Open connection
self.connection = HTTP20Connection(self.url, port=443, secure=True, force_proto="h2", enable_push=True)
# First start downstream
self.start_downstream()
# Send sync state message (required)
header = {'namespace': "System", 'name': "SynchronizeState"}
stream_id = self.send_event(header)
# Manually handle this response for now
data = self.get_response(stream_id)
# Should be 204 response (no content)
if data.status != 204:
print("PUSH" + data.read())
raise NameError("Bad status (%s)" % data.status)
# Start ping thread
ping_thread = threading.Thread(target=self.ping_thread)
ping_thread.start()
示例7: check_http2
# 需要导入模块: import hyper [as 别名]
# 或者: from hyper import HTTP20Connection [as 别名]
def check_http2(self, ssl_sock, host):
self.logger.debug("ip:%s use http/2", ssl_sock.ip_str)
try:
conn = hyper.HTTP20Connection(ssl_sock, host=host, ip=ssl_sock.ip_str, port=443)
conn.request('GET', self.config.check_ip_path)
response = conn.get_response()
return response
except Exception as e:
self.logger.exception("http2 get response fail:%r", e)
return False
示例8: connect_to_apn_if_needed
# 需要导入模块: import hyper [as 别名]
# 或者: from hyper import HTTP20Connection [as 别名]
def connect_to_apn_if_needed(self):
if self.__connection is None:
self.__connection = HTTP20Connection(self.server, self.port, ssl_context=self.ssl_context,
force_proto=self.proto or 'h2')
示例9: send
# 需要导入模块: import hyper [as 别名]
# 或者: from hyper import HTTP20Connection [as 别名]
def send(token_hex, message, **kwargs):
"""
Site: https://apple.com
API: https://developer.apple.com
Desc: iOS notifications
Installation and usage:
pip install hyper
"""
priority = kwargs.pop('priority', 10)
topic = kwargs.pop('topic', None)
alert = {
"title": kwargs.pop("event"),
"body": message,
"action": kwargs.pop(
'apns_action', defaults.APNS_PROVIDER_DEFAULT_ACTION)
}
data = {
"aps": {
'alert': alert,
'content-available': kwargs.pop('content_available', 0) and 1
}
}
data['aps'].update(kwargs)
payload = dumps(data, separators=(',', ':'))
headers = {
'apns-priority': priority
}
if topic is not None:
headers['apns-topic'] = topic
ssl_context = init_context()
ssl_context.load_cert_chain(settings.APNS_CERT_FILE)
connection = HTTP20Connection(
settings.APNS_GW_HOST, settings.APNS_GW_PORT, ssl_context=ssl_context)
stream_id = connection.request(
'POST', '/3/device/{}'.format(token_hex), payload, headers)
response = connection.get_response(stream_id)
if response.status != 200:
raise APNsError(response.read())
return True