rj-core 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
rj_core-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: rj-core
3
+ Version: 0.1.1
4
+ Author: rahul
5
+ Requires-Dist: bcrypt
6
+ Requires-Dist: rj-home
@@ -0,0 +1,7 @@
1
+ [project]
2
+ name = "rj-core"
3
+ version = "0.1.1"
4
+ authors = [
5
+ { name = "rahul" }
6
+ ]
7
+ dependencies = ['bcrypt', "rj-home"]
File without changes
@@ -0,0 +1,121 @@
1
+ import rj.settings
2
+
3
+ from rj.settings import *
4
+ from rj.core.helpers import jsonify
5
+
6
+
7
+ def formatted_json_string_literal(JSON):
8
+ keys = []
9
+ values = []
10
+ largest_key = ""
11
+ len_largest_key = -1
12
+ if not isinstance(JSON, dict):
13
+ raise TypeError("The argument must be a dict.")
14
+ else:
15
+ for key, value in JSON.items():
16
+ keys.append(key)
17
+ len_key = len(key)
18
+ if len_key > len_largest_key:
19
+ largest_key = key
20
+ len_largest_key = len_key
21
+ values.append(value)
22
+
23
+ try:
24
+ print("{\n")
25
+ for key, value in JSON.items():
26
+ len_key = len(key)
27
+ remaining_len = len_largest_key - len_key
28
+ spacing = ""
29
+ for i in range(remaining_len):
30
+ spacing += " "
31
+ string = key + spacing + " "
32
+ print("\t%s: %s" % (string, value))
33
+
34
+ print("}")
35
+
36
+ except Exception as e:
37
+ print(e)
38
+
39
+
40
+ def chaduvukofirst():
41
+ print("Breakup ainda...?? Poyi Chitti tho kalisi chaduvuko ra poookkaaa!!!!")
42
+
43
+
44
+ def cli_test():
45
+
46
+ import sys
47
+
48
+ if len(sys.argv) < 2:
49
+ print("No command given")
50
+ exit(1)
51
+
52
+ command = sys.argv[1]
53
+
54
+ match command:
55
+ case "settings":
56
+ print("__reding__settings__")
57
+
58
+ case "read_settings":
59
+ from rj.settings import SETTINGS_JSON_PATH
60
+ import json
61
+
62
+ with open(SETTINGS_JSON_PATH, "r") as settings:
63
+ try:
64
+ settings_dictionary = json.load(settings)
65
+ formatted_json_string_literal(settings_dictionary)
66
+
67
+ except json.JSONDecodeError as e:
68
+ import sys
69
+
70
+ print(
71
+ "\033[31mError occurred during handling settings. Improperly configured settings.\033[0m"
72
+ )
73
+ print()
74
+ write_log(e, True)
75
+ write_log(settings.read())
76
+
77
+ case "set_username_validator":
78
+ set_username_validator()
79
+ case "help":
80
+ pass
81
+ case "-h":
82
+ pass
83
+ case "--help":
84
+ help = jsonify(
85
+ settings="reads settings",
86
+ read_settings="reads settings and print out to the terminal",
87
+ set_username_validator="sets username validator regex.",
88
+ read_logs="Prints out the logs written in logs",
89
+ clear_logs="Clears all the log file",
90
+ initialise_settings="Initialises settings, and fixes the errrosr and overwrites settings json, if errors were found.",
91
+ )
92
+
93
+ print("avaliable commands:")
94
+ formatted_json_string_literal(help)
95
+
96
+ case "read_logs":
97
+
98
+ read_logs()
99
+
100
+ case "clear_logs":
101
+
102
+ settings.clear_logs()
103
+
104
+ case "mails":
105
+ from rj.mails import show_help, help
106
+
107
+ if sys.argv[2] == "--help":
108
+
109
+ show_help()
110
+
111
+ else:
112
+ print("Use --help for longer description")
113
+ help()
114
+ case "show_args":
115
+ print(("settings", "read_logs", "read_settings", "clear_logs", "--help"))
116
+ case "initialise_settings":
117
+
118
+ initialise_settings()
119
+
120
+ case _:
121
+ print("Iinvalid command.")
@@ -0,0 +1,85 @@
1
+ class BaseException(Exception):
2
+ def __init__(self, message="Value is required."):
3
+ self.message = f" {message}."
4
+ super().__init__(message)
5
+
6
+
7
+ class PhoneNumberException(Exception):
8
+ message = "Invalid Phone number formats."
9
+
10
+ def __init__(self, message="Invalid Phone number formats."):
11
+ super().__init__(self.message)
12
+
13
+
14
+ class InvalidCountryCodeException(Exception):
15
+ def __init__(self, message="Invalid country code format."):
16
+ self.message = f"InvalidPhoneNumberException : {message}."
17
+ super().__init__(self.message)
18
+
19
+
20
+ class InvalidPhoneNumberException(Exception):
21
+ def __init__(self, message="Phone number should contain atleast 10 digits."):
22
+ self.message = f"{message}."
23
+ super().__init__(self.message)
24
+
25
+
26
+ class InvalidEmailException(Exception):
27
+ def __init__(self, message="Email format is invalid."):
28
+ self.message = f"{message}."
29
+ super().__init__(self.message)
30
+
31
+
32
+ class UsernameException(BaseException):
33
+ def __init__(self, message="Invalid Username format."):
34
+ self.message = f"{message}"
35
+ super().__init__(self.message)
36
+
37
+
38
+ class ValidatePhoneNumber(Exception):
39
+
40
+ @staticmethod
41
+ def validate_phone(phone):
42
+ phone = str(phone)
43
+ country_code = phone[:-10]
44
+ if not phone.startswith("+") and len(country_code) < 2:
45
+ error_message = f"{phone} : Invalid countrycode country code is empty."
46
+ raise PhoneNumberException(error_message)
47
+
48
+ if len(phone) > 15 or len(phone) < 10:
49
+ PhoneNumberIsValid = True
50
+ for i in phone:
51
+ if int(i) in range(0, 9):
52
+ pass
53
+ else:
54
+ PhoneNumberIsValid = False
55
+ raise PhoneNumberException(
56
+ f"{phone} : Phone Number should contain only Digits (0-9)."
57
+ )
58
+ raise PhoneNumberException(
59
+ f"{phone} : Phone number should be exactly 10 digits."
60
+ )
61
+ else:
62
+ phone_number = phone[-10:]
63
+ return {"phone_number": phone_number, "country_code": country_code}
64
+
65
+ def __call__(self, phone):
66
+ return self.validate_phone(phone)
67
+
68
+
69
+ class MissingFieldError(ValueError):
70
+ def __init__(self, field="", *args):
71
+ self.message = f"The filed -- {field if not field == "" or field is not None else "__NOT_MENTIONED__"} -- is missing."
72
+ super().__init__(self.message)
73
+
74
+
75
+ class IncompleteWritingError(BaseException):
76
+ def __init__(self, *args):
77
+ super().__init__("Error... The code is marked as incompete")
78
+
79
+
80
+ class ImproperlyConfigured(Exception):
81
+ def __init__(self, *args):
82
+ super().__init__(*args)
83
+
84
+
85
+ class RJMailsMIMETypeException(Exception): ...
@@ -0,0 +1,295 @@
1
+ # def jsonify(update={}, *args: dict, **kwargs) -> dict:
2
+ # # update = {}
3
+ # for i in args:
4
+ # if isinstance(i, dict):
5
+ # update.setdefault("kwargs", {})
6
+ # update["kwargs"].update(i)
7
+
8
+ # else:
9
+ # update.setdefault("args", [])
10
+ # update["args"].append(i)
11
+
12
+ # for i in kwargs:
13
+ # update.setdefault(i, kwargs.get(i))
14
+
15
+ # return update
16
+
17
+
18
+ # def jsonify(*args, ___ignore_empty__=False, **kwargs) -> dict:
19
+ # result = {}
20
+
21
+ # # Process all positional arguments (dicts or single values)
22
+ # for item in args:
23
+ # if isinstance(item, dict):
24
+ # if ___ignore_empty__:
25
+ # continue
26
+ # # Merge dictionary and filter out empty strings/None values if needed
27
+ # for key, val in item.items():
28
+ # if val: # Filters out empty values like "", None, []
29
+ # result[key] = val
30
+ # else:
31
+ # # Handle non-dict positional items
32
+ # result.setdefault("args", []).append(item)
33
+
34
+ # # Process keyword arguments (kwargs override positional args)
35
+ # for key, val in kwargs.items():
36
+ # if val:
37
+ # result[key] = val
38
+
39
+ # return result
40
+
41
+
42
+ import json
43
+
44
+
45
+ def jsonify(*args, ___ignore_empty__=False, **kwargs) -> dict:
46
+ result = {}
47
+
48
+ def is_valid(val):
49
+ if ___ignore_empty__:
50
+ return True
51
+ # Filter out None, empty strings, and empty collections (lists/dicts/tuples)
52
+ if val is None or val == "":
53
+ return False
54
+ if isinstance(val, (list, dict, set, tuple)) and len(val) == 0:
55
+ return False
56
+ return True
57
+
58
+ # 1. Process positional arguments
59
+ for item in args:
60
+ if isinstance(item, dict):
61
+ for key, val in item.items():
62
+ if is_valid(val):
63
+ result[key] = val
64
+ else:
65
+ if is_valid(item):
66
+ result.setdefault("args", []).append(item)
67
+
68
+ # 2. Process keyword arguments
69
+ for key, val in kwargs.items():
70
+ if is_valid(val):
71
+ result[key] = val
72
+
73
+ return result
74
+
75
+
76
+ class STATUS:
77
+ # --- 2xx Success ---
78
+ OK = 200
79
+ CREATED = 201
80
+ ACCEPTED = 202
81
+ NO_CONTENT = 204
82
+
83
+ # --- 3xx Redirection ---
84
+ MOVED_PERMANENTLY = 301
85
+ FOUND = 302
86
+ NOT_MODIFIED = 304
87
+
88
+ # --- 4xx Client Errors ---
89
+ BAD_REQUEST = 400
90
+ UNAUTHENTICATED = 401
91
+ UNAUTHORIZED = 403 # Forbidden
92
+ NOT_FOUND = 404
93
+ METHOD_NOT_ALLOWED = 405
94
+ CONFLICT = 409
95
+ UNPROCESSABLE_ENTITY = 422
96
+ TOO_MANY_REQUESTS = 429
97
+
98
+ # --- 5xx Server Errors ---
99
+ INTERNAL_SERVER_ERROR = 500
100
+ NOT_IMPLEMENTED = 501
101
+ BAD_GATEWAY = 502
102
+ SERVICE_UNAVAILABLE = 503
103
+ GATEWAY_TIMEOUT = 504
104
+
105
+ # Mapping codes to human-readable status phrases
106
+ _MESSAGES = {
107
+ 200: "OK",
108
+ 201: "Created",
109
+ 202: "Accepted",
110
+ 204: "No Content",
111
+ 301: "Moved Permanently",
112
+ 302: "Found",
113
+ 304: "Not Modified",
114
+ 400: "Bad Request",
115
+ 401: "Unauthenticated",
116
+ 403: "Unauthorized",
117
+ 404: "Not Found",
118
+ 405: "Method Not Allowed",
119
+ 409: "Conflict",
120
+ 422: "Unprocessable Entity",
121
+ 429: "Too Many Requests",
122
+ 500: "Internal Server Error",
123
+ 501: "Not Implemented",
124
+ 502: "Bad Gateway",
125
+ 503: "Service Unavailable",
126
+ 504: "Gateway Timeout",
127
+ }
128
+
129
+ def __init__(self, code):
130
+ if code not in self._MESSAGES:
131
+ raise ValueError(f"Invalid or unsupported status code: {code}")
132
+
133
+ self.status = code
134
+ self.message = self._MESSAGES[code]
135
+
136
+ def __repr__(self):
137
+ return f"<STATUS code={self.status} message='{self.message}'>"
138
+
139
+
140
+ class returnjson:
141
+ @staticmethod
142
+ def _N_GET_STATUS_CODES():
143
+ return STATUS
144
+
145
+ def __init__(
146
+ self,
147
+ dictionary={},
148
+ message="",
149
+ error="",
150
+ status="failed",
151
+ info="",
152
+ status_code=200,
153
+ **args,
154
+ ):
155
+ args.setdefault("data", None)
156
+ dictx = jsonify(
157
+ dictionary,
158
+ args,
159
+ message=message,
160
+ status_code=status_code,
161
+ error=error,
162
+ status=status,
163
+ info=info,
164
+ ___ignore_empty__=True,
165
+ )
166
+
167
+ self.__dict__.update(dictx)
168
+
169
+ @property
170
+ def json(self):
171
+ return self.__dict__
172
+
173
+ def __str__(self):
174
+ import json
175
+
176
+ return json.dumps(self.__dict__, indent=2)
177
+
178
+ def __repr__(self):
179
+ return json.dumps(self.__dict__, indent=2)
180
+
181
+ @staticmethod
182
+ def _N_SERVER_ERROR():
183
+ return returnjson(
184
+ message="Server Caught Exception",
185
+ status_code=500,
186
+ error="InternalServerError",
187
+ )
188
+
189
+ @staticmethod
190
+ def _N_STATUS_OK():
191
+ return returnjson(
192
+ message=STATUS._MESSAGES.get(STATUS.OK), status_code=STATUS.OK, status="ok"
193
+ )
194
+
195
+ @staticmethod
196
+ def _N_JSON_DECODE_ERROR():
197
+ return returnjson(
198
+ message="Please provide a valid json format.",
199
+ status_code=STATUS.BAD_REQUEST,
200
+ error="JSONDecodeError",
201
+ )
202
+
203
+
204
+ # class comjson:
205
+ # def __init__(
206
+ # self,
207
+ # message="",
208
+ # error="",
209
+ # status="failed",
210
+ # info="",
211
+ # object=None,
212
+ # data={},
213
+ # **args
214
+ # ):
215
+ # self.__dict__.update(
216
+ # jsonify(
217
+ # error=error,
218
+ # message=message,
219
+ # info=info,
220
+ # data=data,
221
+ # object=object,
222
+ # **args,
223
+ # status=status,
224
+ # )
225
+ # )
226
+
227
+ import json
228
+
229
+
230
+ class comjson:
231
+ def __init__(
232
+ self,
233
+ dictionary=None,
234
+ message="",
235
+ error="",
236
+ status="failed",
237
+ info="",
238
+ object=None,
239
+ data=None,
240
+ **args,
241
+ ):
242
+ if dictionary is None:
243
+ dictionary = {}
244
+
245
+ # Merge extra keyword arguments into dictionary if provided
246
+ combined_dict = {**dictionary, **args}
247
+
248
+ # Filter empty strings, Nones, and empty collections
249
+ dictx = jsonify(
250
+ combined_dict,
251
+ message=message,
252
+ error=error,
253
+ status=status,
254
+ info=info,
255
+ object=object,
256
+ data=data,
257
+ ___ignore_empty__=True,
258
+ )
259
+
260
+ self.__dict__.update(dictx)
261
+
262
+ @property
263
+ def json(self):
264
+ return self.__dict__
265
+
266
+ def __str__(self):
267
+ return json.dumps(self.__dict__, indent=2)
268
+
269
+ def __repr__(self):
270
+ return json.dumps(self.__dict__, indent=2)
271
+
272
+
273
+ if __name__ == "__main__":
274
+
275
+ def printf(*args, **kwargs):
276
+ import json
277
+
278
+ for i in args:
279
+ if isinstance(i, tuple):
280
+ kwargs.setdefault("args", {})
281
+ kwargs["args"].update(args)
282
+ finaldict = (
283
+ kwargs.update(args)
284
+ if isinstance(args, dict)
285
+ else kwargs.setdefault("args", args)
286
+ )
287
+ print(type(args))
288
+ print(json.dumps(kwargs, indent=2))
289
+
290
+ def printf(*args, **kwargs):
291
+ print(*args, **kwargs)
292
+
293
+ print(jsonify(returnjson().json, message="test", **returnjson().json))
294
+ print(returnjson(obj="Hello world string").json)
295
+ print(comjson(neekenduuku="Chaduvuko first").json)
@@ -0,0 +1,21 @@
1
+ class UrlGenerator:
2
+ @staticmethod
3
+ def __init__ (**kwargs):
4
+ host = kwargs.get("hostname")
5
+ port = kwargs.get("port")
6
+ path = kwargs.get("path","")
7
+ return f"http://{host}:{port}/{path}"
8
+
9
+
10
+ class jsonify:
11
+ @staticmethod
12
+ def __init__(**kwargs):
13
+ return kwargs
14
+
15
+ def returnjson (dictionary = {} , message="", error= "", status="failed", info="", **args):
16
+ dictionary.setdefault("message", message)
17
+ dictionary.setdefault("status",status)
18
+ dictionary.setdefault("info", info)
19
+ dictionary.update(args)
20
+
21
+ return dictionary
@@ -0,0 +1,14 @@
1
+ import json
2
+ from pathlib import Path
3
+
4
+ def save_to_config(data):
5
+ # Create a hidden folder in the user's home directory
6
+ config_dir = Path.home() / ".rj_data"
7
+ config_dir.mkdir(exist_ok=True)
8
+
9
+ file_path = config_dir / "settings.json"
10
+
11
+ with open(file_path, "w") as f:
12
+ json.dump(data, f, indent=4)
13
+
14
+ return str(file_path)
@@ -0,0 +1,270 @@
1
+ import re
2
+
3
+ # from django.core.validators import validate_email as django_validate_email
4
+ # from django.core.validators import RegexValidator
5
+ # from django.core.exceptions import ValidationError
6
+ import os
7
+
8
+ from .exeptions import InvalidCountryCodeException
9
+ from .exeptions import InvalidPhoneNumberException, InvalidEmailException
10
+ from rj import settings
11
+
12
+ ###############################################
13
+ # own validators. protect this from ai agents..
14
+ # class UsernameValidator:
15
+ # def __init__ (self, username=None, phone_no=None,email=None,**kwargs):
16
+ # self.username = username or kwargs.get("username")
17
+ # self.email = email or kwargs.get("email")
18
+ # self.phone_no = phone_no or kwargs.get("phone_no")
19
+ # return self.validate(username)
20
+ # def __str__(self):
21
+ # return self.username
22
+ # def __repr__(self):
23
+ # return self.email
24
+ # @staticmethod
25
+ # def validate(username):
26
+ # if username is None or len(username) <6:
27
+ # raise BaseException("Username should be greater than 6 characters.")
28
+ # else :
29
+ # temp = UsernameValidator(username)
30
+ # if temp:
31
+ # return temp.username
32
+ # else :
33
+ # class UsernameInvalidException(Exception):
34
+ # message = "Please match the request username format."
35
+ # def __init__(self,message=None, *args):
36
+ # self.message = message if message is not None else self.message
37
+ # super().__init__(self.message,*args)
38
+ # raise UsernameInvalidException
39
+ # @staticmethod
40
+ # def validate_username(username):
41
+ # return Validators.validate(username)
42
+ # def valid_username(self):
43
+ # try:
44
+ # valid_username = self.validate_
45
+ username_validation_pattern = ""
46
+ from rj.settings import DEFAULT_SETTINGS_DICT
47
+
48
+ username_validation_pattern = DEFAULT_SETTINGS_DICT.get("regex").get("username_regex")
49
+
50
+
51
+ class UsernameValidator:
52
+ def __init__(self, username=None):
53
+ self.username = username
54
+
55
+ def validate(username):
56
+ import re
57
+
58
+ # username = self.username
59
+ # username_validation_pattern = r'^(?=.*[a-z])[a-z0-9_.]+$'
60
+ IsMatched = re.compile(username_validation_pattern)
61
+ if IsMatched.match(username):
62
+ return username
63
+ else:
64
+ raise Exception("Username is not valid.")
65
+
66
+ @property
67
+ def is_valid(self):
68
+ import re
69
+
70
+ username = self.username
71
+ username_validation_pattern = r"^(?=.*[a-z])[a-z0-9_.]+$"
72
+ IsMatched = re.compile(username_validation_pattern)
73
+ if IsMatched.match(username):
74
+ return True
75
+ else:
76
+ return False
77
+
78
+
79
+ class Validators:
80
+ def __init__(self, username=None, phone_no=None, email=None, **kwargs):
81
+ self.username = username or kwargs.get("username")
82
+ self.email = email or kwargs.get("email")
83
+ self.phone_no = phone_no or kwargs.get("phone_no")
84
+ return None
85
+
86
+ @staticmethod
87
+ def validate_username(username):
88
+ import re
89
+
90
+ pattern = r"^[a-z0-9A-Z]+$"
91
+ username_regex = re.compile(pattern)
92
+ return username if username_regex.fullmatch(username) else None
93
+
94
+ @staticmethod
95
+ def validate_username_list(*args):
96
+ import re
97
+
98
+ pattern = r"^[a-z0-9A-Z]+$"
99
+ username_regex = re.compile(pattern)
100
+ if len(*args) < 1:
101
+ raise ValueError("Atleast one argument required. %s" % (args))
102
+ elif len(args) == 1 and isinstance(args, tuple):
103
+ if username_regex.fullmatch(args[0]):
104
+ return str(args[0])
105
+ else:
106
+ return None
107
+ elif len(args) > 1 and (isinstance(args, tuple) or isinstance(args, list)):
108
+
109
+ returnargs = []
110
+ for i in args:
111
+ if username_regex.fullmatch(i):
112
+ returnargs.append(i)
113
+ else:
114
+ print("Invalid username.%s" % (i))
115
+
116
+ return returnargs
117
+
118
+ @property
119
+ def valid_username(self):
120
+ temp = UsernameValidator(self.username)
121
+ return temp.is_valid
122
+
123
+ @staticmethod
124
+ def validate_phone(phone):
125
+ if isinstance(phone, dict):
126
+ if phone.get("country_code", None) and phone.get("phone_no"):
127
+ phone_no = phone.get("phone_no")
128
+ country_code = phone.get("country_code")
129
+ if not country_code.startswith("+"):
130
+ country_code = f"+{str(country_code)}"
131
+
132
+ else:
133
+
134
+ class JsonDecodeError(Exception):
135
+ def __init__(
136
+ self,
137
+ message="Json pattern not matched. { phone_no : value, country_code : value ",
138
+ ):
139
+ self.message = message
140
+ super().__init__(message)
141
+
142
+ raise JsonDecodeError()
143
+ else:
144
+
145
+ phone = str(phone)
146
+ phone = phone.replace(" ", "")
147
+ if not phone == "" and not phone is None:
148
+ phone_no = phone[-10:]
149
+ country_code = phone[:-10]
150
+ if country_code == "" or country_code is None:
151
+ print("Warning : Default country code : IN +91")
152
+ country_code = "+91"
153
+ for i in str(phone_no):
154
+ # print("Forloop executed.")
155
+
156
+ try:
157
+ int(i)
158
+ except ValueError:
159
+ raise InvalidPhoneNumberException(
160
+ "Phone Number should exactly contain digits. (value: %s , phone : %s)"
161
+ % (i, phone)
162
+ )
163
+ except Exception as e:
164
+ raise Exception
165
+
166
+ if country_code.startswith("+") and len(str(country_code)) < 2:
167
+ raise InvalidCountryCodeException
168
+ elif not country_code.startswith("+") and len(phone) > 10:
169
+ print(phone, " : ", len(phone))
170
+ raise InvalidPhoneNumberException(
171
+ "Phone number shouldnot Exceed 10 digits with countrycode mentioned as +ccph"
172
+ )
173
+
174
+ if not phone_no.__len__() == 10 or phone_no is None and phone_no == "":
175
+ raise InvalidPhoneNumberException(
176
+ "Phone No should consists of exactly 10 digits. (input : %s )"
177
+ % (phone_no)
178
+ )
179
+ elif phone_no.__len__() == 10:
180
+ return f"{country_code}{phone_no}".strip()
181
+
182
+ @property
183
+ def valid_phone_no(self):
184
+ temp = None
185
+ try:
186
+ temp = Validators.validate_phone(self.phone_no)
187
+ return True if temp is not None else False
188
+ except:
189
+ return False
190
+
191
+ @staticmethod
192
+ def validate_email(email):
193
+ email = str(email)
194
+
195
+ if not email == "" and not email is None and email.__len__() >= 5:
196
+ try:
197
+ userid, domain = email.split("@")
198
+ host, x = domain.split(".")
199
+ if host and x and userid:
200
+ return f"{userid}@{domain}"
201
+ else:
202
+ raise Exception("Invalud emallil")
203
+ except:
204
+ raise InvalidEmailException("Enter a valid emailformat.")
205
+ else:
206
+ raise InvalidEmailException(
207
+ "Empty Email Detected!!"
208
+ if email == "" or email is None
209
+ else "Email should be greater than 5 characters...!"
210
+ )
211
+
212
+ @property
213
+ def valid_email(self):
214
+ temp = None
215
+ try:
216
+ temp = self.validate_email(self.email)
217
+ return True if temp is not None else False
218
+ except:
219
+ return False
220
+
221
+ @staticmethod
222
+ def validate_username(username):
223
+ return UsernameValidator.validate(username)
224
+
225
+ @property
226
+ def all_valid(self):
227
+ return (
228
+ True
229
+ if self.valid_phone_no and self.valid_username and self.valid_email
230
+ else False
231
+ )
232
+
233
+
234
+ class URLValidator:
235
+ class InvalidException(Exception):
236
+ def __init__(self, *args):
237
+ self.message = (
238
+ args[1] or "Invalid url. URL must start with http:// or https://"
239
+ )
240
+ super().__init__(*args)
241
+
242
+ @staticmethod
243
+ def validate(*args):
244
+ if len(args) < 1:
245
+ raise ValueError("Url argument is required.")
246
+
247
+ else:
248
+ url = URLValidator(args)
249
+ return url.valid_urls
250
+
251
+ def __init__(self, *args):
252
+ self.urls = args
253
+
254
+ @property
255
+ def valid_urls(self):
256
+ valid_url = []
257
+ urls = self.urls
258
+ for i in urls:
259
+ if str(i).startswith("https://") or str(i).startswith("http://"):
260
+
261
+ valid_url.append(str(i))
262
+
263
+ self.valid_url = valid_url
264
+ # return valid_url
265
+
266
+ return valid_url if not len(self.valid_url) > 0 else None
267
+
268
+ def validate(self, url):
269
+ if isinstance(self, str):
270
+ return
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: rj-core
3
+ Version: 0.1.1
4
+ Author: rahul
5
+ Requires-Dist: bcrypt
6
+ Requires-Dist: rj-home
@@ -0,0 +1,13 @@
1
+ pyproject.toml
2
+ rj_core/__init__.py
3
+ rj_core/cli.py
4
+ rj_core/exeptions.py
5
+ rj_core/helpers.py
6
+ rj_core/modules.py
7
+ rj_core/save_data.py
8
+ rj_core/validators.py
9
+ rj_core.egg-info/PKG-INFO
10
+ rj_core.egg-info/SOURCES.txt
11
+ rj_core.egg-info/dependency_links.txt
12
+ rj_core.egg-info/requires.txt
13
+ rj_core.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ bcrypt
2
+ rj-home
@@ -0,0 +1 @@
1
+ rj_core
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+