How to use _parse_result method in tappy

Best Python code snippet using tappy_python

api.py

Source:api.py Github

copy

Full Screen

...39 **kwargs)40 if resp.status_code // 100 != 2:41 raise exceptions.make_exception(resp)42 return resp43 def _parse_result(self, resp, parse_func, klass):44 """45 Used to parse response result.46 :param resp: http response from requests module47 :param parse_func: helper function from utils.parse_utils module, it parses response and fill the result fields48 :param klass: the class of parsed response result this method returns49 :return: an instance of klass with parsed response information50 """51 result = klass(resp)52 parse_func(result, resp.json())53 return result54class DnsApi(_ApiBase):55 """56 The api class for DNS. More details about each parameter :class:`here <namecom.Record>`.57 Official namecom documentation : https://www.name.com/api-docs/DNS58 """59 def __init__(self, domainName, auth, use_test_env=False):60 """61 Parameters62 ----------63 domainName : string64 domain that dns records belongs to65 auth : :class:`~namecom.Auth`66 http authentication to use67 use_test_env : bool68 whether runs in test environment69 """70 super(DnsApi, self).__init__(auth, use_test_env)71 self.endpoint = '/v4/domains/{domain_name}/records'.format(domain_name=domainName)72 def list_records(self, page=1, perPage=1000):73 """Returns all records for a zone.74 Parameters75 ----------76 page: int77 which page to return78 perPage : int79 the number of records to return per request80 Returns81 -------82 :class:`~namecom.result_models.ListRecordsResult`83 a response result instance with parsed response info84 """85 params = {86 'page': page,87 'perPage': perPage88 }89 resp = self._do('GET', params=params)90 return self._parse_result(resp, parse_list_records, ListRecordsResult)91 def get_record(self, id):92 """Returns details about an individual record.93 Parameters94 ----------95 id : int96 the server-assigned unique identifier for this record97 Returns98 -------99 :class:`~namecom.result_models.GetRecordResult`100 a response result instance with parsed response info101 """102 resp = self._do('GET', relative_path='/{id}'.format(id=id))103 return self._parse_result(resp, parse_get_record, GetRecordResult)104 def create_record(self, host, type, answer, ttl=300, priority=None):105 """Creates a new record in the zone.106 Parameters107 ----------108 host : string109 hostname relative to the zone110 type : string111 dns record type112 answer : string113 dns record answer114 ttl : int115 dns record ttl116 priority : int117 dns record priority118 Returns119 -------120 :class:`~namecom.result_models.CreateRecordResult`121 a response result instance with parsed response info122 """123 data = json_dumps({124 'host': host,125 'type': type,126 'answer': answer,127 'ttl': ttl,128 'priority': priority129 })130 resp = self._do('POST', data=data)131 return self._parse_result(resp, parse_create_record, CreateRecordResult)132 def update_record(self, id, host=None, type=None, answer=None, ttl=300, priority=None):133 """Replaces the record with the new record that is passed.134 Parameters135 ----------136 id : int137 the server-assigned unique identifier for this record138 host : string139 hostname relative to the zone140 type : string141 dns record type142 answer : string143 dns record answer144 ttl : int145 dns record ttl146 priority : int147 dns record priority148 Returns149 -------150 :class:`~namecom.result_models.UpdateRecordResult`151 a response result instance with parsed response info152 """153 data = json.dumps({154 'host': host,155 'type': type,156 'answer': answer,157 'ttl': ttl,158 'priority': priority159 })160 resp = self._do('PUT', relative_path='/{id}'.format(id=id), data=data)161 return self._parse_result(resp, parse_update_record, UpdateRecordResult)162 def delete_record(self, id):163 """Deletes a record from the zone.164 Parameters165 ----------166 id : int167 the server-assigned unique identifier for this record168 Returns169 -------170 :class:`~namecom.result_models.DeleteRecordResult`171 a response result instance with parsed response info172 """173 resp = self._do('DELETE', relative_path='/{id}'.format(id=id))174 return self._parse_result(resp, parse_delete_record, DeleteRecordResult)175class DnssecApi(_ApiBase):176 """177 The api class for Domain Name System Security Extensions (DNSSEC).178 More details about each parameter :class:`here <namecom.DNSSEC>`.179 Official namecom documentation : https://www.name.com/api-docs/DNSSECs180 """181 def __init__(self, domainName, auth, use_test_env=False):182 """183 Parameters184 ----------185 domainName : string186 domain to manipulate dnssec on187 auth : :class:`~namecom.Auth`188 http authentication to use189 use_test_env : bool190 whether runs in test environment191 """192 super(DnssecApi, self).__init__(auth, use_test_env)193 self.endpoint = '/v4/domains/{domainName}/dnssec'.format(domainName=domainName)194 def list_dnssecs(self, page=1, perPage=1000):195 """Lists all of the DNSSEC keys registered with the registry.196 Parameters197 ----------198 page: int199 which page to return200 perPage : int201 the number of records to return per request202 Returns203 -------204 :class:`~namecom.result_models.ListDnssecsResult`205 a response result instance with parsed response info206 """207 params = {208 'page': page,209 'perPage': perPage210 }211 resp = self._do('GET', params=params)212 return self._parse_result(resp, parse_list_dnssecs, ListDnssecsResult)213 def get_dnssec(self, digest):214 """Retrieves the details for a key registered with the registry.215 Parameters216 ----------217 digest : string218 Digest is the digest for the DNSKEY RR to retrieve.219 Returns220 -------221 :class:`~namecom.result_models.GetDnssecResult`222 a response result instance with parsed response info223 """224 resp = self._do('GET', relative_path='/{digest}'.format(digest=digest))225 return self._parse_result(resp, parse_get_dnssec, GetDnssecResult)226 def create_dnssec(self, keyTag, algorithm, digestType, digest):227 """Registers a DNSSEC key with the registry.228 Parameters229 ----------230 keyTag : int231 key tag value of the DNSKEY RR232 algorithm : int233 an integer identifying the algorithm used for signing234 digestType : int235 an integer identifying the algorithm used to create the digest236 digest : string237 a digest of the DNSKEY RR that is registered with the registry238 Returns239 -------240 :class:`~namecom.result_models.CreateDnssecResult`241 a response result instance with parsed response info242 """243 data = json_dumps({244 'keyTag': keyTag,245 'algorithm': algorithm,246 'digestType': digestType,247 'digest': digest248 })249 resp = self._do('POST', data=data)250 return self._parse_result(resp, parse_create_dnssec, CreateDnssecResult)251 def delete_dnssec(self, digest):252 """Removes a DNSSEC key from the registry.253 Parameters254 ----------255 digest : string256 a digest of the DNSKEY RR that is registered with the registry257 Returns258 -------259 :class:`~namecom.result_models.DeleteDnssecResult`260 a response result instance with parsed response info261 """262 resp = self._do('DELETE', relative_path='/{digest}'.format(digest=digest))263 return self._parse_result(resp, parse_delete_dnssec, DeleteDnssecResult)264class DomainApi(_ApiBase):265 """266 The api class for Domain.267 More details about each parameter :class:`here <namecom.Domain>`.268 Official namecom documentation : https://www.name.com/api-docs/domain269 """270 def __init__(self, auth, use_test_env=False):271 """272 Parameters273 ----------274 auth : :class:`~namecom.Auth`275 http authentication to use276 use_test_env : bool277 whether runs in test environment278 """279 super(DomainApi, self).__init__(auth, use_test_env)280 self.endpoint = '/v4/domains'281 def list_domains(self, page=1, perPage=1000):282 """Returns all domains in the account. It omits some information that can be retrieved from GetDomain.283 Parameters284 ----------285 page: int286 which page to return287 perPage : int288 the number of records to return per request289 Returns290 -------291 :class:`~namecom.result_models.ListDomainsResult`292 a response result instance with parsed response info293 """294 params = {295 'page': page,296 'perPage': perPage297 }298 resp = self._do('GET', params=params)299 return self._parse_result(resp, parse_list_domains, ListDomainsResult)300 def get_domain(self, domainName):301 """Returns details about a specific domain302 Parameters303 ----------304 domainName : string305 name of the domain to retrieve306 Returns307 -------308 :class:`~namecom.result_models.GetDomainResult`309 a response result instance with parsed response info310 """311 resp = self._do('GET', relative_path='/{domainName}'.format(domainName=domainName))312 return self._parse_result(resp, parse_get_domain, GetDomainResult)313 def create_domain(self, domain, purchasePrice, purchaseType='registration',314 years=1, tldRequirements=None, promoCode=None):315 """316 Parameters317 ----------318 domain : :class:`~namecom.Domain`319 the domain object to create320 purchasePrice : float321 the amount to pay for the domain322 purchaseType : string323 PurchaseType defaults to "registration" but should be copied from the result of a search command otherwise324 years : int325 how many years to register the domain for.326 tldRequirements : dict[string -> string]327 TLDRequirements is a way to pass additional data that is required by some registries328 promoCode : string329 PromoCode is not yet implemented330 Returns331 -------332 :class:`~namecom.result_models.CreateDomainResult`333 a response result instance with parsed response info334 """335 data = json_dumps({336 'domain': domain,337 'purchasePrice': purchasePrice,338 'purchaseType': purchaseType,339 'years': years,340 'tldRequirements': tldRequirements if tldRequirements else [],341 'promoCode': promoCode342 })343 resp = self._do('POST', data=data)344 return self._parse_result(resp, parse_create_domain, CreateDomainResult)345 def enable_autorenew(self, domainName):346 """Enables the domain to be automatically renewed when it gets close to expiring.347 Parameters348 ----------349 domainName : string350 name of the domain to retrieve351 Returns352 -------353 :class:`~namecom.result_models.EnableAutorenewResult`354 a response result instance with parsed response info355 """356 resp = self._do('POST', relative_path='/{domainName}:enableAutorenew'.format(domainName=domainName))357 return self._parse_result(resp, parse_enable_autorenew, EnableAutorenewResult)358 def disable_autorenew(self, domainName):359 """Disables automatic renewals, thus requiring the domain to be renewed manually.360 Parameters361 ----------362 domainName : string363 name of the domain to retrieve364 Returns365 -------366 :class:`~namecom.result_models.DisableAutorenewResult`367 a response result instance with parsed response info368 """369 resp = self._do('POST', relative_path='/{domainName}:disableAutorenew'.format(domainName=domainName))370 return self._parse_result(resp, parse_disable_autorenew, DisableAutorenewResult)371 def renew_domain(self, domainName, purchasePrice, years=1, promoCode=None):372 """Renew a domain. Purchase_price is required if the renewal is not regularly priced.373 Parameters374 ----------375 domainName : string376 name of the domain to renew377 purchasePrice : float378 the amount to pay for the domain renewal379 years : int380 how many years to renew the domain for381 promoCode : string382 PromoCode is not yet implemented383 Returns384 -------385 :class:`~namecom.result_models.RenewDomainResult`386 a response result instance with parsed response info387 """388 data = json_dumps({389 'purchasePrice': purchasePrice,390 'years': years,391 'promoCode': promoCode392 })393 resp = self._do('POST', relative_path='/{domainName}:renew'.format(domainName=domainName), data=data)394 return self._parse_result(resp, parse_renew_domain, RenewDomainResult)395 def get_auth_code_for_domain(self, domainName):396 """Returns the Transfer Authorization Code for the domain.397 Parameters398 ----------399 domainName : string400 name of the domain to renew401 Returns402 -------403 :class:`~namecom.result_models.GetAuthCodeForDomainResult`404 a response result instance with parsed response info405 """406 resp = self._do('GET', relative_path='/{domainName}:getAuthCode'.format(domainName=domainName))407 return self._parse_result(resp, parse_get_authcode, GetAuthCodeForDomainResult)408 def purchase_privacy(self, domainName, purchasePrice, years=1, promoCode=None):409 """Add Whois Privacy protection to a domain or will an renew existing subscription.410 Parameters411 ----------412 domainName : string413 name of the domain to renew414 purchasePrice : float415 the amount to pay for the domain renewal416 years : int417 how many years to renew the domain for418 promoCode : string419 PromoCode is not yet implemented420 Returns421 -------422 :class:`~namecom.result_models.PurchasePrivacyResult`423 a response result instance with parsed response info424 """425 data = json_dumps({426 'purchasePrice': purchasePrice,427 'years': years,428 'promoCode': promoCode429 })430 resp = self._do('POST', relative_path='/{domainName}:purchasePrivacy'.format(domainName=domainName), data=data)431 return self._parse_result(resp, parse_purchase_privacy, PurchasePrivacyResult)432 def set_nameservers(self, domainName, nameservers):433 """Set the nameservers for the Domain.434 Parameters435 ----------436 domainName : string437 name of the domain to set the nameservers for438 nameservers : []string439 a list of the nameservers to set440 Returns441 -------442 :class:`~namecom.result_models.SetNameserversResult`443 a response result instance with parsed response info444 """445 data = json_dumps({446 'nameservers': nameservers447 })448 resp = self._do('POST', relative_path='/{domainName}:setNameservers'.format(domainName=domainName), data=data)449 return self._parse_result(resp, parse_set_nameservers, SetNameserversResult)450 def set_contacts(self, domainName, contacts):451 """"Set the contacts for the Domain.452 Parameters453 ----------454 domainName : string455 name of the domain to set the contacts for456 contacts : Contacts457 contacts to set458 Returns459 -------460 :class:`~namecom.result_models.SetContactsResult`461 a response result instance with parsed response info462 """463 data = json_dumps({464 'contacts': contacts465 })466 resp = self._do('POST', relative_path='/{domainName}:setContacts'.format(domainName=domainName), data=data)467 return self._parse_result(resp, parse_set_contacts, SetContactsResult)468 def lock_domain(self, domainName):469 """Lock a domain so that it cannot be transfered to another registrar.470 Parameters471 ----------472 domainName : string473 name of the domain to lock474 Returns475 -------476 :class:`~namecom.result_models.LockDomainResult`477 a response result instance with parsed response info478 """479 resp = self._do('POST', relative_path='/{domainName}:lock'.format(domainName=domainName))480 return self._parse_result(resp, parse_lock_domain, LockDomainResult)481 def unlock_domain(self, domainName):482 """Unlock a domain so that it can be transfered to another registrar.483 Parameters484 ----------485 domainName : string486 name of the domain to unlock487 Returns488 -------489 :class:`~namecom.result_models.UnlockDomainResult`490 a response result instance with parsed response info491 """492 resp = self._do('POST', relative_path='/{domainName}:unlock'.format(domainName=domainName))493 return self._parse_result(resp, parse_unlock_domain, UnlockDomainResult)494 def check_availability(self, domainNames, promoCode=None):495 """Check a list of domains to see if they are purchaseable. A Maximum of 50 domains can be specified.496 Parameters497 ----------498 domainNames : []string499 the list of domains to check if they are available500 promoCode : string501 PromoCode is not yet implemented502 Returns503 -------504 :class:`~namecom.result_models.CheckAvailabilityResult`505 a response result instance with parsed response info506 """507 data = json_dumps({508 'domainNames': domainNames,509 'promoCode': promoCode510 })511 resp = self._do('POST', relative_path=':checkAvailability', data=data)512 return self._parse_result(resp, parse_check_availability, CheckAvailabilityResult)513 def search(self, keyword, tldFilter=None, timeout=1000, promoCode=None):514 """Perform a search for specified keywords.515 Parameters516 ----------517 keyword : string518 the search term to search for519 tldFilter : []string520 TLDFilter will limit results to only contain the specified TLDs521 timeout : int522 Timeout is a value in milliseconds on how long to perform the search for523 promoCode : string524 PromoCode is not yet implemented525 Returns526 -------527 :class:`~namecom.result_models.SearchResult`528 a response result instance with parsed response info529 """530 data = json_dumps({531 'keyword': keyword,532 'tldFilter': tldFilter if tldFilter else [],533 'timeout': timeout,534 'promoCode': promoCode535 })536 resp = self._do('POST', relative_path=':search', data=data)537 return self._parse_result(resp, parse_search, SearchResult)538 def search_stream(self, keyword, tldFilter=None, timeout=1000, promoCode=None):539 """Return JSON encoded SearchResults as they are recieved from the registry540 Parameters541 ----------542 keyword : string543 the search term to search for544 tldFilter : []string545 TLDFilter will limit results to only contain the specified TLDs546 timeout : int547 Timeout is a value in milliseconds on how long to perform the search for548 promoCode : string549 PromoCode is not yet implemented550 Returns551 -------552 :class:`~namecom.result_models.SearchStreamResult`553 a response result instance with parsed response info554 """555 data = json_dumps({556 'keyword': keyword,557 'tldFilter': tldFilter if tldFilter else [],558 'timeout': timeout,559 'promoCode': promoCode560 })561 resp = self._do('POST', relative_path=':searchStream', data=data, stream=True)562 result = SearchStreamResult(resp)563 parse_search_stream(result, resp)564 return result565class EmailForwardingApi(_ApiBase):566 """567 The api class for name.com EmailForwarding.568 More details about each parameter :class:`here <namecom.EmailForwarding>`.569 Official namecom documentation : https://www.name.com/api-docs/EmailForwardings570 """571 def __init__(self, domainName, auth, use_test_env=False):572 """573 Parameters574 ----------575 domainName : string576 domain that dns records belongs to577 auth : :class:`~namecom.Auth`578 http authentication to use579 use_test_env : bool580 whether runs in test environment581 """582 super(EmailForwardingApi, self).__init__(auth, use_test_env)583 self.endpoint = '/v4/domains/{domain_name}/email/forwarding'.format(domain_name=domainName)584 def list_email_forwardings(self, perPage=1000, page=1):585 """Returns a pagenated list of email forwarding entries for a domain.586 Parameters587 ----------588 perPage : int589 the number of records to return per request590 page : int591 which page to return592 Returns593 -------594 :class:`~namecom.result_models.ListEmailForwardingsResult`595 a response result instance with parsed response info596 """597 params = {598 'page': page,599 'perPage': perPage600 }601 resp = self._do('GET', params=params)602 return self._parse_result(resp, parse_list_email_forwardings, ListEmailForwardingsResult)603 def get_mail_forwarding(self, emailBox):604 """Returns an email forwarding entry605 Parameters606 ----------607 emailBox : string608 which email box to retrieve609 Returns610 -------611 :class:`~namecom.result_models.GetEmailForwardingResult`612 a response result instance with parsed response info613 """614 resp = self._do('GET', relative_path='/{emailBox}'.format(emailBox=emailBox))615 return self._parse_result(resp, parse_get_email_forwarding, GetEmailForwardingResult)616 def create_email_forwarding(self, emailBox, emailTo):617 """Creates an email forwarding entry.618 If this is the first email forwarding entry, it may modify the MX records for the domain accordingly.619 Parameters620 ----------621 emailBox : string622 the user portion of the email address to forward623 emailTo : string624 the entire email address to forward email to625 Returns626 -------627 :class:`~namecom.result_models.GetEmailForwardingResult`628 a response result instance with parsed response info629 """630 data = json_dumps({631 'emailBox': emailBox,632 'emailTo': emailTo633 })634 resp = self._do('POST', data=data)635 return self._parse_result(resp, parse_create_email_forwarding, CreateEmailForwardingResult)636 def update_email_forwarding(self, emailBox, emailTo):637 """Updates which email address the email is being forwarded to.638 Parameters639 ----------640 emailBox : string641 the user portion of the email address to forward642 emailTo : string643 the entire email address to forward email to644 Returns645 -------646 :class:`~namecom.result_models.GetEmailForwardingResult`647 a response result instance with parsed response info648 """649 data = json_dumps({650 'emailTo': emailTo651 })652 resp = self._do('PUT', relative_path='/{emailBox}'.format(emailBox=emailBox), data=data)653 return self._parse_result(resp, parse_update_email_forwarding, UpdateEmailForwardingResult)654 def delete_email_forwarding(self, emailBox):655 """Deletes the email forwarding entry.656 Parameters657 ----------658 emailBox : string659 the user portion of the email address to forward660 Returns661 -------662 :class:`~namecom.result_models.DeleteEmailForwardingResult`663 a response result instance with parsed response info664 """665 resp = self._do('DELETE', relative_path='/{emailBox}'.format(emailBox=emailBox))666 return self._parse_result(resp, parse_delete_email_forwarding, DeleteEmailForwardingResult)667class TransferApi(_ApiBase):668 """669 The api class for Domain Transfer.670 More details about each parameter :class:`here <namecom.Transfer>`.671 Official namecom documentation : https://www.name.com/api-docs/Transfers672 """673 def __init__(self, auth, use_test_env=False):674 """675 Parameters676 ----------677 auth : :class:`~namecom.Auth`678 http authentication to use679 use_test_env : bool680 whether runs in test environment681 """682 super(TransferApi, self).__init__(auth, use_test_env)683 self.endpoint = '/v4/transfers'684 def list_transfers(self, page=1, perPage=1000):685 """Lists all pending transfer in requests.686 To get the information related to a non-pending transfer, you can use the GetTransfer function for that.687 Returns688 -------689 :class:`~namecom.result_models.ListTransferResult`690 a response result instance with parsed response info691 """692 params = {693 'page': page,694 'perPage': perPage695 }696 resp = self._do('GET', params=params)697 return self._parse_result(resp, parse_list_transfers, ListTransfersResult)698 def get_transfer(self, domainName):699 """Gets details for a transfer request.700 Parameters701 ----------702 domainName : str703 DomainName is the domain you want to get the transfer information for704 Returns705 -------706 :class:`~namecom.result_models.GetTransferResult`707 a response result instance with parsed response info708 """709 resp = self._do('GET', relative_path='/{domainName}'.format(domainName=domainName))710 return self._parse_result(resp, parse_get_transfer, GetTransferResult)711 def create_transfer(self, domainName, authCode, purchasePrice, privacyEnabled=False, promoCode=None):712 """Purchases a new domain transfer request.713 Parameters714 ----------715 domainName : str716 DomainName is the domain you want to transfer to Name.com717 authCode : str718 AuthCode is the authorization code for the transfer719 purchasePrice : float720 the amount to pay for the transfer of the domain721 privacyEnabled : bool722 a flag on whether to purchase Whois Privacy with the transfer723 promoCode : str724 PromoCode is not implemented yet725 Returns726 -------727 :class:`~namecom.result_models.CreateTransferResult`728 a response result instance with parsed response info729 """730 data = json_dumps({731 'domainName': domainName,732 'authCode': authCode,733 'purchasePrice': purchasePrice,734 'privacyEnabled': privacyEnabled,735 'promoCode': promoCode736 })737 resp = self._do('POST', data=data)738 return self._parse_result(resp, parse_create_transfer, CreateTransferResult)739 def cancel_transfer(self, domainName):740 """Cancels a pending transfer request and refunds the amount to account credit.741 Parameters742 ----------743 domainName : str744 DomainName is the domain to be transfered to Name.com745 Returns746 -------747 :class:`~namecom.result_models.CancelTransferResult`748 a response result instance with parsed response info749 """750 resp = self._do('POST', relative_path='/{domainName}:cancel'.format(domainName=domainName))751 return self._parse_result(resp, parse_cancel_tranfer, CancelTransferResult)752class URLForwardingApi(_ApiBase):753 def __init__(self, domainName, auth, use_test_env=False):754 """755 Parameters756 ----------757 domainName : str758 domain name to manipulate url forwarding for759 auth : :class:`~namecom.Auth`760 http authentication to use761 use_test_env : bool762 whether runs in test environment763 """764 super(URLForwardingApi, self).__init__(auth, use_test_env)765 self.endpoint = '/v4/domains/{domainName}/url/forwarding'.format(domainName=domainName)766 def list_url_forwardings(self, page=1, perPage=1000):767 """Returns a pagenated list of URL forwarding entries for a domain.768 Parameters769 ----------770 page: int771 which page to return772 perPage : int773 the number of records to return per request774 Returns775 -------776 :class:`~namecom.result_models.ListURLForwardingsResult`777 a response result instance with parsed response info778 """779 params = {780 'page': page,781 'perPage': perPage782 }783 resp = self._do('GET', params=params)784 return self._parse_result(resp, parse_list_url_forwardings, ListURLForwardingsResult)785 def get_url_forwarding(self, host):786 """Returns an URL forwarding entry.787 Parameters788 ----------789 host : str790 the part of the domain name before the domain791 Returns792 -------793 :class:`~namecom.result_models.GetURLForwardingResult`794 a response result instance with parsed response info795 """796 resp = self._do('GET', relative_path='/{host}'.format(host=host))797 return self._parse_result(resp, parse_get_url_forwarding, GetURLForwardingResult)798 def create_url_forwarding(self, host, forwardsTo, type=None, title=None, meta=None):799 """Creates an URL forwarding entry.800 If this is the first URL forwarding entry, it may modify the A records for the domain accordingly.801 Parameters802 ----------803 host : str804 the entirety of the hostname. i.e. www.example.org805 forwardsTo : str806 the URL this host will be forwarded to807 type : str808 the type of forwarding809 title : str810 the title for the html page to use if the type is masked811 meta : str812 the meta tags to add to the html page if the type is masked813 Returns814 -------815 :class:`~namecom.result_models.CreateURLForwardingResult`816 a response result instance with parsed response info817 """818 data = json_dumps({819 'host': host,820 'forwardsTo': forwardsTo,821 'type': type,822 'title': title,823 'meta': meta824 })825 resp = self._do('POST', data=data)826 return self._parse_result(resp, parse_create_url_forwarding, CreateURLForwardingResult)827 def update_url_forwarding(self, host, forwardsTo, type=None, title=None, meta=None):828 """Updates which URL the host is being forwarded to.829 Parameters830 ----------831 host : str832 the entirety of the hostname. i.e. www.example.org833 forwardsTo : str834 the URL this host will be forwarded to835 type : str836 the type of forwarding837 title : str838 the title for the html page to use if the type is masked839 meta : str840 the meta tags to add to the html page if the type is masked841 Returns842 -------843 :class:`~namecom.result_models.UpdateURLForwardingResult`844 a response result instance with parsed response info845 """846 data = json_dumps({847 'forwardsTo': forwardsTo,848 'type': type,849 'title': title,850 'meta': meta851 })852 resp = self._do('PUT', relative_path='/{host}'.format(host=host), data=data)853 return self._parse_result(resp, parse_update_url_forwarding, UpdateURLForwardingResult)854 def delete_url_forwarding(self, host):855 """Deletes the URL forwarding entry.856 Parameters857 ----------858 host : str859 the entirety of the hostname. i.e. www.example.org860 Returns861 -------862 :class:`~namecom.result_models.DeleteURLForwardingResult`863 a response result instance with parsed response info864 """865 resp = self._do('DELETE', relative_path='/{host}'.format(host=host))866 return self._parse_result(resp, parse_delete_url_forwarding, DeleteURLForwardingResult)867class VanityNameserverApi(_ApiBase):868 def __init__(self, domainName, auth, use_test_env=False):869 """870 Parameters871 ----------872 domainName : str873 domain name to manipulate nameserver for874 auth : :class:`~namecom.Auth`875 http authentication to use876 use_test_env : bool877 whether runs in test environment878 """879 super(VanityNameserverApi, self).__init__(auth, use_test_env)880 self.endpoint = '/v4/domains/{domainName}/vanity_nameservers'.format(domainName=domainName)881 def list_vanity_nameservers(self, page=1, perPage=1000):882 """Lists all nameservers registered with the registry.883 It omits the IP addresses from the response. Those can be found from calling GetVanityNameserver.884 Parameters885 ----------886 page: int887 which page to return888 perPage : int889 the number of records to return per request890 Returns891 -------892 :class:`~namecom.result_models.ListVanityNameserversResult`893 a response result instance with parsed response info894 """895 params = {896 'page': page,897 'perPage': perPage898 }899 resp = self._do('GET', params=params)900 return self._parse_result(resp, parse_list_vanity_nameservers, ListVanityNameserversResult)901 def get_vanity_nameserver(self, hostname):902 """GetVanityNameserver gets the details for a vanity nameserver registered with the registry.903 Parameters904 ----------905 hostname: str906 the hostname of the nameserver907 Returns908 -------909 :class:`~namecom.result_models.GetVanityNameserverResult`910 a response result instance with parsed response info911 """912 resp = self._do('GET', relative_path='/{hostname}'.format(hostname=hostname))913 return self._parse_result(resp, parse_get_vanity_nameserver, GetVanityNameserverResult)914 def create_vanity_nameserver(self, hostname, ips):915 """Registers a nameserver with the registry.916 Parameters917 ----------918 hostname: str919 the hostname of the nameserver920 ips: []str921 a list of IP addresses that are used for glue records for this nameserver922 Returns923 -------924 :class:`~namecom.result_models.CreateVanityNameserverResult`925 a response result instance with parsed response info926 """927 data = json_dumps({928 'hostname': hostname,929 'ips': ips930 })931 resp = self._do('POST', data=data)932 return self._parse_result(resp, parse_create_vanity_nameserver, CreateVanityNameserverResult)933 def update_vanity_nameserver(self, hostname, ips):934 """Update the glue record IP addresses at the registry.935 Parameters936 ----------937 hostname: str938 the domain to for the vanity nameserver939 ips: []str940 a list of IP addresses that are used for glue records for this nameserver941 Returns942 -------943 :class:`~namecom.result_models.UpdateVanityNameserverResult`944 a response result instance with parsed response info945 """946 data = json_dumps({947 'ips': ips948 })949 resp = self._do('PUT', relative_path='/{hostname}'.format(hostname=hostname), data=data)950 return self._parse_result(resp, parse_update_vanity_nameserver, UpdateVanityNameserverResult)951 def delete_vanity_nameserver(self, hostname):952 """Unregisteres the nameserver at the registry.953 This might fail if the registry believes the nameserver is in use.954 Parameters955 ----------956 hostname : str957 the domain of the vanity nameserver to delete958 Returns959 -------960 :class:`~namecom.result_models.DeleteVanityNameserverResult`961 a response result instance with parsed response info962 """963 resp = self._do('DELETE', relative_path='/{hostname}'.format(hostname=hostname))...

