MCPcopy Create free account
hub / github.com/MacHu-GWU/uszipcode-project / by_zipcode

Method by_zipcode

uszipcode/search.py:567–594  ·  view source on GitHub ↗

Search zipcode by exact 5 digits zipcode. No zero padding is needed. :param zipcode: int or str, the zipcode will be automatically zero padding to 5 digits. :param zipcode_type: str or :class`~uszipcode.model.ZipcodeType` attribute. by default, it re

(self,
                   zipcode,
                   zipcode_type=None,
                   zero_padding=True)

Source from the content-addressed store, hash-verified

565 return q.all()
566
567 def by_zipcode(self,
568 zipcode,
569 zipcode_type=None,
570 zero_padding=True):
571 """
572 Search zipcode by exact 5 digits zipcode. No zero padding is needed.
573
574 :param zipcode: int or str, the zipcode will be automatically
575 zero padding to 5 digits.
576 :param zipcode_type: str or :class`~uszipcode.model.ZipcodeType` attribute.
577 by default, it returns any zipcode type.
578 :param zero_padding: bool, toggle on and off automatic zero padding.
579 """
580 if zero_padding:
581 zipcode = str(zipcode).zfill(5)
582 else: # pragma: no cover
583 zipcode = str(zipcode)
584
585 res = self.query(
586 zipcode=zipcode,
587 sort_by=None,
588 returns=1,
589 zipcode_type=zipcode_type,
590 )
591 if len(res):
592 return res[0]
593 else:
594 return self.zip_klass()
595
596 def by_prefix(self,
597 prefix,

Callers 5

testMethod · 0.80
test_by_zipcodeMethod · 0.80
test_edge_caseMethod · 0.80
testMethod · 0.80

Calls 1

queryMethod · 0.95

Tested by 5

testMethod · 0.64
test_by_zipcodeMethod · 0.64
test_edge_caseMethod · 0.64
testMethod · 0.64