{"id":17693555,"url":"https://github.com/amboxer21/custompythondecorators","last_synced_at":"2025-09-13T07:29:52.175Z","repository":{"id":147837220,"uuid":"149297013","full_name":"amboxer21/CustomPythonDecorators","owner":"amboxer21","description":"Custom Python decorators I wrote to restrict method arguments to a specific type. I also added an encrypt/decrypt decorator as well.","archived":false,"fork":false,"pushed_at":"2025-03-01T23:21:46.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-02T00:19:09.338Z","etag":null,"topics":["advanced","aes","aes-encryption","curried-functions","currying","custom","custom-python-decorators","decorator","decorators","encrypt","encrypted","encryption","encryption-decryption","functional","functional-programming","functional-python","higher-order-functions","metaprogramming","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amboxer21.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-18T13:56:02.000Z","updated_at":"2025-03-01T23:21:49.000Z","dependencies_parsed_at":"2023-05-27T16:00:13.420Z","dependency_job_id":null,"html_url":"https://github.com/amboxer21/CustomPythonDecorators","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amboxer21%2FCustomPythonDecorators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amboxer21%2FCustomPythonDecorators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amboxer21%2FCustomPythonDecorators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amboxer21%2FCustomPythonDecorators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amboxer21","download_url":"https://codeload.github.com/amboxer21/CustomPythonDecorators/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246390864,"owners_count":20769478,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["advanced","aes","aes-encryption","curried-functions","currying","custom","custom-python-decorators","decorator","decorators","encrypt","encrypted","encryption","encryption-decryption","functional","functional-programming","functional-python","higher-order-functions","metaprogramming","python"],"created_at":"2024-10-24T13:45:22.653Z","updated_at":"2025-03-30T23:18:27.789Z","avatar_url":"https://github.com/amboxer21.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CustomPythonDecorators\nThese are custom Python decorators I wrote to restrict method arguments to a specific type. If you pass an argument other than what the decorator allows, it will raise a TypeError exception. These decorators also ensure that you are calling the decorator on an instance method of a class. I also wrote other decorators to encrypt/decrypt strings passed to instance methods.\n\n**Examples:**\n\n\u003e**accepts decorators**\n\n```python\nclass TestAcceptsClass(object):\n\n    # This instance method will raise an exception\n    # if an argument other than boolean is passed.\n    @accepts.boolean\n    def _boolean(self,_boolean_):\n        print('boolean =\u003e '+str(_boolean_))\n\n    # This instance method will raise an exception\n    # if an argument other than integer is passed.\n    @accepts.integer\n    def _integer(self,_integer_):\n        print('integer =\u003e '+str(_integer_))\n\n    # This instance method will raise an exception\n    # if an argument other than string is passed.\n    @accepts.string\n    def _string(self,_string_):\n        print('string =\u003e '+str(_string_))\n\n    # This instance method will raise an exception\n    # if an argument other than dict is passed.\n    @accepts.dictionary\n    def _dictionary(self,_dictionary_):\n        print('dictionary =\u003e '+str(_dictionary_))\n\n    # This instance method will raise an exception\n    # if an argument other than list is passed.\n    @accepts.list\n    def _list(self,_list_):\n        print('list =\u003e '+str(_list_))\n\n    # This instance method will raise an exception\n    # if an argument other than tuple is passed.\n    @accepts.tuple\n    def _tuple(self,_tuple_):\n        print('tuple =\u003e '+str(_tuple_))\n\nif __name__ == '__main__':\n\n    # Our test class\n    test = TestAcceptsClass()\n\n    # The following examples are ways that the custom\n    # decorators can be used. \n    \n    test._integer(1)\n    test._integer(1,2)\n\n    test._boolean(True)\n    test._boolean(True,False)\n\n    test._list(['1','2','3'])\n    test._list(['1','2','3'],['4','5','6'])\n\n    test._tuple(('1','2','3'),)\n    test._tuple(('1','2','3'),('4','5','6'))\n\n    test._string('test string')\n    test._string('test string1','test string2')\n\n    test._dictionary(\n        {'one': '1','two': '2','three': '3'},\n        {'four': '4','five': '5','six': '6'}\n    )\n    test._dictionary({'one': '1','two': '2','three': '3'})\n    \n    # The following test cases will fail and will raise a type exception!\n    test._integer('1')\n    test._integer('1','2')\n    test._boolean(1)\n    test._boolean('True','False',1)\n    test._list(('1','2','3'))\n    test._list(('1','2','3'),('4','5','6'))\n    test._tuple(['1','2','3'],)\n    test._tuple(['1','2','3'],['4','5','6'])\n    test._string(True)\n    test._string(True,False)\n\n# The following examples will fail and will raise a SyntaxError\n# and complain about the method not being an instance of a class.\n@accepts.integer\ndef _integer(_integer_):\n    print('integer: '+str(_integer_))\n    \n_integer(1)\n    \n```\n\n\u003e**encryption decorators**\n\n```javascript\nclass TestStringClass(object):\n\n    @string.encrypt\n    def encrypt(self,string):\n        return string \n\n    @string.decrypt\n    def decrypt(self,string):\n        return string\n\nif __name__ == '__main__':\n\n    # This will work\n    test = TestStringClass()\n    encrypted_text = test.encrypt('This is an encrypted string')\n    print test.decrypt(encrypted_text)\n\n# This will not work\n@string.encrypt\ndef test_string_method(string):\n    string\n    \ntest_string_method('This is a test')    \n```\n\n\u003e ^^ Remove newlines in between method declarations if using the python shell/interpretter and are having problems!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famboxer21%2Fcustompythondecorators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famboxer21%2Fcustompythondecorators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famboxer21%2Fcustompythondecorators/lists"}