Full Screen

Full Screen

account.py

Source:account.py Github

copy

Full Screen

1#!/usr/bin/env python2# -*- coding: utf-8 -*-3"""4:mod:`account`5=======================6List of bank account number formats from `Bankgirot7<https://www.bankgirot.se/globalassets/dokument/anvandarmanualer/bankernaskontonummeruppbyggnad_anvandarmanual_sv.pdf>`_.8.. moduleauthor:: hbldh <henrik.blidh@swedwise.com>9Created on 2017-02-15, 11:4110"""11from __future__ import division12from __future__ import print_function13from __future__ import absolute_import14from __future__ import unicode_literals15import re16from bankkonto.exceptions import BankkontoValidationError17TYPE_1_ACCOUNT_NUMBERS = """18Amfa Bank AB 9660-9669 00000xxxxxxC 219Avanza Bank AB 9550-9569 00000xxxxxxC 220BlueStep Finans AB 9680-9689 00000xxxxxxC 121BNP Paribas Fortis Bank 9470-9479 00000xxxxxxC 222Citibank 9040-9049 00000xxxxxxC 223Danske Bank 1200-1399 00000xxxxxxC 124Danske Bank 2400-2499 00000xxxxxxC 125DNB Bank 9190-9199 00000xxxxxxC 226DNB Bank 9260-9269 00000xxxxxxC 227Ekobanken 9700-9709 00000xxxxxxC 228Erik Penser AB 9590 – 9599 00000xxxxxxC 229Forex Bank 9400-9449 00000xxxxxxC 130ICA Banken AB 9270-9279 00000xxxxxxC 131IKANO Bank 9170-9179 00000xxxxxxC 132JAK Medlemsbank 9670-9679 00000xxxxxxC 233Landshypotek AB 9390-9399 00000xxxxxxC 234Lån & Spar Bank Sverige 9630-9639 00000xxxxxxC 135Länsförsäkringar Bank 3400-3409 00000xxxxxxC 136Länsförsäkringar Bank 9020-9029 00000xxxxxxC 237Länsförsäkringar Bank 9060-9069 00000xxxxxxC 138Marginalen Bank 9230-9239 00000xxxxxxC 139Nordax Bank AB 9640-9649 00000xxxxxxC 240Nordea 1100-1199 00000xxxxxxC 141Nordea 1400-2099 00000xxxxxxC 142Nordea 3000-3299 00000xxxxxxC 143Nordea 3301-3399 00000xxxxxxC 144Nordea 3410-3781 00000xxxxxxC 145Nordea 3783-3999 00000xxxxxxC 146Nordea 4000-4999 00000xxxxxxC 247Nordnet Bank 9100-9109 00000xxxxxxC 248Resurs Bank 9280-9289 00000xxxxxxC 149Riksgälden 9880-9889 00000xxxxxxC 250Royal bank of Scotland 9090-9099 00000xxxxxxC 251Santander Consumer Bank AS 9460-9469 00000xxxxxxC 152SBAB 9250-9259 00000xxxxxxC 153SEB 5000-5999 00000xxxxxxC 154SEB 9120-9124 00000xxxxxxC 155SEB 9130-9149 00000xxxxxxC 156Skandiabanken 9150-9169 00000xxxxxxC 257Swedbank 7000-7999 00000xxxxxxC 158Ålandsbanken Sverige AB 2300-2399 00000xxxxxxC 259"""60TYPE_2_ACCOUNT_NUMBERS = """61Danske Bank 9180-9189 00xxxxxxxxxC 162Handelsbanken 6000-6999 000xxxxxxxxC 263Nordea/Plusgirot 9500-9549 00xxxxxxxxxC 364Nordea/Plusgirot 9960-9969 00xxxxxxxxxC 365Nordea - personkonto 3300 00xxxxxxxxxC 166Nordea - personkonto 3782 00xxxxxxxxxC 167Riksgälden 9890 -9899 00xxxxxxxxxC 168Sparbanken Syd 9570- 9579 00xxxxxxxxxC 169Swedbank 8000-8999 00xxxxxxxxxC 370Swedbank 9300-9329 00xxxxxxxxxC 171Swedbank (f.d. Sparbanken Öresund) 9330-9349 00xxxxxxxxxC 172"""73_type_1 = [(_parse_result[0], int(_parse_result[1]),74 int(_parse_result[2]) if _parse_result[2] else int(_parse_result[1]),75 _parse_result[3], int(_parse_result[4])) for76 _parse_result in re.findall('(.+)\\s([\\d]+)-*(\\d*)\\s(0+x+C)\\s(\\d+)', TYPE_1_ACCOUNT_NUMBERS.strip())]77_type_1.sort(key=lambda x: x[1])78_type_2 = [(_parse_result[0], int(_parse_result[1]),79 int(_parse_result[2]) if _parse_result[2] else int(_parse_result[1]),80 _parse_result[3], int(_parse_result[4])) for81 _parse_result in re.findall('(.+)\\s([\\d]+)-*(\\d*)\\s(0+x+C)\\s(\\d+)', TYPE_2_ACCOUNT_NUMBERS.strip())]82_type_2.sort(key=lambda x: x[1])83def validate(clearing_number, bank_account_number):84 clearing_number = re.sub('\\D', '', str(clearing_number))85 bank_account_number = re.sub('\\D', '', str(bank_account_number))86 if clearing_number[0] == '8':87 # Swedbank account. Clearing number has five digits.88 # Disregard the last one for validation purposes.89 if len(clearing_number) != 5:90 raise BankkontoValidationError("Clearing number for Swedbank accounts must be 5 digits.")91 clearing_number = clearing_number[:-1]92 else:93 if len(clearing_number) != 4:94 raise BankkontoValidationError("Clearing number must be 4 digits.")95 bank_name, type_, nbr_format, footnote = get_account_number_format_based_on_clearing_number(clearing_number)96 if len(nbr_format.strip('0')) != len(bank_account_number):97 raise BankkontoValidationError("Bank account number for {0} must be {1} digits.".format(98 bank_name, len(nbr_format.strip('0'))))99 if type_ == 1:100 if footnote == 1:101 if not _module_11(clearing_number[1:], bank_account_number):102 raise BankkontoValidationError("Bank account number {0} for {1} has invalid control digit: {2}".format(103 bank_account_number, bank_name, bank_account_number[-1]))104 elif footnote == 2:105 if not _module_11(clearing_number, bank_account_number):106 raise BankkontoValidationError("Bank account number {0} for {1} has invalid control digit: {2}".format(107 bank_account_number, bank_name, bank_account_number[-1]))108 else:109 raise BankkontoValidationError("Unknown Type 1 footnote value: {0}.".format(footnote))110 elif type_ == 2:111 if footnote == 1:112 if not _module_10(bank_account_number):113 raise BankkontoValidationError("Bank account number {0} for {1} has invalid control digit: {2}".format(114 bank_account_number, bank_name, bank_account_number[-1]))115 elif footnote == 2:116 if not _module_11('', bank_account_number):117 raise BankkontoValidationError("Bank account number {0} for {1} has invalid control digit: {2}".format(118 bank_account_number, bank_name, bank_account_number[-1]))119 elif footnote == 3:120 if not _module_10(bank_account_number):121 # FIXME: The account number consists of 10 digits. Checksum calculation uses the last ten digits using122 # the modulus 10 check, according format for account number (clearing number not123 # included). However in rare occasions some of Swedbank’s accounts cannot be validated by124 # a checksum calculation.125 raise BankkontoValidationError("Bank account number {0} for {1} has invalid control digit: {2}".format(126 bank_account_number, bank_name, bank_account_number[-1]))127 else:128 raise BankkontoValidationError("Unknown Type 2 footnote value: {0}.".format(footnote))129 else:130 raise BankkontoValidationError("Unknown account type: {0}.".format(type_))131 return True132def get_account_number_format_based_on_clearing_number(clearing_number):133 clearing_number = int(clearing_number)134 if clearing_number < 1000 or clearing_number > 9999:135 raise BankkontoValidationError("Clearing number must be in range 1000 - 9999.")136 res = list(filter(lambda x: x[1] <= clearing_number <= x[2], _type_1))137 if res:138 return res[0][0], 1, res[0][3], res[0][4]139 res = list(filter(lambda x: x[1] <= clearing_number <= x[2], _type_2))140 if res:141 return res[0][0], 2, res[0][3], res[0][4]142 raise BankkontoValidationError("Clearing number {0} does not correspond to any Swedish bank.".format(clearing_number))143def _module_11(clearing_number, bank_account_number):144 weights = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)145 value = sum([weights[i] * int(c) for i, c in enumerate(146 (str(clearing_number) + str(bank_account_number))[::-1])])147 return (value % 11) == 0148def _module_10(bank_account_number):149 values = [(2 if i % 2 else 1) * int(c) for i, c in enumerate(150 (str(bank_account_number))[::-1])]151 value = sum([(v - 9) if (v > 9) else v for v in values])...

