本文整理汇总了Python中stripe.util.utf8函数的典型用法代码示例。如果您正苦于以下问题:Python utf8函数的具体用法?Python utf8怎么用?Python utf8使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了utf8函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: instance_url
def instance_url(self):
self.id = util.utf8(self.id)
extn = urllib.quote_plus(self.id)
if hasattr(self, "customer"):
customer = util.utf8(self.customer)
base = Customer.class_url()
owner_extn = urllib.quote_plus(customer)
class_base = "sources"
elif hasattr(self, "recipient"):
recipient = util.utf8(self.recipient)
base = Recipient.class_url()
owner_extn = urllib.quote_plus(recipient)
class_base = "cards"
elif hasattr(self, "account"):
account = util.utf8(self.account)
base = Account.class_url()
owner_extn = urllib.quote_plus(account)
class_base = "external_accounts"
else:
raise error.InvalidRequestError(
"Could not determine whether card_id %s is "
"attached to a customer, recipient, or "
"account." % self.id,
"id",
)
return "%s/%s/%s/%s" % (base, owner_extn, class_base, extn)
示例2: instance_url
def instance_url(self):
token = util.utf8(self.id)
transfer = util.utf8(self.transfer)
base = Transfer.class_url()
cust_extn = urllib.quote_plus(transfer)
extn = urllib.quote_plus(token)
return "%s/%s/reversals/%s" % (base, cust_extn, extn)
示例3: instance_url
def instance_url(self):
token = util.utf8(self.id)
schedule = util.utf8(self.schedule)
base = SubscriptionSchedule.class_url()
schedule_extn = quote_plus(schedule)
extn = quote_plus(token)
return "%s/%s/revisions/%s" % (base, schedule_extn, extn)
示例4: instance_url
def instance_url(self):
token = util.utf8(self.id)
account = util.utf8(self.account)
base = Account.class_url()
acct_extn = quote_plus(account)
extn = quote_plus(token)
return "%s/%s/persons/%s" % (base, acct_extn, extn)
示例5: instance_url
def instance_url(self):
token = util.utf8(self.id)
extn = quote_plus(token)
if hasattr(self, "customer"):
customer = util.utf8(self.customer)
base = Customer.class_url()
owner_extn = quote_plus(customer)
class_base = "sources"
elif hasattr(self, "account"):
account = util.utf8(self.account)
base = Account.class_url()
owner_extn = quote_plus(account)
class_base = "external_accounts"
else:
raise error.InvalidRequestError(
"Could not determine whether bank_account_id %s is "
"attached to a customer or an account." % token,
"id",
)
return "%s/%s/%s/%s" % (base, owner_extn, class_base, extn)
示例6: instance_url
def instance_url(self):
self.id = util.utf8(self.id)
self.customer = util.utf8(self.customer)
base = Customer.class_url()
cust_extn = urllib.quote_plus(self.customer)
extn = urllib.quote_plus(self.id)
return "%s/%s/subscriptions/%s" % (base, cust_extn, extn)
示例7: instance_url
def instance_url(self):
token = util.utf8(self.id)
extn = urllib.quote_plus(token)
customer = util.utf8(self.customer)
base = Customer.class_url()
owner_extn = urllib.quote_plus(customer)
return "%s/%s/sources/%s" % (base, owner_extn, extn)
示例8: instance_url
def instance_url(self):
token = util.utf8(self.id)
extn = urllib.parse.quote_plus(token)
if (hasattr(self, 'customer')):
customer = util.utf8(self.customer)
base = Customer.class_url()
cust_extn = urllib.parse.quote_plus(customer)
return "%s/%s/sources/%s" % (base, cust_extn, extn)
else:
base = BitcoinReceiver.class_url()
return "%s/%s" % (base, extn)
示例9: verify
def verify(self, idempotency_key=None, **params):
headers = populate_headers(idempotency_key)
extn = urllib.quote_plus(util.utf8(self.id))
if (hasattr(self, 'customer')):
customer = util.utf8(self.customer)
base = Customer.class_url()
owner_extn = urllib.quote_plus(customer)
class_base = "bank_accounts"
url = "%s/%s/%s/%s/verify" % (base, owner_extn, class_base, extn)
self.refresh_from(self.request('post', url, params, headers))
else:
raise NotImplementedError(
"Can't verify bank account not attached to customer")
return self
示例10: request
def request(self, method, url, headers, post_data=None):
s = util.StringIO.StringIO()
rheaders = util.StringIO.StringIO()
curl = pycurl.Curl()
if method == 'get':
curl.setopt(pycurl.HTTPGET, 1)
elif method == 'post':
curl.setopt(pycurl.POST, 1)
curl.setopt(pycurl.POSTFIELDS, post_data)
else:
curl.setopt(pycurl.CUSTOMREQUEST, method.upper())
# pycurl doesn't like unicode URLs
curl.setopt(pycurl.URL, util.utf8(url))
curl.setopt(pycurl.WRITEFUNCTION, s.write)
curl.setopt(pycurl.HEADERFUNCTION, rheaders.write)
curl.setopt(pycurl.NOSIGNAL, 1)
curl.setopt(pycurl.CONNECTTIMEOUT, 30)
curl.setopt(pycurl.TIMEOUT, 80)
curl.setopt(pycurl.HTTPHEADER, ['%s: %s' % (k, v)
for k, v in headers.iteritems()])
if self._verify_ssl_certs:
curl.setopt(pycurl.CAINFO, os.path.join(
os.path.dirname(__file__), 'data/ca-certificates.crt'))
else:
curl.setopt(pycurl.SSL_VERIFYHOST, False)
try:
curl.perform()
except pycurl.error, e:
self._handle_request_error(e)
示例11: instance_url
def instance_url(self):
self.id = util.utf8(self.id)
extn = urllib.quote_plus(self.id)
if (hasattr(self, 'customer')):
self.customer = util.utf8(self.customer)
base = Customer.class_url()
owner_extn = urllib.quote_plus(self.customer)
else:
raise error.InvalidRequestError(
"Could not determine whether bank_id %s is "
"attached to a customer "
"or a recipient." % self.id, 'id')
return "%s/%s/bank_accounts/%s" % (base, owner_extn, extn)
示例12: detach
def detach(self, idempotency_key=None, **params):
if hasattr(self, 'customer') and self.customer:
extn = quote_plus(util.utf8(self.id))
customer = util.utf8(self.customer)
base = Customer.class_url()
owner_extn = quote_plus(customer)
url = "%s/%s/sources/%s" % (base, owner_extn, extn)
headers = util.populate_headers(idempotency_key)
self.refresh_from(self.request('delete', url, params, headers))
return self
else:
raise NotImplementedError(
"This source object does not appear to be currently attached "
"to a customer object.")
示例13: retrieve
def retrieve(self, id, **params):
base = self.get('url')
id = util.utf8(id)
extn = urllib.quote_plus(id)
url = "%s/%s" % (base, extn)
return self.request('get', url, params)
示例14: retrieve
def retrieve(self, id, **params):
base = self.get("url")
id = util.utf8(id)
extn = quote_plus(id)
url = "%s/%s" % (base, extn)
return self.request("get", url, params)
示例15: request
def request(self, method, url, headers, post_data=None):
b = util.io.BytesIO()
rheaders = util.io.BytesIO()
# Pycurl's design is a little weird: although we set per-request
# options on this object, it's also capable of maintaining established
# connections. Here we call reset() between uses to make sure it's in a
# pristine state, but notably reset() doesn't reset connections, so we
# still get to take advantage of those by virtue of re-using the same
# object.
self._curl.reset()
proxy = self._get_proxy(url)
if proxy:
if proxy.hostname:
self._curl.setopt(pycurl.PROXY, proxy.hostname)
if proxy.port:
self._curl.setopt(pycurl.PROXYPORT, proxy.port)
if proxy.username or proxy.password:
self._curl.setopt(
pycurl.PROXYUSERPWD,
"%s:%s" % (proxy.username, proxy.password),
)
if method == "get":
self._curl.setopt(pycurl.HTTPGET, 1)
elif method == "post":
self._curl.setopt(pycurl.POST, 1)
self._curl.setopt(pycurl.POSTFIELDS, post_data)
else:
self._curl.setopt(pycurl.CUSTOMREQUEST, method.upper())
# pycurl doesn't like unicode URLs
self._curl.setopt(pycurl.URL, util.utf8(url))
self._curl.setopt(pycurl.WRITEFUNCTION, b.write)
self._curl.setopt(pycurl.HEADERFUNCTION, rheaders.write)
self._curl.setopt(pycurl.NOSIGNAL, 1)
self._curl.setopt(pycurl.CONNECTTIMEOUT, 30)
self._curl.setopt(pycurl.TIMEOUT, 80)
self._curl.setopt(
pycurl.HTTPHEADER,
["%s: %s" % (k, v) for k, v in six.iteritems(dict(headers))],
)
if self._verify_ssl_certs:
self._curl.setopt(pycurl.CAINFO, stripe.ca_bundle_path)
else:
self._curl.setopt(pycurl.SSL_VERIFYHOST, False)
try:
self._curl.perform()
except pycurl.error as e:
self._handle_request_error(e)
rbody = b.getvalue().decode("utf-8")
rcode = self._curl.getinfo(pycurl.RESPONSE_CODE)
headers = self.parse_headers(rheaders.getvalue().decode("utf-8"))
return rbody, rcode, headers