Skip to content

Commit

Permalink
PEP-8 fix & simplify some code (#26)
Browse files Browse the repository at this point in the history
* PEP-8 fix change tab to space indentation
* Add __init__.py to src dir
* Simplify some code
* Fix error if speriod not defined
* Fix error if slength not defined & backward None for speriod
  • Loading branch information
ivlevdenis authored and dzungtran committed Mar 22, 2018
1 parent 05aa765 commit d40882e
Show file tree
Hide file tree
Showing 7 changed files with 461 additions and 451 deletions.
2 changes: 1 addition & 1 deletion __init__.py
@@ -1,4 +1,4 @@
from paymentwall.base import Paymentwall
from paymentwall.product import Product
from paymentwall.widget import Widget
from paymentwall.pingback import Pingback
from paymentwall.pingback import Pingback
8 changes: 8 additions & 0 deletions paymentwall/__init__.py
@@ -0,0 +1,8 @@
from __future__ import absolute_import

from .base import Paymentwall
from .pingback import Pingback
from .product import Product
from .widget import Widget

__all__ = ['Paymentwall', 'Pingback', 'Product', 'Widget']
165 changes: 82 additions & 83 deletions paymentwall/base.py
Expand Up @@ -3,86 +3,85 @@

class Paymentwall:

VERSION = '1.0.0'

API_VC = 1
API_GOODS = 2
API_CART = 3

VC_CONTROLLER = 'ps'
GOODS_CONTROLLER = 'subscription'
CART_CONTROLLER = 'cart'

DEFAULT_SIGNATURE_VERSION = 3
SIGNATURE_VERSION_1 = 1
SIGNATURE_VERSION_2 = 2
SIGNATURE_VERSION_3 = 3

errors = []

api_type = None
app_key = None
secret_key = None

@classmethod
def set_api_type(cls, api_type):
cls.api_type = api_type

@classmethod
def get_api_type(cls):
return cls.api_type

@classmethod
def set_app_key(cls, app_key):
cls.app_key = app_key

@classmethod
def get_app_key(cls):
return cls.app_key

@classmethod
def set_secret_key(cls, secret_key):
cls.secret_key = secret_key

@classmethod
def get_secret_key(cls):
return cls.secret_key

@classmethod
def append_to_errors(cls, err):
cls.errors.append(err)

@classmethod
def get_errors(cls):
return cls.errors

@classmethod
def get_error_summary(cls):
return '\n'.join(cls.get_errors())

#
# Helper functions
#
@classmethod
def is_empty(cls, dictionary, key):
if isinstance(dictionary, dict):
if key in dictionary:
if dictionary[key]:
return False
return True

@classmethod
def array_merge(cls, first_array, second_array):
if isinstance(first_array, list) and isinstance(second_array, list):
return first_array + second_array
elif isinstance(first_array, dict) and isinstance(second_array, dict):
return dict(list(first_array.items()) + list(second_array.items()))
elif isinstance(first_array, set) and isinstance(second_array, set):
return first_array.union(second_array)
return False

@classmethod
def hash(cls, string, library_type):
hashed_string = hashlib.md5() if library_type == 'md5' else hashlib.sha256()
hashed_string.update(string.encode('utf-8'))
return hashed_string.hexdigest()
VERSION = '1.0.0'

API_VC = 1
API_GOODS = 2
API_CART = 3

VC_CONTROLLER = 'ps'
GOODS_CONTROLLER = 'subscription'
CART_CONTROLLER = 'cart'

DEFAULT_SIGNATURE_VERSION = 3
SIGNATURE_VERSION_1 = 1
SIGNATURE_VERSION_2 = 2
SIGNATURE_VERSION_3 = 3

errors = []

api_type = None
app_key = None
secret_key = None

@classmethod
def set_api_type(cls, api_type):
cls.api_type = api_type

@classmethod
def get_api_type(cls):
return cls.api_type

@classmethod
def set_app_key(cls, app_key):
cls.app_key = app_key

@classmethod
def get_app_key(cls):
return cls.app_key

@classmethod
def set_secret_key(cls, secret_key):
cls.secret_key = secret_key

@classmethod
def get_secret_key(cls):
return cls.secret_key

@classmethod
def append_to_errors(cls, err):
cls.errors.append(err)

@classmethod
def get_errors(cls):
return cls.errors

@classmethod
def get_error_summary(cls):
return '\n'.join(cls.get_errors())

#
# Helper functions
#
@classmethod
def is_empty(cls, dictionary, key):
if isinstance(dictionary, dict):
if key in dictionary and dictionary[key]:
return False
return True

@classmethod
def array_merge(cls, first_array, second_array):
if isinstance(first_array, list) and isinstance(second_array, list):
return first_array + second_array
elif isinstance(first_array, dict) and isinstance(second_array, dict):
return dict(list(first_array.items()) + list(second_array.items()))
elif isinstance(first_array, set) and isinstance(second_array, set):
return first_array.union(second_array)
return False

@classmethod
def hash(cls, string, library_type):
hashed_string = hashlib.md5() if library_type == 'md5' else hashlib.sha256()
hashed_string.update(string.encode('utf-8'))
return hashed_string.hexdigest()

0 comments on commit d40882e

Please sign in to comment.