Full Screen

Full Screen

test_firefox_profile_parsing.py

Source:test_firefox_profile_parsing.py Github

copy

Full Screen

...27 def setUp(self):28 self.results = []29 @unittest.skipIf(JYTHON, 'ApprovalTest does not work with Jython')30 def test_single_method(self):31 self._parse_result(self.creator._get_ff_profile('set_preference("key1", "arg1")'))32 self._parse_result(33 self.creator._get_ff_profile('set_preference("key1", "arg1");set_preference("key1", "arg1")'))34 self._parse_result(35 self.creator._get_ff_profile('set_preference("key1", "arg1") ; set_preference("key2", "arg2")'))36 profile = self.creator._get_ff_profile('update_preferences()')37 self.results.append(isinstance(profile, webdriver.FirefoxProfile))38 try:39 self.creator._get_ff_profile('wrong_name("key1", "arg1")')40 except AttributeError as error:41 self.results.append(error)42 try:43 self.creator._get_ff_profile('set_proxy("foo")')44 except Exception as error:45 self.results.append(str(error))46 verify_all('Firefox profile parsing', self.results, reporter=self.reporter)47 def _parse_result(self, result):48 to_str = ''49 if 'key1' in result.default_preferences:50 to_str = '%s %s %s' % (to_str, 'key1', result.default_preferences['key1'])51 if 'key2' in result.default_preferences:52 to_str = '%s %s %s' % (to_str, 'key2', result.default_preferences['key2'])...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tappy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful