Coverage for fingerprint_server_sdk/models/ip_info_v4.py: 75%

40 statements  

« prev     ^ index     » next       coverage.py v7.14.3, created at 2026-07-14 10:45 +0000

1""" 

2Server API 

3Fingerprint Server API allows you to get, search, and update Events in a server environment. It can be used for data exports, decision-making, and data analysis scenarios. 

4Server API is intended for server-side usage, it's not intended to be used from the client side, whether it's a browser or a mobile device. 

5The API also supports collection of Automation Intelligence for requests to your server in edge, pre-origin, or middleware contexts. 

6 

7The version of the OpenAPI document: 4 

8Contact: support@fingerprint.com 

9Generated by OpenAPI Generator (https://openapi-generator.tech) 

10 

11Do not edit the class manually. 

12""" # noqa: E501 

13 

14from __future__ import annotations 

15 

16import json 

17import pprint 

18import re # noqa: F401 

19from typing import Any, ClassVar, Optional 

20 

21from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr 

22from typing_extensions import Self 

23 

24from fingerprint_server_sdk.models.geolocation import Geolocation 

25 

26 

27class IPInfoV4(BaseModel): 

28 """ 

29 IPInfoV4 

30 """ 

31 

32 address: StrictStr 

33 geolocation: Optional[Geolocation] = None 

34 asn: Optional[StrictStr] = None 

35 asn_name: Optional[StrictStr] = None 

36 asn_network: Optional[StrictStr] = None 

37 asn_type: Optional[StrictStr] = None 

38 datacenter_result: Optional[StrictBool] = Field( 

39 default=None, description='When true, the request originated from a datacenter.' 

40 ) 

41 datacenter_name: Optional[StrictStr] = None 

42 __properties: ClassVar[list[str]] = [ 

43 'address', 

44 'geolocation', 

45 'asn', 

46 'asn_name', 

47 'asn_network', 

48 'asn_type', 

49 'datacenter_result', 

50 'datacenter_name', 

51 ] 

52 

53 model_config = ConfigDict( 

54 populate_by_name=True, 

55 validate_assignment=True, 

56 protected_namespaces=(), 

57 ) 

58 

59 def to_str(self) -> str: 

60 """Returns the string representation of the model using alias""" 

61 return pprint.pformat(self.model_dump(by_alias=True)) 

62 

63 def to_json(self) -> str: 

64 """Returns the JSON representation of the model using alias""" 

65 # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead 

66 return json.dumps(self.to_dict()) 

67 

68 @classmethod 

69 def from_json(cls, json_str: str) -> Optional[Self]: 

70 """Create an instance of IPInfoV4 from a JSON string""" 

71 return cls.from_dict(json.loads(json_str)) 

72 

73 def to_dict(self) -> dict[str, Any]: 

74 """Return the dictionary representation of the model using alias. 

75 

76 This has the following differences from calling pydantic's 

77 `self.model_dump(by_alias=True)`: 

78 

79 * `None` is only added to the output dict for nullable fields that 

80 were set at model initialization. Other fields with value `None` 

81 are ignored. 

82 """ 

83 excluded_fields: set[str] = set([]) 

84 

85 _dict = self.model_dump( 

86 by_alias=True, 

87 exclude=excluded_fields, 

88 exclude_none=True, 

89 ) 

90 # override the default output from pydantic by calling `to_dict()` of geolocation 

91 if self.geolocation: 

92 _dict['geolocation'] = self.geolocation.to_dict() 

93 return _dict 

94 

95 @classmethod 

96 def from_dict(cls, obj: Optional[dict[str, Any]]) -> Optional[Self]: 

97 """Create an instance of IPInfoV4 from a dict""" 

98 if obj is None: 

99 return None 

100 

101 if not isinstance(obj, dict): 

102 return cls.model_validate(obj) 

103 

104 _obj = cls.model_validate( 

105 { 

106 'address': obj.get('address'), 

107 'geolocation': Geolocation.from_dict(obj['geolocation']) 

108 if obj.get('geolocation') is not None 

109 else None, 

110 'asn': obj.get('asn'), 

111 'asn_name': obj.get('asn_name'), 

112 'asn_network': obj.get('asn_network'), 

113 'asn_type': obj.get('asn_type'), 

114 'datacenter_result': obj.get('datacenter_result'), 

115 'datacenter_name': obj.get('datacenter_name'), 

116 } 

117 ) 

118 return _obj