def _validate_cik(self, cik): """Validates that given CIK *could* be valid. Args: cik (Union[str, int]): Central index key (CIK) to validate. Returns: cik (Union[str, int]): Validated CIK. Note that the CIK is only validated in that it *could* be valid. All CIKs must be 10 digits, but not all 10 digit numbers are valid CIKs. Raises: ValueError: If given cik is not str or int CIKError: If cik is not a 10 digit number. """ if not isinstance(cik, (str, int)): raise ValueError("CIK must be of type str or int.") elif isinstance(cik, str): if len(cik) != 10 or not cik.isdigit(): raise CIKError(cik) elif isinstance(cik, int): if cik not in range(10**9, 10**10): raise CIKError(cik) return cik
def _validate_cik(cik): """Validates that given CIK *could* be valid. Args: cik (Union[CIK, str, int]): Central index key (CIK) to validate. Returns: cik (Union[str, list of str]): Validated CIK. Note that the CIK is only validated in that it *could* be valid. CIKs formatted as 10 digits, but not all 10 digit numbers are valid CIKs. Raises: ValueError: If given cik is not str, int, or CIK object. CIKError: If cik is not a 10 digit number or valid CIK object """ # creating CIK object should check to see if ciks are valid if not isinstance(cik, CIK): if not isinstance(cik, (str, int)): raise ValueError("CIK must be of type str or int.") elif isinstance(cik, str): if len(cik) != 10 or not cik.isdigit(): raise CIKError(cik) elif isinstance(cik, int): if cik > 10**10: raise CIKError(cik) elif cik < 10**9: return str(cik).zfill( 10) # pad with zeros if less than 10 digits given return str(cik) else: return cik.cik
def _check_cik(cik): """Check if CIK is valid. Args: cik (Union[str, int]): Central Index Key assigned by SEC. See https://www.sec.gov/edgar/searchedgar/cik.htm to search for Returns: (Union[str, int]): Valid CIK Raises: CIKError: An error occured while verifying the CIK. """ invalid_str = isinstance(cik, str) and len(cik) != 10 invalid_int = isinstance(cik, int) and not (999999999 < cik < 10**10) invalid_type = not isinstance(cik, (int, str)) if invalid_str or invalid_int or invalid_type: raise CIKError(cik) else: return cik
def _get_all_ciks(self): """ Gets CIKs based on _lookup attribute. Returns: ciks (Union[str, list]): CIKs as string or list of strings based on lookup attribute. Raises: CIKError: If any given value in _lookup does not return CIK. """ if isinstance(self._lookup, str): return self._get_cik(self._lookup) elif isinstance(self._lookup, (tuple, list, set)): ciks = [] for cik in self._lookup: ciks.append(self._get_cik(cik)) return ciks else: raise CIKError(self._lookup)
def _validate_cik(cik): """ Check if CIK is 10 digit string. """ if not (isinstance(cik, str) and len(cik) == 10 and cik.isdigit()): raise CIKError(cik)