-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from ersul4ik/fix-tests-circle
Fix tests circle
- Loading branch information
Showing
23 changed files
with
507 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,5 @@ requests.egg-info/ | |
*.egg | ||
env/ | ||
dist | ||
swcregistrypython.egg-info/ | ||
*.egg-info/ | ||
.eggs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
include swcregistrypython/swc-definition.json | ||
include swc_registry/swc-definition.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# SWC-registry-python | ||
|
||
[![CircleCI](https://circleci.com/gh/SmartContractSecurity/SWC-registry-python.svg?style=svg)](https://circleci.com/gh/SmartContractSecurity/SWC-registry-python) | ||
|
||
## Description | ||
Python library for accessing SWC-registry content. | ||
|
||
## Installation | ||
|
||
```console | ||
$ pip install -U swc-registry | ||
``` | ||
|
||
## Usage | ||
```python | ||
from swc_registry import SWC | ||
|
||
swc = SWC('SWC-100') | ||
swc.title | ||
``` | ||
|
||
## Contribution |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
requests==2.20.1 | ||
pytest==4.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pytest==4.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[aliases] | ||
test=pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,53 @@ | ||
import setuptools | ||
setuptools.setup( | ||
name="swcregistrypython", | ||
version="1.0", | ||
|
||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
""" | ||
:copyright: (c) 2017 by Lev Lazinskiy | ||
:license: MIT, see LICENSE for more details. | ||
""" | ||
import os | ||
import sys | ||
|
||
from setuptools import setup | ||
from setuptools.command.install import install | ||
|
||
# circleci.py version | ||
VERSION = "1.1.1" | ||
|
||
class VerifyVersionCommand(install): | ||
"""Custom command to verify that the git tag matches our version""" | ||
description = 'verify that the git tag matches our version' | ||
|
||
def run(self): | ||
tag = os.getenv('CIRCLE_TAG') | ||
|
||
if tag != VERSION: | ||
info = "Git tag: {0} does not match the version of this app: {1}".format( | ||
tag, VERSION | ||
) | ||
sys.exit(info) | ||
|
||
setup( | ||
name="swc-registry", | ||
version=VERSION, | ||
url="https://github.com/SmartContractSecurity/SWC-registry-python", | ||
author="SmartContractSecurity", | ||
author_email="[email protected]", | ||
description="An package to get the required swc definition fields.", | ||
long_description=open('README.rst').read(), | ||
packages=['swcregistrypython'], | ||
include_package_data = True, | ||
install_requires=[ | ||
'requests==2.20.1', | ||
], | ||
description="Python library for accessing SWC-registry content.", | ||
long_description=open("README.md").read(), | ||
packages=["swc_registry"], | ||
include_package_data=True, | ||
install_requires=["requests==2.20.1"], | ||
classifiers=[ | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.3', | ||
'Programming Language :: Python :: 3.4' | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3.3", | ||
"Programming Language :: Python :: 3.4", | ||
], | ||
setup_requires=["pytest-runner"], | ||
tests_require=["pytest"], | ||
cmdclass={ | ||
'verify': VerifyVersionCommand, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from swc_registry.get_entry_info import SWC | ||
|
||
__version__ = "0.0.3" | ||
__author__ = "SmartContractSecurity" | ||
__all__ = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import os | ||
import requests | ||
import json | ||
|
||
|
||
class SWCException(Exception): | ||
pass | ||
|
||
|
||
class Singleton(type): | ||
_instances = {} | ||
|
||
def __call__(cls, *args, **kwargs): | ||
if cls not in cls._instances: | ||
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) | ||
return cls._instances[cls] | ||
|
||
|
||
class SWCRegistry(object, metaclass=Singleton): | ||
""" | ||
Registry class takes care of loading and downloading the swc registry | ||
""" | ||
|
||
def __init__(self): | ||
self._content = None | ||
|
||
@staticmethod | ||
def _get_latest_version(): | ||
try: | ||
url = ( | ||
"https://raw.githubusercontent.com/SmartContractSecurity/SWC-registry/master/export/swc-definition" | ||
".json" | ||
) | ||
response = requests.get(url).json() | ||
return response | ||
except requests.exceptions.RequestException: | ||
return None | ||
|
||
def _load_from_file(self): | ||
path_file_content = os.path.join( | ||
os.path.dirname(__file__), "swc-definition.json" | ||
) | ||
with open(path_file_content, "r") as f: | ||
self._content = json.load(f) | ||
|
||
def update(self): | ||
self._content = SWCRegistry._get_latest_version() | ||
|
||
@property | ||
def content(self): | ||
if self._content is None: | ||
self._load_from_file() | ||
return self._content | ||
|
||
def __repr__(self): | ||
return "<SWCRegistry with {} entries>".format(len(self.content.keys())) | ||
|
||
|
||
class SWC: | ||
""" | ||
SWC class contains information on an SWC entry | ||
Example usage: | ||
swc = SWC('SWC-100') | ||
print(swc.title) | ||
""" | ||
|
||
def __init__(self, swc_id, get_last=False): | ||
self.swc_id = swc_id | ||
if get_last: | ||
SWCRegistry().update() | ||
|
||
@property | ||
def _swc_content(self): | ||
return SWCRegistry().content | ||
|
||
@property | ||
def _content(self): | ||
entries = self._swc_content | ||
current_entry = entries.get(self.swc_id) | ||
if not current_entry: | ||
raise SWCException("SWC with ID {} does not exist".format(self.swc_id)) | ||
content = current_entry.get("content", {}) | ||
return content | ||
|
||
@property | ||
def title(self) -> str: | ||
content = self._content | ||
title = content.get("Title", "") | ||
return title | ||
|
||
@property | ||
def relationships(self) -> str: | ||
content = self._content | ||
relationships = content.get("Relationships", "") | ||
return relationships | ||
|
||
@property | ||
def description(self) -> str: | ||
content = self._content | ||
description = content.get("Description", "") | ||
return description | ||
|
||
@property | ||
def remediation(self) -> str: | ||
content = self._content | ||
remediation = content.get("Remediation", "") | ||
return remediation | ||
|
||
def __repr__(self): | ||
return "<SWC swc_id={0.swc_id} title={0.title}>".format(self) |
Oops, something went wrong.