Skip to content

Commit

Permalink
initial PyPi package release
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiSchwarz-cnic committed Jul 9, 2018
1 parent 67430e3 commit eb2ac4c
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 29 deletions.
11 changes: 4 additions & 7 deletions CONTRIBUTING.md
@@ -1,16 +1,14 @@
# Contributing

When contributing to this repository, please first discuss the change you wish to make via issue,
email, or any other method with the owners of this repository before making a change.
email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

## Pull Request (PR) Process

1. Ensure any install or build dependencies are removed before the end of the layer when doing a
build.
2. Update the README.md with details of changes to the interface, this includes new environment
variables, exposed ports, useful file locations and container parameters.
1. Ensure any install or build dependencies are removed before the end of the layer when doing a build.
2. Update the README.md with details of changes to the interface, this includes new environment variables, exposed ports, useful file locations and container parameters.
3. Address the PR to us, we care about further steps like versioning etc.

## Code of Conduct
Expand All @@ -37,8 +35,7 @@ include:

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
Expand Down
1 change: 1 addition & 0 deletions README.md
@@ -1,2 +1,3 @@
# python-sdk

Python SDK is a connector library for the insanely fast HEXONET backend API.
9 changes: 6 additions & 3 deletions __init__.py → hexonet/apiconnector/__init__.py
@@ -1,9 +1,12 @@
from ispapi.connection import Connection
from ispapi.response import Response
from apiconnector.connection import Connection
from apiconnector.response import Response

__version__ = '1.0.0'
name = "apiconnector"

def connect(login=None, password=None, url=None, entity=None, user=None, role=None, config=None):
"""
Returns an instance of ispapi.Connection
Returns an instance of apiconnector.Connection
"""

if config == None:
Expand Down
23 changes: 11 additions & 12 deletions connection.py → hexonet/apiconnector/connection.py
@@ -1,16 +1,22 @@
import ispapi.util
import urllib
import apiconnector.util
from apiconnector.response import Response
try:
# For Python 3.0 and later
from urllib.request import urlopen
except ImportError:
# Fall back to Python 2's urllib2
from urllib2 import urlopen
from ispapi.response import Response
try:
# For Python 3.0 and later
from urllib import parse as urlparse
except ImportError:
# Fall back to Python 2
from urlparse import urlparse


"""
ISPAPI Connection
APICONNECTOR Connection
"""
class Connection:
Expand All @@ -37,15 +43,8 @@ def call_raw_http(self, command, config = None):
if ('role' in self._config):
post['s_login'] = self._config['login'] + "!" + self._config['role']

post['s_command'] = ispapi.util.command_encode(command)

try:
# For Python 3.0 and later
post = urllib.parse.urlencode(post)
except:
# Fall back to Python 2's urllib2
post = urllib.urlencode(post)

post['s_command'] = apiconnector.util.command_encode(command)
post = urlparse.urlencode(post)
response = urlopen(self._config['url'], post.encode('UTF-8'))
content = response.read()
return content
Expand Down
8 changes: 4 additions & 4 deletions response.py → hexonet/apiconnector/response.py
@@ -1,7 +1,7 @@
import ispapi.util
import apiconnector.util

"""
ISPAPI Response
APICONNECTOR Response
"""
class Response:
Expand Down Expand Up @@ -41,7 +41,7 @@ def as_hash(self):
Returns the response as a hash
"""
if self._response_hash == None:
self._response_hash = ispapi.util.response_to_hash(self._response_string)
self._response_hash = apiconnector.util.response_to_hash(self._response_string)
return self._response_hash


Expand All @@ -50,7 +50,7 @@ def as_list_hash(self):
Returns the response as a list hash
"""
if self._response_list_hash == None:
self._response_list_hash = ispapi.util.response_to_list_hash(self.as_hash())
self._response_list_hash = apiconnector.util.response_to_list_hash(self.as_hash())
return self._response_list_hash


Expand Down
11 changes: 8 additions & 3 deletions util.py → hexonet/apiconnector/util.py
@@ -1,7 +1,12 @@
import re
from datetime import datetime
import time
import urllib
try:
# For Python 3.0 and later
from urllib import parse as urlparse
except ImportError:
# Fall back to Python 2
from urlparse import urlparse
import base64


Expand Down Expand Up @@ -152,13 +157,13 @@ def url_encode(string):
URL-encodes string
This function is convenient when encoding a string to be used in a query part of a URL
"""
return urllib.quote(string)
return urlparse.quote(string)

def url_decode(string):
"""
Decodes URL-encoded string Decodes any %## encoding in the given string.
"""
return urllib.unquote(string)
return urlparse.unquote(string)

def base64_encode(string):
"""
Expand Down
2 changes: 2 additions & 0 deletions scripts/createdistribution.sh
@@ -0,0 +1,2 @@
#!/bin/bash
python setup.py sdist bdist_wheel
2 changes: 2 additions & 0 deletions scripts/uploaddistribution_live.sh
@@ -0,0 +1,2 @@
#!/bin/bash
twine upload dist/*
2 changes: 2 additions & 0 deletions scripts/uploaddistribution_test.sh
@@ -0,0 +1,2 @@
#!/bin/bash
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
13 changes: 13 additions & 0 deletions setup.cfg
@@ -0,0 +1,13 @@
[bdist_wheel]
universal=1

[metadata]
license_file = LICENSE

[pep8]
max-line-length = 120

[flake8]
max-line-length = 120
ignore = F401,E402,F403
exclude = venv
55 changes: 55 additions & 0 deletions setup.py
@@ -0,0 +1,55 @@
#!/usr/bin/env python

import os
import io
import re

from setuptools import setup, find_packages

def read(*names, **kwargs):
with io.open(
os.path.join(os.path.dirname(__file__), *names),
encoding=kwargs.get("encoding", "utf8")
) as fp:
return fp.read()

def find_version(*file_paths):
version_file = read(*file_paths)
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
version_file, re.M)
if version_match:
return version_match.group(1)
raise RuntimeError("Unable to find version string.")

with open("README.md", "r") as fh:
long_description = fh.read()

VERSION = find_version('hexonet', 'apiconnector', '__init__.py')

requirements = [
'six'
]

setup(name='hexonet.apiconnector',
version=VERSION,
description='hexonet.apiconnector is a connector library for the insanely fast HEXONET Backend API',
long_description=long_description,
long_description_content_type="text/markdown",
author='Anthony Schneider',
author_email='anthonys@hexonet.net',
maintainer='Kai Schwarz',
maintainer_email='kschwarz@hexonet.net',
url='https://github.com/hexonet/python-sdk/',
packages=['hexonet.apiconnector'],
install_require=requirements,
license="MIT",
scripts=[],
zip_safe=True,
classifiers=(
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent"
),
namespace_packages = ['hexonet']
)

0 comments on commit eb2ac4c

Please sign in to comment.