def save(self, location, profile_name):
     features_dict = self.to_dict()
     if location is None:
         return json.dumps(features_dict)
     if isinstance(location, str):
         transport_params = {}
         if _is_url(location):
             raise ValueError("Writing to URLs is not supported")
         if _is_s3(location):
             boto3 = import_or_raise("boto3", BOTO3_ERR_MSG)
             session = boto3.Session()
             if isinstance(profile_name, str):
                 transport_params = {'session': boto3.Session(profile_name=profile_name)}
                 use_smartopen_features(location, features_dict, transport_params, read=False)
             elif profile_name is False:
                 use_s3fs_features(location, features_dict, read=False)
             elif session.get_credentials() is not None:
                 use_smartopen_features(location, features_dict, read=False)
             else:
                 use_s3fs_features(location, features_dict, read=False)
         else:
             with open(location, "w") as f:
                 json.dump(features_dict, f)
     else:
         json.dump(features_dict, location)
Example #2
0
 def load(cls, features, profile_name):
     if isinstance(features, str):
         try:
             features_dict = json.loads(features)
         except ValueError:
             if _is_url(features):
                 features_dict = use_smartopen_features(features)
             elif _is_s3(features):
                 boto3 = import_or_raise("boto3", BOTO3_ERR_MSG)
                 session = boto3.Session()
                 if isinstance(profile_name, str):
                     transport_params = {
                         'session': boto3.Session(profile_name=profile_name)
                     }
                     features_dict = use_smartopen_features(
                         features, transport_params)
                 elif profile_name is False:
                     features_dict = use_s3fs_features(features)
                 elif session.get_credentials() is not None:
                     features_dict = use_smartopen_features(features)
                 else:
                     features_dict = use_s3fs_features(features)
             else:
                 with open(features, 'r') as f:
                     features_dict = json.load(f)
         return cls(features_dict)
     return cls(json.load(features))
 def save(self, location, profile_name):
     features_dict = self.to_dict()
     if location is None:
         return json.dumps(features_dict)
     if isinstance(location, str):
         if _is_url(location):
             raise ValueError("Writing to URLs is not supported")
         if _is_s3(location):
             transport_params = get_transport_params(profile_name)
             use_smartopen_features(
                 location, features_dict, transport_params, read=False
             )
         else:
             with open(location, "w") as f:
                 json.dump(features_dict, f)
     else:
         json.dump(features_dict, location)
Example #4
0
 def load(cls, features, profile_name):
     if isinstance(features, str):
         try:
             features_dict = json.loads(features)
         except ValueError:
             if _is_url(features) or _is_s3(features):
                 transport_params = None
                 if _is_s3(features):
                     transport_params = get_transport_params(profile_name)
                 features_dict = use_smartopen_features(
                     features, transport_params=transport_params)
             else:
                 with open(features, "r") as f:
                     features_dict = json.load(f)
         return cls(features_dict)
     return cls(json.load(features))