<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  propersubtract.py
#
#  Copyright 2016 Bruno S <bruno@oac.unc.edu.ar>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#
#

import os
import numpy as np
from . import propercoadd as pc
from . import utils as u

try:
    import pyfftw
    _fftwn = pyfftw.interfaces.numpy_fft.fftn
    _ifftwn = pyfftw.interfaces.numpy_fft.ifftn
except:
    _fftwn = np.fft.fft2
    _ifftwn = np.fft.ifft2

class ImageSubtractor(object):
    def __init__(self, refpath, newpath):

        #~ newpath = u.align_for_diff(refpath, newpath)

        self.ens = pc.ImageEnsemble([refpath, newpath])

    def subtract(self):
        ref = self.ens.atoms[0]
        new = self.ens.atoms[1]

        shape = ref.imagedata.shape

        _, psf_ref = ref.get_variable_psf()
        _, psf_new = new.get_variable_psf()

        psf_ref_hat = _fftwn(psf_ref[0], s=shape)
        psf_new_hat = _fftwn(psf_new[0], s=shape)

        r_zp = ref.zp
        n_zp = new.zp

        r_var = ref.bkg.globalrms
        n_var = new.bkg.globalrms

        D_hat_r = n_zp * psf_new_hat.conjugate() * _fftwn(ref.imagedata)
        D_hat_n = r_zp * psf_ref_hat.conjugate() * _fftwn(new.imagedata)

        norm  = r_var*r_var * r_zp*r_zp * psf_ref_hat*psf_ref_hat.conjugate()
        norm += n_var*n_var * n_zp*n_zp * psf_new_hat*psf_new_hat.conjugate()

        D_hat = (D_hat_n - D_hat_r)/np.sqrt(norm)

        #~ psf_rate = 1.  # this is a wrong value, but we can't calculate it now
        #~ lam = 1. + ((n_zp/n_var)/(r_zp/r_var))**2

        #~ D_hat = s_n/lam - (1. - 1./lam)*s_r
        D = _ifftwn(D_hat)

        #~ print lam
        return D, D_hat

<commit_msg>Context manager for subtractions<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  propersubtract.py
#
#  Copyright 2016 Bruno S <bruno@oac.unc.edu.ar>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#
#

import os
import numpy as np
from . import propercoadd as pc
from . import utils as u

try:
    import pyfftw
    _fftwn = pyfftw.interfaces.numpy_fft.fftn
    _ifftwn = pyfftw.interfaces.numpy_fft.ifftn
except:
    _fftwn = np.fft.fft2
    _ifftwn = np.fft.ifft2

class ImageSubtractor(object):
    def __init__(self, refpath, newpath):

        #~ newpath = u.align_for_diff(refpath, newpath)

        self.ens = pc.ImageEnsemble([refpath, newpath])

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        self._clean()

    def _clean(self):
        self.ens._clean()

    def subtract(self):
        ref = self.ens.atoms[0]
        new = self.ens.atoms[1]

        shape = ref.imagedata.shape

        _, psf_ref = ref.get_variable_psf()
        _, psf_new = new.get_variable_psf()

        psf_ref_hat = _fftwn(psf_ref[0], s=shape)
        psf_new_hat = _fftwn(psf_new[0], s=shape)

        r_zp = ref.zp
        n_zp = new.zp

        r_var = ref.bkg.globalrms
        n_var = new.bkg.globalrms

        D_hat_r = n_zp * psf_new_hat.conjugate() * _fftwn(ref.imagedata)
        D_hat_n = r_zp * psf_ref_hat.conjugate() * _fftwn(new.imagedata)

        norm  = r_var*r_var * r_zp*r_zp * psf_ref_hat*psf_ref_hat.conjugate()
        norm += n_var*n_var * n_zp*n_zp * psf_new_hat*psf_new_hat.conjugate()

        D_hat = (D_hat_n - D_hat_r)/np.sqrt(norm)

        #~ psf_rate = 1.  # this is a wrong value, but we can't calculate it now
        #~ lam = 1. + ((n_zp/n_var)/(r_zp/r_var))**2

        #~ D_hat = s_n/lam - (1. - 1./lam)*s_r
        D = _ifftwn(D_hat)

        #~ print lam
        return D, D_hat

<|endoftext|>


<commit_before># coding: utf-8

try:
    from setuptools import setup, find_packages
except ImportError:
    from distutils.core import setup

import sys
import shutil
import os
if sys.version_info[0] < 3:
    import __builtin__ as builtins
else:
    import builtins

from pysal.version import version as dversion

with open('README.txt') as file:
    long_description = file.read()

MINOR = 9
MICRO = 1
ISRELEASED = False
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)

# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
# update it when the contents of directories change.
if os.path.exists('MANIFEST'):
    os.remove('MANIFEST')

def setup_package():

    # Perform 2to3 if needed
    local_path = os.path.dirname(os.path.abspath(sys.argv[0]))  # get cwd
    src_path = local_path

    if sys.version_info[0] == 3:
        src_path = os.path.join(local_path, 'build', 'py3k')
        sys.path.insert(0, os.path.join(local_path, 'tools'))
        import py3tool
        print("Converting to Python3 via 2to3...")
        py3tool.sync_2to3('pysal', os.path.join(src_path, 'pysal'))

        site_cfg = os.path.join(local_path, 'site.cfg')
        if os.path.isfile(site_cfg):
            shutil.copy(site_cfg, src_path)

        # Ugly hack to make pip work with Python 3, see #1857.
        # Explanation: pip messes with __file__ which interacts badly with the
        # change in directory due to the 2to3 conversion.  Therefore we restore
        # __file__ to what it would have been otherwise.
        global __file__
        __file__ = os.path.join(os.curdir, os.path.basename(__file__))
        if '--egg-base' in sys.argv:
            # Change pip-egg-info entry to absolute path, so pip can find it
            # after changing directory.
            idx = sys.argv.index('--egg-base')
            if sys.argv[idx + 1] == 'pip-egg-info':
                sys.argv[idx + 1] = os.path.join(local_path, 'pip-egg-info')

    old_path = os.getcwd()
    os.chdir(src_path)
    sys.path.insert(0, src_path)

    # get all file endings and copy whole file names without a file suffix
    # assumes nested directories are only down one level
    example_data_files = set()
    for i in os.listdir("pysal/examples"):
        if i.endswith(('py', 'pyc')):
            continue
        if not os.path.isdir("pysal/examples/" + i):
            if "." in i:
                glob_name = "examples/*." + i.split(".")[-1]
            else:
                glob_name = "examples/" + i
        else:
            glob_name = "examples/" + i + "/*"

        example_data_files.add(glob_name)

    setup(
        name='PySAL',
        version=dversion,
        description="A library of spatial analysis functions.",
        long_description=long_description,
        maintainer="PySAL Developers",
        maintainer_email='pysal-dev@googlegroups.com',
        url='http://pysal.org',
        download_url='https://pypi.python.org/pypi/PySAL',
        license='BSD',
        py_modules=['pysal'],
        test_suite='nose.collector',
        tests_require=['nose'],
        keywords='spatial statistics',
        classifiers=[
            'Development Status :: 5 - Production/Stable',
            'Intended Audience :: Science/Research',
            'Intended Audience :: Developers',
            'Intended Audience :: Education',
            'Topic :: Scientific/Engineering',
            'Topic :: Scientific/Engineering :: GIS',
            'License :: OSI Approved :: BSD License',
            'Programming Language :: Python',
            'Programming Language :: Python :: 2.5',
            'Programming Language :: Python :: 2.6',
            'Programming Language :: Python :: 2.7'
        ],
        packages=find_packages(exclude=[".meta", "*.meta.*", "meta.*",
                                        "meta"]),
        package_data={'pysal': list(example_data_files)},
        requires=['scipy']
    )

if __name__ == '__main__':
    setup_package()
<commit_msg>missing Major<commit_after># coding: utf-8

try:
    from setuptools import setup, find_packages
except ImportError:
    from distutils.core import setup

import sys
import shutil
import os
if sys.version_info[0] < 3:
    import __builtin__ as builtins
else:
    import builtins

from pysal.version import version as dversion

with open('README.txt') as file:
    long_description = file.read()

MAJOR = 1
MINOR = 9
MICRO = 1
ISRELEASED = False
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)

# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
# update it when the contents of directories change.
if os.path.exists('MANIFEST'):
    os.remove('MANIFEST')

def setup_package():

    # Perform 2to3 if needed
    local_path = os.path.dirname(os.path.abspath(sys.argv[0]))  # get cwd
    src_path = local_path

    if sys.version_info[0] == 3:
        src_path = os.path.join(local_path, 'build', 'py3k')
        sys.path.insert(0, os.path.join(local_path, 'tools'))
        import py3tool
        print("Converting to Python3 via 2to3...")
        py3tool.sync_2to3('pysal', os.path.join(src_path, 'pysal'))

        site_cfg = os.path.join(local_path, 'site.cfg')
        if os.path.isfile(site_cfg):
            shutil.copy(site_cfg, src_path)

        # Ugly hack to make pip work with Python 3, see #1857.
        # Explanation: pip messes with __file__ which interacts badly with the
        # change in directory due to the 2to3 conversion.  Therefore we restore
        # __file__ to what it would have been otherwise.
        global __file__
        __file__ = os.path.join(os.curdir, os.path.basename(__file__))
        if '--egg-base' in sys.argv:
            # Change pip-egg-info entry to absolute path, so pip can find it
            # after changing directory.
            idx = sys.argv.index('--egg-base')
            if sys.argv[idx + 1] == 'pip-egg-info':
                sys.argv[idx + 1] = os.path.join(local_path, 'pip-egg-info')

    old_path = os.getcwd()
    os.chdir(src_path)
    sys.path.insert(0, src_path)

    # get all file endings and copy whole file names without a file suffix
    # assumes nested directories are only down one level
    example_data_files = set()
    for i in os.listdir("pysal/examples"):
        if i.endswith(('py', 'pyc')):
            continue
        if not os.path.isdir("pysal/examples/" + i):
            if "." in i:
                glob_name = "examples/*." + i.split(".")[-1]
            else:
                glob_name = "examples/" + i
        else:
            glob_name = "examples/" + i + "/*"

        example_data_files.add(glob_name)

    setup(
        name='PySAL',
        version=dversion,
        description="A library of spatial analysis functions.",
        long_description=long_description,
        maintainer="PySAL Developers",
        maintainer_email='pysal-dev@googlegroups.com',
        url='http://pysal.org',
        download_url='https://pypi.python.org/pypi/PySAL',
        license='BSD',
        py_modules=['pysal'],
        test_suite='nose.collector',
        tests_require=['nose'],
        keywords='spatial statistics',
        classifiers=[
            'Development Status :: 5 - Production/Stable',
            'Intended Audience :: Science/Research',
            'Intended Audience :: Developers',
            'Intended Audience :: Education',
            'Topic :: Scientific/Engineering',
            'Topic :: Scientific/Engineering :: GIS',
            'License :: OSI Approved :: BSD License',
            'Programming Language :: Python',
            'Programming Language :: Python :: 2.5',
            'Programming Language :: Python :: 2.6',
            'Programming Language :: Python :: 2.7'
        ],
        packages=find_packages(exclude=[".meta", "*.meta.*", "meta.*",
                                        "meta"]),
        package_data={'pysal': list(example_data_files)},
        requires=['scipy']
    )

if __name__ == '__main__':
    setup_package()
<|endoftext|>


<commit_before>#!/usr/bin/env python3

from pprint import pprint
from select import select
import importlib
import json
import re
import sys
import telnetlib
import traceback
telnetlib.GMCP = b'\xc9'

def log(*args):
    sys.stdout.write("     ----- ")
    print(*args)
    pass

class Session(object):
    def __init__(self, world_module, arg):
        self.mud_encoding = 'iso-8859-1'
        self.gmcp = {}
        self.world_module = world_module
        self.arg = arg
        self.world = world_module.getClass()(self, self.arg)
        host_port = self.world.getHostPort()
        self.telnet = self.connect(*host_port)
        self.gmcp = {}

    def join(self):
        self.thr.join()

    def log(*args):
        global log
        log(*args[1:])

    def strip_ansi(self, line):
        return re.sub(r'(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]', '', line)

    def gmcpOut(self, msg):
        self.telnet.sock.sendall(telnetlib.IAC + telnetlib.SB + telnetlib.GMCP + msg.encode(self.mud_encoding) + telnetlib.IAC + telnetlib.SE)

    def iac(self, sock, cmd, option):
        if cmd == telnetlib.WILL:
            if option == telnetlib.GMCP:
                log("Enabling GMCP")
                sock.sendall(telnetlib.IAC + telnetlib.DO + option)
                self.gmcpOut('Core.Hello { "client": "Cizra", "version": "1" }')
                supportables = ['char 1', 'char.base 1', 'char.maxstats 1', 'char.status 1', 'char.statusvars 1', 'char.vitals 1', 'char.worth 1', 'comm 1', 'comm.tick 1', 'group 1', 'room 1', 'room.info 1']
                self.gmcpOut('Core.Supports.Set ' + str(supportables).replace("'", '"'))
                self.gmcpOut('request room')
                self.gmcpOut('request char')
            elif option == telnetlib.TTYPE:
                log("Sending terminal type 'Cizra'")
                sock.sendall(telnetlib.IAC + telnetlib.DO + option +
                        telnetlib.IAC + telnetlib.SB + telnetlib.TTYPE + telnetlib.BINARY + b'Cizra' + telnetlib.IAC + telnetlib.SE)

            else:
                sock.sendall(telnetlib.IAC + telnetlib.DONT + option)
        elif cmd == telnetlib.SE:
            data = self.telnet.read_sb_data()
            if data[0] == ord(telnetlib.GMCP):
                try:
                    self.handleGmcp(data[1:].decode(self.mud_encoding))
                except Exception as e:
                    traceback.print_exc()

    def handleGmcp(self, data):
        # this.that {JSON blob}
        # TODO: move into clients
        space_idx = data.find(' ')
        whole_key = data[:space_idx]
        value_json = data[space_idx + 1:]
        nesting = whole_key.split('.')
        current = self.world.gmcp
        for nest in nesting[:-1]:
            if nest not in current:
                current[nest] = {}
            current = current[nest]
        lastkey = nesting[-1]
        try:
            val = json.loads(value_json)
        except json.decoder.JSONDecodeError:
            val = {"string": value_json}
        if lastkey not in current:
            current[lastkey] = {}
        current[lastkey] = val
        self.world.handleGmcp(whole_key, val)

    def connect(self, host, port):
        t = telnetlib.Telnet()
        t.set_option_negotiation_callback(self.iac)
        # t.set_debuglevel(1)
        t.open(host, int(port))
        return t

    def send(self, line):
        print("> ", line)
        self.telnet.write((line + '\n').encode(self.mud_encoding))

    def handle_input(self):
        try:
            data = self.telnet.read_very_eager()
        except EOFError:
            self.world.quit()
            raise
        try:
            data = data.decode(self.mud_encoding)
        except UnicodeError as e:
            print("Unicode error:", e)
            print("Data was:", data)
            data = ''

        if not data:
            _ = self.telnet.read_sb_data()
        prn = []
        for line in data.split('\n'):
            if line:
                replacement = None
                try:
                    replacement = self.world.trigger(line.strip())
                except Exception as e:
                    traceback.print_exc()
                if replacement is not None:
                    line = replacement
            prn.append(line)
        sys.stdout.write('\n'.join(prn))
        sys.stdout.flush()

    def handle_output(self):
        try:
            data = input()
        except EOFError:
            self.world.quit()
            raise

        if data == '#reload' and self.world:
            log('Reloading world')
            try:
                state = self.world.state
                self.world.quit()
                self.world_module = importlib.reload(self.world_module)
                self.world = self.world_module.getClass()(self, self.arg)
                self.world.state = state
                self.gmcpOut('request room')
                self.gmcpOut('request char')
            except Exception:
                traceback.print_exc()
            return
        else:
            handled = False
            try:
                handled = self.world.alias(data)
            except Exception as e:
                traceback.print_exc()
            else:
                if not handled:
                    self.send(data)

    def run(self):
        try:
            while True:
                try:
                    fds, _, _ = select([self.telnet.get_socket(), sys.stdin], [], [])
                except KeyboardInterrupt:
                    pass
                for fd in fds:
                    if fd == self.telnet.get_socket():
                        self.handle_input()
                    elif fd == sys.stdin:
                        self.handle_output()
        finally:
            self.telnet.close()

def main():
    if len(sys.argv) != 2 and len(sys.argv) != 3:
        print("Usage: {} worldmodule (without .py) [arg]".format(sys.argv[0]))
        exit(1)

    world_module = importlib.import_module(sys.argv[1])
    arg = sys.argv[2] if len(sys.argv) == 3 else None
    ses = Session(world_module, arg)
    ses.run()

assert(__name__ == '__main__')
main()
<commit_msg>Fixed hang when connecting fails<commit_after>#!/usr/bin/env python3

from pprint import pprint
from select import select
import importlib
import json
import re
import sys
import telnetlib
import traceback
telnetlib.GMCP = b'\xc9'

def log(*args):
    sys.stdout.write("     ----- ")
    print(*args)
    pass

class Session(object):
    def __init__(self, world_module, arg):
        self.mud_encoding = 'iso-8859-1'
        self.gmcp = {}
        self.world_module = world_module
        self.arg = arg
        self.world = world_module.getClass()(self, self.arg)
        try:
            host_port = self.world.getHostPort()
            self.telnet = self.connect(*host_port)
            self.gmcp = {}
        except:
            self.world.quit()
            raise

    def join(self):
        self.thr.join()

    def log(*args):
        global log
        log(*args[1:])

    def strip_ansi(self, line):
        return re.sub(r'(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]', '', line)

    def gmcpOut(self, msg):
        self.telnet.sock.sendall(telnetlib.IAC + telnetlib.SB + telnetlib.GMCP + msg.encode(self.mud_encoding) + telnetlib.IAC + telnetlib.SE)

    def iac(self, sock, cmd, option):
        if cmd == telnetlib.WILL:
            if option == telnetlib.GMCP:
                log("Enabling GMCP")
                sock.sendall(telnetlib.IAC + telnetlib.DO + option)
                self.gmcpOut('Core.Hello { "client": "Cizra", "version": "1" }')
                supportables = ['char 1', 'char.base 1', 'char.maxstats 1', 'char.status 1', 'char.statusvars 1', 'char.vitals 1', 'char.worth 1', 'comm 1', 'comm.tick 1', 'group 1', 'room 1', 'room.info 1']
                self.gmcpOut('Core.Supports.Set ' + str(supportables).replace("'", '"'))
                self.gmcpOut('request room')
                self.gmcpOut('request char')
            elif option == telnetlib.TTYPE:
                log("Sending terminal type 'Cizra'")
                sock.sendall(telnetlib.IAC + telnetlib.DO + option +
                        telnetlib.IAC + telnetlib.SB + telnetlib.TTYPE + telnetlib.BINARY + b'Cizra' + telnetlib.IAC + telnetlib.SE)

            else:
                sock.sendall(telnetlib.IAC + telnetlib.DONT + option)
        elif cmd == telnetlib.SE:
            data = self.telnet.read_sb_data()
            if data[0] == ord(telnetlib.GMCP):
                try:
                    self.handleGmcp(data[1:].decode(self.mud_encoding))
                except Exception as e:
                    traceback.print_exc()

    def handleGmcp(self, data):
        # this.that {JSON blob}
        # TODO: move into clients
        space_idx = data.find(' ')
        whole_key = data[:space_idx]
        value_json = data[space_idx + 1:]
        nesting = whole_key.split('.')
        current = self.world.gmcp
        for nest in nesting[:-1]:
            if nest not in current:
                current[nest] = {}
            current = current[nest]
        lastkey = nesting[-1]
        try:
            val = json.loads(value_json)
        except json.decoder.JSONDecodeError:
            val = {"string": value_json}
        if lastkey not in current:
            current[lastkey] = {}
        current[lastkey] = val
        self.world.handleGmcp(whole_key, val)

    def connect(self, host, port):
        t = telnetlib.Telnet()
        t.set_option_negotiation_callback(self.iac)
        # t.set_debuglevel(1)
        t.open(host, int(port))
        return t

    def send(self, line):
        print("> ", line)
        self.telnet.write((line + '\n').encode(self.mud_encoding))

    def handle_input(self):
        try:
            data = self.telnet.read_very_eager()
        except EOFError:
            self.world.quit()
            raise
        try:
            data = data.decode(self.mud_encoding)
        except UnicodeError as e:
            print("Unicode error:", e)
            print("Data was:", data)
            data = ''

        if not data:
            _ = self.telnet.read_sb_data()
        prn = []
        for line in data.split('\n'):
            if line:
                replacement = None
                try:
                    replacement = self.world.trigger(line.strip())
                except Exception as e:
                    traceback.print_exc()
                if replacement is not None:
                    line = replacement
            prn.append(line)
        sys.stdout.write('\n'.join(prn))
        sys.stdout.flush()

    def handle_output(self):
        try:
            data = input()
        except EOFError:
            self.world.quit()
            raise

        if data == '#reload' and self.world:
            log('Reloading world')
            try:
                state = self.world.state
                self.world.quit()
                self.world_module = importlib.reload(self.world_module)
                self.world = self.world_module.getClass()(self, self.arg)
                self.world.state = state
                self.gmcpOut('request room')
                self.gmcpOut('request char')
            except Exception:
                traceback.print_exc()
            return
        else:
            handled = False
            try:
                handled = self.world.alias(data)
            except Exception as e:
                traceback.print_exc()
            else:
                if not handled:
                    self.send(data)

    def run(self):
        try:
            while True:
                try:
                    fds, _, _ = select([self.telnet.get_socket(), sys.stdin], [], [])
                except KeyboardInterrupt:
                    pass
                for fd in fds:
                    if fd == self.telnet.get_socket():
                        self.handle_input()
                    elif fd == sys.stdin:
                        self.handle_output()
        finally:
            self.telnet.close()

def main():
    if len(sys.argv) != 2 and len(sys.argv) != 3:
        print("Usage: {} worldmodule (without .py) [arg]".format(sys.argv[0]))
        exit(1)

    world_module = importlib.import_module(sys.argv[1])
    arg = sys.argv[2] if len(sys.argv) == 3 else None
    ses = Session(world_module, arg)
    ses.run()

assert(__name__ == '__main__')
main()
<|endoftext|>


<commit_before>from setuptools import setup, find_packages

requirements = [
    "alembic>=0.6.4, <1.0",
    "beautifulsoup4>=4.3.2, <5.0",
    "blinker>=1.3, <2.0",
    "Flask-Babel>=0.9, <1.0",
    "Flask-Login",                      # was pinned to Flask-Login==0.2.3 in the past. GitHub version 3.0+ is used now.
    "Flask-Mail>=0.9.0, <1.0",
    "misaka>=1.0.0, <2.0.0"
    "Flask-Misaka>=0.2.0, <1.0",
    "Flask-OAuthlib>=0.9.1, <0.9.2",
    "Flask-SQLAlchemy>=2.0, <2.1",
    "Flask-WTF>=0.9.5, <0.9.6",         # was pinned to Flask-WTF==0.9.5
    "Flask>=0.10.1, <0.10.2",           # was pinned to Flask==0.10.1
    "html2text>=2014.4.5, <2014.9.7",
    "itsdangerous>=0.24, <1.0",
    "M2Crypto>=0.22.3, <0.22.4",        # let's be more restrictive on M2Crypto version
    "markdown>=2.4, <3.0",
    "psycopg2>=2.5.2, <3.0",
    "pygeoip>=0.3.1, <1.0",
    "python-dateutil>=2.2, <3.0",
    "raven>=4.1.1, <5.0",
    "pyOpenSSL>=0.15.1, <1.0",          # fix for python below 2.7.9
    "ndg-httpsclient>=0.4.0, <1.0",     # fix for python below 2.7.9
    "pyasn1>=0.1.7, <1.0",              # fix for python below 2.7.9
    "requests>=2.2.1, <3.0",
    "SQLAlchemy>=1.0.5, <1.0.6",
    "six>=1.9.0, <2.0.0",
    "nose",
    "rednose",
    "redis>=2.9, <2.10",
    "sphinx>=1.2.2, <2.0",
    "coverage",
    "mock",
    "pyrax>=1.9.5, <2.0",
    "pillow>=2.4, <2.5",
    "flask-debugtoolbar>=0.9.0, <1.0",
    "factory_boy>=2.4.1, <2.5",
    "rq>=0.4.6, <0.5",
    "rq-scheduler>=0.5.1, <0.5.2",
    "rq-dashboard",
    "unidecode>=0.04.16, <0.05",
    "mailchimp",
    "flask-plugins",
    "humanize",
    "pbr>=1.0, <2.0",                   # keep an eye on pbr: https://github.com/rackspace/pyrax/issues/561
]

setup(
    name = 'pybossa',
    version = '1.1.2',
    packages = find_packages(),
    install_requires = requirements,
    # only needed when installing directly from setup.py (PyPi, eggs?) and pointing to e.g. a git repo.
    # Keep in mind that dependency_links are not used when installing with requirements.txt
    # and need to be added redundant to requirements.txt in this case!
    # Example:
    # dependency_links = ['git+https://github.com/Hypernode/M2Crypto#egg=M2Crypto-0.22.dev'],
    dependency_links = ['git+https://github.com/maxcountryman/flask-login.git@13af160b3fd14dfb5f35f9cdc3863771efe194eb#egg=Flask-Login',
                        'git+https://github.com/PyBossa/rq-dashboard.git#egg=rq-dashboard'],

    # metadata for upload to PyPI
    author = 'SciFabric LTD',
    # TODO: change
    author_email = 'info@scifabric.com',
    description = 'Open Source CrowdSourcing framework',
    long_description = '''PyBossa is an open source crowdsourcing solution for volunteer computing, thinking and sensing ''',
    license = 'AGPLv3',
    url = 'http://pybossa.com',
    download_url = 'https://github.com/PyBossa/pybossa',
    include_package_data = True,
    classifiers = [
        'Development Status :: 5 - Production/Stable',
        'Environment :: Console',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: GNU Affero v3',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        'Topic :: Software Development :: Libraries :: Python Modules'
    ],
    entry_points = '''
    '''
)
<commit_msg>fix typo<commit_after>from setuptools import setup, find_packages

requirements = [
    "alembic>=0.6.4, <1.0",
    "beautifulsoup4>=4.3.2, <5.0",
    "blinker>=1.3, <2.0",
    "Flask-Babel>=0.9, <1.0",
    "Flask-Login",                      # was pinned to Flask-Login==0.2.3 in the past. GitHub version 3.0+ is used now.
    "Flask-Mail>=0.9.0, <1.0",
    "misaka>=1.0.0, <2.0.0",
    "Flask-Misaka>=0.2.0, <1.0",
    "Flask-OAuthlib>=0.9.1, <0.9.2",
    "Flask-SQLAlchemy>=2.0, <2.1",
    "Flask-WTF>=0.9.5, <0.9.6",         # was pinned to Flask-WTF==0.9.5
    "Flask>=0.10.1, <0.10.2",           # was pinned to Flask==0.10.1
    "html2text>=2014.4.5, <2014.9.7",
    "itsdangerous>=0.24, <1.0",
    "M2Crypto>=0.22.3, <0.22.4",        # let's be more restrictive on M2Crypto version
    "markdown>=2.4, <3.0",
    "psycopg2>=2.5.2, <3.0",
    "pygeoip>=0.3.1, <1.0",
    "python-dateutil>=2.2, <3.0",
    "raven>=4.1.1, <5.0",
    "pyOpenSSL>=0.15.1, <1.0",          # fix for python below 2.7.9
    "ndg-httpsclient>=0.4.0, <1.0",     # fix for python below 2.7.9
    "pyasn1>=0.1.7, <1.0",              # fix for python below 2.7.9
    "requests>=2.2.1, <3.0",
    "SQLAlchemy>=1.0.5, <1.0.6",
    "six>=1.9.0, <2.0.0",
    "nose",
    "rednose",
    "redis>=2.9, <2.10",
    "sphinx>=1.2.2, <2.0",
    "coverage",
    "mock",
    "pyrax>=1.9.5, <2.0",
    "pillow>=2.4, <2.5",
    "flask-debugtoolbar>=0.9.0, <1.0",
    "factory_boy>=2.4.1, <2.5",
    "rq>=0.4.6, <0.5",
    "rq-scheduler>=0.5.1, <0.5.2",
    "rq-dashboard",
    "unidecode>=0.04.16, <0.05",
    "mailchimp",
    "flask-plugins",
    "humanize",
    "pbr>=1.0, <2.0",                   # keep an eye on pbr: https://github.com/rackspace/pyrax/issues/561
]

setup(
    name = 'pybossa',
    version = '1.1.2',
    packages = find_packages(),
    install_requires = requirements,
    # only needed when installing directly from setup.py (PyPi, eggs?) and pointing to e.g. a git repo.
    # Keep in mind that dependency_links are not used when installing with requirements.txt
    # and need to be added redundant to requirements.txt in this case!
    # Example:
    # dependency_links = ['git+https://github.com/Hypernode/M2Crypto#egg=M2Crypto-0.22.dev'],
    dependency_links = ['git+https://github.com/maxcountryman/flask-login.git@13af160b3fd14dfb5f35f9cdc3863771efe194eb#egg=Flask-Login',
                        'git+https://github.com/PyBossa/rq-dashboard.git#egg=rq-dashboard'],

    # metadata for upload to PyPI
    author = 'SciFabric LTD',
    # TODO: change
    author_email = 'info@scifabric.com',
    description = 'Open Source CrowdSourcing framework',
    long_description = '''PyBossa is an open source crowdsourcing solution for volunteer computing, thinking and sensing ''',
    license = 'AGPLv3',
    url = 'http://pybossa.com',
    download_url = 'https://github.com/PyBossa/pybossa',
    include_package_data = True,
    classifiers = [
        'Development Status :: 5 - Production/Stable',
        'Environment :: Console',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: GNU Affero v3',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        'Topic :: Software Development :: Libraries :: Python Modules'
    ],
    entry_points = '''
    '''
)
<|endoftext|>


<commit_before>import sys

registers = [0 for _ in xrange(32)]

def execute(line):
    instr = line.split()
    opcode = instr[0]
    if opcode == 'li':
        # li $1, 3
        target = int(instr[1][1:-1])  # $ and ,
        toput = int(instr[2])
        registers[target] = toput

def dump():
    for i, each in enumerate(registers):
        print '${} : {}'.format(i, each)

def main():
    if len(sys.argv) != 2:
        print 'usage'
        sys.exit(1)

    with open(sys.argv[1]) as f:
        for line in f.readlines():
            execute(line)

    dump()

if __name__ == '__main__':
    main()
<commit_msg>Add Registers class<commit_after>import sys

class Registers:
    def __init__(self):
        self.registers = [0 for _ in xrange(32)]
        self.regtab = {
            'v0': 2,
            'v1': 3,
        }

    def read(self, reg):
        ind = reg if type(reg) is int else self.regtab[reg]
        return self.registers[ind]

    def write(self, reg, contents):
        ind = reg if type(reg) is int else self.regtab[reg]
        self.registers[ind] = contents

    def dump(self):
        for i, each in enumerate(self.registers):
            print '${} : {}\t\t'.format(i, each)

R = Registers()

def execute(line):
    instr = line.split()
    opcode = instr[0]
    if opcode == 'li':
        # li $1, 3
        dest = int(instr[1][1:-1])  # $ and ,
        src = int(instr[2])
        R.write(dest, src)

def main():
    if len(sys.argv) != 2:
        print 'usage'
        sys.exit(1)

    with open(sys.argv[1]) as f:
        for line in f.readlines():
            execute(line)

    R.dump()

if __name__ == '__main__':
    main()
<|endoftext|>


<commit_before>#!/usr/bin/env python
import os
import sys

from setuptools import find_packages, setup

from django_x509 import get_version

def get_install_requires():
    """
    parse requirements.txt, ignore links, exclude comments
    """
    requirements = []
    for line in open('requirements.txt').readlines():
        # skip to next iteration if comment or empty line
        if line.startswith('#') or line == '' or line.startswith('http') or line.startswith('git'):
            continue
        # add line to requirements
        requirements.append(line)
    return requirements

if sys.argv[-1] == 'publish':
    # delete any *.pyc, *.pyo and __pycache__
    os.system('find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf')
    os.system("python setup.py sdist bdist_wheel upload -s")
    args = {'version': get_version()}
    print("You probably want to also tag the version now:")
    print("  git tag -a %(version)s -m 'version %(version)s'" % args)
    print("  git push --tags")
    sys.exit()

setup(
    name='django-x509',
    version=get_version(),
    license='BSD',
    author='Federico Capoano',
    author_email='f.capoano@cineca.it',
    description='Reusable django app to generate and manage x509 certificates',
    long_description=open('README.rst').read(),
    url='https://github.com/openwisp/django-x509',
    download_url='https://github.com/openwisp/django-x509/releases',
    platforms=['Platform Indipendent'],
    keywords=['django', 'x509', 'pki', 'PEM', 'openwisp'],
    packages=find_packages(exclude=['tests', 'docs']),
    include_package_data=True,
    zip_safe=False,
    install_requires=get_install_requires(),
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Environment :: Web Environment',
        'Topic :: Internet :: WWW/HTTP',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: BSD License',
        'Operating System :: OS Independent',
        'Framework :: Django',
        'Topic :: Security :: Cryptography',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3.4',
    ]
)
<commit_msg>[setup.py] Remove build dir<commit_after>#!/usr/bin/env python
import os
import sys

from setuptools import find_packages, setup

from django_x509 import get_version

def get_install_requires():
    """
    parse requirements.txt, ignore links, exclude comments
    """
    requirements = []
    for line in open('requirements.txt').readlines():
        # skip to next iteration if comment or empty line
        if line.startswith('#') or line == '' or line.startswith('http') or line.startswith('git'):
            continue
        # add line to requirements
        requirements.append(line)
    return requirements

if sys.argv[-1] == 'publish':
    # delete any *.pyc, *.pyo and __pycache__
    os.system('find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf')
    os.system('rm -rf build/')
    os.system("python setup.py sdist bdist_wheel upload -s")
    args = {'version': get_version()}
    print("You probably want to also tag the version now:")
    print("  git tag -a %(version)s -m 'version %(version)s'" % args)
    print("  git push --tags")
    sys.exit()

setup(
    name='django-x509',
    version=get_version(),
    license='BSD',
    author='Federico Capoano',
    author_email='f.capoano@cineca.it',
    description='Reusable django app to generate and manage x509 certificates',
    long_description=open('README.rst').read(),
    url='https://github.com/openwisp/django-x509',
    download_url='https://github.com/openwisp/django-x509/releases',
    platforms=['Platform Indipendent'],
    keywords=['django', 'x509', 'pki', 'PEM', 'openwisp'],
    packages=find_packages(exclude=['tests', 'docs']),
    include_package_data=True,
    zip_safe=False,
    install_requires=get_install_requires(),
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Environment :: Web Environment',
        'Topic :: Internet :: WWW/HTTP',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: BSD License',
        'Operating System :: OS Independent',
        'Framework :: Django',
        'Topic :: Security :: Cryptography',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3.4',
    ]
)
<|endoftext|>


<commit_before>import os
import base64
import boto.ec2

# EU-WEST-1: RHEL7 HVM
AMI_ID = 'ami-25158352'
region = 'eu-west-1'

def generate_userdata():
	'''Read environment vars and various other things to
	get SSH keys, usernames and deploy scripts and inject them into an
	instance as a userdata script
	'''
	ssh_key					= os.environ["DEPLOY_SSH_KEY"]
	deploy_script_location	= os.environ["DEPLOY_SCRIPT_LOCATION"]
	with open(deploy_script_location, 'r') as deploy_handle:
		deploy_script = deploy_handle.readlines()
	deploy_handle.close()
	user_data = '''#!/bin/bash

	printf '{0}' >> /home/ec2-user/.ssh/authorized_keys;
	echo {1} > /opt/code-deploy/deploy.sh
	sudo chmod a+x /opt/code-deploy/deploy.sh
	echo "all done"

	'''.format(ssh_key, deploy_script)
	print user_data

	return base64.b64encode(user_data)

def create_many(definitions, cluster_id):
	return map(format_instance, map(lambda data: create_new(data, cluster_id),
		definitions))

def create_new(data, cluster_id):
	# Always keep the nursery full
	name = data['name'] if 'name' in data else 'unnamed instance'
	nursery_instance = create_new_in_nursery(data)

	instances = transfer_machine_from_nursery_to_cluster(cluster_id, new_name=name)

	if len(instances) == 1:
		return instances[0]

	raise Exception("No available instances")

def create_new_in_nursery(data):
	security_groups = [ 'sg-8a2574ef' ]
	connection = boto.ec2.connect_to_region(region)
	instance = connection.run_instances(AMI_ID, instance_type='m3.medium', user_data=generate_userdata()).instances[0]
	connection.create_tags([instance.id], { 'cluster': '__nursery__' })

	return instance

def transfer_machine_from_nursery_to_cluster(cluster_id, new_name="clustered_machine"):
	connection = boto.ec2.connect_to_region(region)

	# TODO: RACE CONDITIONS COULD OCCUR HERE! Need a DLM?
	instances = connection.get_only_instances(filters={ 'instance-state-name':
		'running', 'tag-key': 'cluster', 'tag-value':
		'__nursery__'})

	connection.create_tags(map(lambda instance: instance.id, instances),
			tags={ 'cluster': str(cluster_id), 'Name': new_name })
	# END OF RACE CONDITION TERRITORY
	return instances

def get_instances_in_cluster(cluster_id):
	connection = boto.ec2.connect_to_region(region)
	return 	map(format_instance, connection.get_only_instances(filters={ 'tag-key': 'cluster',
				'tag-value': cluster_id }))

def format_instance(instance):
	return {
		'id': instance.id,
		'name': instance.tags['Name'],
#		'hostname': instance.private_ip_address,
		'hostname': instance.public_dns_name,
# hardcoded m3.medium
		'cpu': 1,
		'memory': '4026531840',
		'disk': '4',
		'region': region,
		'metadata': '{}',
		'state': instance.state
	}

def get_instance_info(instance_ids):
	connection = boto.ec2.connect_to_region(region)
	instance_states = connection.get_only_instances(instance_ids=instance_ids)
	return instances

def delete_instance(instance_id, region):
	connection = boto.ec2.connect_to_region(region)
	connection.terminate_instances(instance_ids=[instance_id])
	return True
<commit_msg>Add luke's key<commit_after>import os
import base64
import boto.ec2

# EU-WEST-1: RHEL7 HVM
AMI_ID = 'ami-25158352'
region = 'eu-west-1'

def generate_userdata():
	'''Read environment vars and various other things to
	get SSH keys, usernames and deploy scripts and inject them into an
	instance as a userdata script
	'''
	ssh_key					= os.environ["DEPLOY_SSH_KEY"]
	deploy_script_location	= os.environ["DEPLOY_SCRIPT_LOCATION"]
	with open(deploy_script_location, 'r') as deploy_handle:
		deploy_script = deploy_handle.readlines()
	deploy_handle.close()
	user_data = '''#!/bin/bash

	printf '{0}' >> /home/ec2-user/.ssh/authorized_keys;
	echo {1} > /opt/code-deploy/deploy.sh
	sudo chmod a+x /opt/code-deploy/deploy.sh
	echo "all done"

	'''.format(ssh_key, deploy_script)
	print user_data

	return base64.b64encode(user_data)

def create_many(definitions, cluster_id):
	return map(format_instance, map(lambda data: create_new(data, cluster_id),
		definitions))

def create_new(data, cluster_id):
	# Always keep the nursery full
	name = data['name'] if 'name' in data else 'unnamed instance'
	nursery_instance = create_new_in_nursery(data)

	instances = transfer_machine_from_nursery_to_cluster(cluster_id, new_name=name)

	if len(instances) == 1:
		return instances[0]

	raise Exception("No available instances")

def create_new_in_nursery(data):
	security_groups = [ 'sg-8a2574ef' ]
	connection = boto.ec2.connect_to_region(region)
	instance = connection.run_instances(AMI_ID, instance_type='m3.medium',
			user_data=generate_userdata(), key_name="LukeBlaney").instances[0]
	connection.create_tags([instance.id], { 'cluster': '__nursery__' })

	return instance

def transfer_machine_from_nursery_to_cluster(cluster_id, new_name="clustered_machine"):
	connection = boto.ec2.connect_to_region(region)

	# TODO: RACE CONDITIONS COULD OCCUR HERE! Need a DLM?
	instances = connection.get_only_instances(filters={ 'instance-state-name':
		'running', 'tag-key': 'cluster', 'tag-value':
		'__nursery__'})

	connection.create_tags(map(lambda instance: instance.id, instances),
			tags={ 'cluster': str(cluster_id), 'Name': new_name })
	# END OF RACE CONDITION TERRITORY
	return instances

def get_instances_in_cluster(cluster_id):
	connection = boto.ec2.connect_to_region(region)
	return 	map(format_instance, connection.get_only_instances(filters={ 'tag-key': 'cluster',
				'tag-value': cluster_id }))

def format_instance(instance):
	return {
		'id': instance.id,
		'name': instance.tags['Name'],
#		'hostname': instance.private_ip_address,
		'hostname': instance.public_dns_name,
# hardcoded m3.medium
		'cpu': 1,
		'memory': '4026531840',
		'disk': '4',
		'region': region,
		'metadata': '{}',
		'state': instance.state
	}

def get_instance_info(instance_ids):
	connection = boto.ec2.connect_to_region(region)
	instance_states = connection.get_only_instances(instance_ids=instance_ids)
	return instances

def delete_instance(instance_id, region):
	connection = boto.ec2.connect_to_region(region)
	connection.terminate_instances(instance_ids=[instance_id])
	return True
<|endoftext|>


<commit_before>import codecs
from setuptools import setup

classifiers = '''\
Framework :: Django
Environment :: Web Environment
Intended Audience :: Developers
Topic :: Internet :: WWW/HTTP
License :: OSI Approved :: Apache Software License
Development Status :: 5 - Production/Stable
Natural Language :: English
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.6
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.2
Programming Language :: Python :: 3.3
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: Implementation :: PyPy
Operating System :: MacOS :: MacOS X
Operating System :: Microsoft :: Windows
Operating System :: POSIX
Operating System :: Unix
'''

description = 'iron.io cache as Django sessions backend'

packages = ['iron_sessions', ]

def long_description():
    with codecs.open('README.rst', 'r', encoding="utf-8") as f:
        rst = f.read()
    return rst

setup(
    name='django-iron-sessions',
    version='0.0.2',
    packages=packages,
    description=description,
    long_description=long_description(),
    author='hellysmile',
    author_email='hellysmile@gmail.com',
    url='https://github.com/hellysmile/django-iron-sessions',
    zip_safe=False,
    install_requires=[
        'django >= 1.4',
        'iron-cache == 0.2.0'
    ],
    license='http://www.apache.org/licenses/LICENSE-2.0',
    classifiers=filter(None, classifiers.split('\n')),
    keywords=[
        "django", "sessions", "iron cache", "heroku"
    ]
)
<commit_msg>Bump version<commit_after>import codecs
from setuptools import setup

classifiers = '''\
Framework :: Django
Environment :: Web Environment
Intended Audience :: Developers
Topic :: Internet :: WWW/HTTP
License :: OSI Approved :: Apache Software License
Development Status :: 5 - Production/Stable
Natural Language :: English
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.6
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.2
Programming Language :: Python :: 3.3
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: Implementation :: PyPy
Operating System :: MacOS :: MacOS X
Operating System :: Microsoft :: Windows
Operating System :: POSIX
Operating System :: Unix
'''

description = 'iron.io cache as Django sessions backend'

packages = ['iron_sessions', ]

def long_description():
    with codecs.open('README.rst', 'r', encoding="utf-8") as f:
        rst = f.read()
    return rst

setup(
    name='django-iron-sessions',
    version='0.0.3',
    packages=packages,
    description=description,
    long_description=long_description(),
    author='hellysmile',
    author_email='hellysmile@gmail.com',
    url='https://github.com/hellysmile/django-iron-sessions',
    zip_safe=False,
    install_requires=[
        'django >= 1.4',
        'iron-cache == 0.2.0'
    ],
    license='http://www.apache.org/licenses/LICENSE-2.0',
    classifiers=filter(None, classifiers.split('\n')),
    keywords=[
        "django", "sessions", "iron cache", "heroku"
    ]
)
<|endoftext|>


<commit_before># -*- coding: utf-8 -*-
"""
    pyfan
    a command line fanfou client
    ~~~~~~~~~~~~~~~~

    :copyright: 2016 by raptor.zh@gmail.com.

    usage:

    python
    >> import pyfan
    >> pyfan.timeline(10)
    >> pyfan.mentions(10)
    >> pyfan.usertimeline(user_id, 10)
    >> pyfan.showstatus("smmM8CbcJ4E")
    >> pyfan.destroy("tp6O2eYs2SI")
    >> pyfan.post(u"status", "photo.jpg")
    >> pyfan.repost(u"status", index)
    >> pyfan.reply(u"status", index)
"""
from os.path import exists
from datetime import datetime

from restclient.fanfou import Fanfou

from config import config

import logging

logger = logging.getLogger(__name__)

tldata = []

def get_api():
    return Fanfou(config['CLIENT_KEY'], client_secret=config['CLIENT_SECRET'],
                  token=config['ACCESS_TOKEN'],
                  token_secret=config['ACCESS_SECRET'],
                  proxies={"http": config['proxy'], "https": config['proxy']} if config['proxy'] else None)

def print_status(i, status):
    row = {}
    row[u'index'] = i
    row[u'created'] = datetime.strptime(status['created_at'], "%a %b %d %H:%M:%S +0000 %Y").strftime("%Y-%m-%d %H:%M:%S")
    row[u'id'] = status['id']
    row[u'screen_name'] = status['user']['screen_name']
    row[u'user_id'] = status['user']['id']
    row[u'text'] = status['text']
    row[u'photo'] = status['photo']['largeurl'] if status.get('photo') else ""
    print(u"[%(index)s]%(created)s(%(id)s)%(screen_name)s(%(user_id)s): %(text)s %(photo)s" % row)

def timeline(count=10, page=0):
    api = get_api()
    global tldata
    data = api.statuses.GET_home_timeline(count=count, page=page, mode='lite')
    del tldata[:]
    tldata.extend(data)
    for i, status in enumerate(data):
        print_status(i, status)

def mentions(count=10, page=0):
    api = get_api()
    global tldata
    data = api.statuses.GET_mentions(count=count, page=page, mode="lite")
    del tldata[:]
    tldata.extend(data)
    for i, status in enumerate(data):
        print_status(i, status)

def usertimeline(user_id, count=10, page=0):
    api = get_api()
    global tldata
    data = api.statuses.GET_user_timeline(id=user_id, count=count, page=page, mode='lite')
    del tldata[:]
    tldata.extend(data)
    for i, status in enumerate(data):
        print_status(i, status)

def showstatus(status_id):
    api = get_api()
    data = api.statuses.GET_show(id=status_id, mode="lite")
    del tldata[:]
    tldata.append(data)
    print_status(0, data)

def destroy(status_id):
    api = get_api()
    api.statuses.POST_destroy(id=status_id, mode="lite")

def post(status, photo="", in_reply_to_status_id=None, repost_status_id=None, in_reply_to_user_id=None):
    api = get_api()
    if photo:
        if not exists(photo):
            print("Photo file {} not found!".format(photo))
        else:
            api.photos.POST_upload(status=status, photo=open(photo, "rb"), mode="lite")
    else:
        api.statuses.POST_update(status=status,
                in_reply_to_status_id=in_reply_to_status_id,
                repost_status_id=repost_status_id,
                in_reply_to_user_id=in_reply_to_user_id,
                mode="lite")

def reply(status, index):
    global tldata
    in_reply_to = tldata[index]
    api = get_api()
    api.statuses.POST_update(status=u"@{} {}".format(in_reply_to['user']['screen_name'], status),
                             in_reply_to_status_id=in_reply_to['id'],
                             in_reply_to_user_id=in_reply_to['user']['id'])

def repost(status, index):
    global tldata
    in_reply_to = tldata[index]
    api = get_api()
    api.statuses.POST_update(status=u"{} 转:@{} {}".format(status, in_reply_to['user']['screen_name'], in_reply_to['text']),
                             repost_status_id=in_reply_to['id'])

<commit_msg>add showstatus/destory with index, add replyall<commit_after># -*- coding: utf-8 -*-
"""
    pyfan
    a command line fanfou client
    ~~~~~~~~~~~~~~~~

    :copyright: 2016 by raptor.zh@gmail.com.

    usage:

    python
    >> import pyfan
    >> pyfan.timeline(10)
    >> pyfan.mentions(10)
    >> pyfan.usertimeline(user_id, 10)
    >> pyfan.showstatus("smmM8CbcJ4E") or index
    >> pyfan.destroy("tp6O2eYs2SI") or index
    >> pyfan.post(u"status", "photo.jpg")
    >> pyfan.repost(u"status", index)
    >> pyfan.reply(u"status", index)
    >> pyfan.replyall(u"status", index)
"""
from os.path import exists
from datetime import datetime
import re

from restclient.fanfou import Fanfou

from config import config

import logging

logger = logging.getLogger(__name__)

tldata = []

pat_reply = re.compile(u"@([^\s]+)\s")

def get_api():
    return Fanfou(config['CLIENT_KEY'], client_secret=config['CLIENT_SECRET'],
                  token=config['ACCESS_TOKEN'],
                  token_secret=config['ACCESS_SECRET'],
                  proxies={"http": config['proxy'], "https": config['proxy']} if config['proxy'] else None)

def print_status(i, status):
    row = {}
    row[u'index'] = i
    row[u'created'] = datetime.strptime(status['created_at'], "%a %b %d %H:%M:%S +0000 %Y").strftime("%Y-%m-%d %H:%M:%S")
    row[u'id'] = status['id']
    row[u'screen_name'] = status['user']['screen_name']
    row[u'user_id'] = status['user']['id']
    row[u'text'] = status['text']
    row[u'photo'] = status['photo']['largeurl'] if status.get('photo') else ""
    print(u"[%(index)s]%(created)s(%(id)s)%(screen_name)s(%(user_id)s): %(text)s %(photo)s" % row)

def timeline(count=10, page=0):
    api = get_api()
    global tldata
    data = api.statuses.GET_home_timeline(count=count, page=page, mode='lite')
    del tldata[:]
    tldata.extend(data)
    for i, status in enumerate(data):
        print_status(i, status)

def mentions(count=10, page=0):
    api = get_api()
    global tldata
    data = api.statuses.GET_mentions(count=count, page=page, mode="lite")
    del tldata[:]
    tldata.extend(data)
    for i, status in enumerate(data):
        print_status(i, status)

def usertimeline(user_id, count=10, page=0):
    api = get_api()
    global tldata
    data = api.statuses.GET_user_timeline(id=user_id, count=count, page=page, mode='lite')
    del tldata[:]
    tldata.extend(data)
    for i, status in enumerate(data):
        print_status(i, status)

def showstatus(status_id):
    if isinstance(status_id, int):
        global tldata
        status_id = tldata[status_id]['id']
    api = get_api()
    data = api.statuses.GET_show(id=status_id, mode="lite")
    del tldata[:]
    tldata.append(data)
    print_status(0, data)

def destroy(status_id):
    if isinstance(status_id, int):
        global tldata
        status_id = tldata[status_id]['id']
    api = get_api()
    api.statuses.POST_destroy(id=status_id, mode="lite")

def post(status, photo="", in_reply_to_status_id=None, repost_status_id=None, in_reply_to_user_id=None):
    api = get_api()
    if photo:
        if not exists(photo):
            print("Photo file {} not found!".format(photo))
        else:
            api.photos.POST_upload(status=status, photo=open(photo, "rb"), mode="lite")
    else:
        api.statuses.POST_update(status=status,
                in_reply_to_status_id=in_reply_to_status_id,
                repost_status_id=repost_status_id,
                in_reply_to_user_id=in_reply_to_user_id,
                mode="lite")

def reply(status, index):
    global tldata
    in_reply_to = tldata[index]
    api = get_api()
    api.statuses.POST_update(status=u"@{} {}".format(in_reply_to['user']['screen_name'], status),
                             in_reply_to_status_id=in_reply_to['id'],
                             in_reply_to_user_id=in_reply_to['user']['id'])

def replyall(status, index):
    global tldata
    in_reply_to = tldata[index]
    users = pat_reply.findall(u"".join([in_reply_to['text'], " ")))
    reply_user = in_reply_to['user']'screen_name']
    users = list(set(users) - set([reply_user]))
    users.insert(0, reply_user)
    api = get_api()
    api.statuses.POST_update(status=u"@{} {}".format(" @".join(users), status),
                             in_reply_to_status_id=in_reply_to['id'],
                             in_reply_to_user_id=in_reply_to['user']['id'])

def repost(status, index):
    global tldata
    in_reply_to = tldata[index]
    api = get_api()
    api.statuses.POST_update(status=u"{} 转:@{} {}".format(status, in_reply_to['user']['screen_name'], in_reply_to['text']),
                             repost_status_id=in_reply_to['id'])

<|endoftext|>


<commit_before>import os
from setuptools import setup, find_packages

here = os.path.abspath(os.path.dirname(__file__))

with open(os.path.join(here, 'README.rst')) as f:
    README = f.read()

requires = [
    'barbecue',
    'boto',
    'chaussette',
    'cornice',
    'couchdb-schematics',
    'gevent',
    'iso8601',
    'jsonpatch',
    'pbkdf2',
    'pycrypto',
    'pyramid_exclog',
    'rfc6266',
    'setuptools',
    'tzlocal',
]
test_requires = requires + [
    'webtest',
    'python-coveralls',
]
docs_requires = requires + [
    'sphinxcontrib-httpdomain',
]

entry_points = {
    'paste.app_factory': [
        'main = openprocurement.api:main'
    ],
    'openprocurement.api.plugins': [
        'belowThreshold = openprocurement.api:includeme'
    ]
}

setup(name='openprocurement.api',
      version='0.11a2',
      description='openprocurement.api',
      long_description=README,
      classifiers=[
          "Framework :: Pylons",
          "License :: OSI Approved :: Apache Software License",
          "Programming Language :: Python",
          "Topic :: Internet :: WWW/HTTP",
          "Topic :: Internet :: WWW/HTTP :: WSGI :: Application"
      ],
      keywords="web services",
      author='Quintagroup, Ltd.',
      author_email='info@quintagroup.com',
      license='Apache License 2.0',
      url='https://github.com/openprocurement/openprocurement.api',
      package_dir={'': 'src'},
      py_modules=['cgi'],
      packages=find_packages('src'),
      namespace_packages=['openprocurement'],
      include_package_data=True,
      zip_safe=False,
      install_requires=requires,
      tests_require=test_requires,
      extras_require={'test': test_requires, 'docs': docs_requires},
      test_suite="openprocurement.api.tests.main.suite",
      entry_points=entry_points)
<commit_msg>Prepare release<commit_after>import os
from setuptools import setup, find_packages

here = os.path.abspath(os.path.dirname(__file__))

with open(os.path.join(here, 'README.rst')) as f:
    README = f.read()

requires = [
    'barbecue',
    'boto',
    'chaussette',
    'cornice',
    'couchdb-schematics',
    'gevent',
    'iso8601',
    'jsonpatch',
    'pbkdf2',
    'pycrypto',
    'pyramid_exclog',
    'rfc6266',
    'setuptools',
    'tzlocal',
]
test_requires = requires + [
    'webtest',
    'python-coveralls',
]
docs_requires = requires + [
    'sphinxcontrib-httpdomain',
]

entry_points = {
    'paste.app_factory': [
        'main = openprocurement.api:main'
    ],
    'openprocurement.api.plugins': [
        'belowThreshold = openprocurement.api:includeme'
    ]
}

setup(name='openprocurement.api',
      version='0.11',
      description='openprocurement.api',
      long_description=README,
      classifiers=[
          "Framework :: Pylons",
          "License :: OSI Approved :: Apache Software License",
          "Programming Language :: Python",
          "Topic :: Internet :: WWW/HTTP",
          "Topic :: Internet :: WWW/HTTP :: WSGI :: Application"
      ],
      keywords="web services",
      author='Quintagroup, Ltd.',
      author_email='info@quintagroup.com',
      license='Apache License 2.0',
      url='https://github.com/openprocurement/openprocurement.api',
      package_dir={'': 'src'},
      py_modules=['cgi'],
      packages=find_packages('src'),
      namespace_packages=['openprocurement'],
      include_package_data=True,
      zip_safe=False,
      install_requires=requires,
      tests_require=test_requires,
      extras_require={'test': test_requires, 'docs': docs_requires},
      test_suite="openprocurement.api.tests.main.suite",
      entry_points=entry_points)
<|endoftext|>


<commit_before>import re
from math import log
from string import ascii_lowercase
from heapq import nlargest

py_freq= {}
p2c = {}
py_short = {}
re_eng = re.compile('([a-zA-Z]+)')
MAX_FREQ = 260000
MAX_SEARCH_ENTRIES = 1000
MAX_SHOW_ENTRIES = 15

for line in open("freq.txt"):
    line = line.rstrip()
    py,freq = line.split(' ')
    freq = float(freq)
    if freq>MAX_FREQ: #cut the over-high frequency
        freq = MAX_FREQ
    py_freq[py] = py_freq.get(py,0)+freq

for line in open("p2c.txt"):
    line = line.decode('utf-8').rstrip()
    py,words = line.split(' ')
    p2c[py] = words.split(',')

for line in open("short.txt"):
    line = line.decode('utf-8').rstrip()
    py,words = line.split(' ')
    py_short[py] = words.split(',')

total = sum(py_freq.values())

py_freq = dict( (k,log(v/total)) for k,v in py_freq.iteritems())

min_freq = min(py_freq.values())
single_letters = set(ascii_lowercase)
print "data loaded."

def word_rank(word):
    if word in single_letters:
        return min_freq-1.0
    elif len(word)==1:
        return 0.0
    return py_freq.get(word,min_freq*20.0)

def dp_cut(sentence):
     max_word_len=20
     best_hop = {}
     N = len(sentence)
     best_hop[N] = [(0,N)]
     for i in xrange(N-1,-1,-1):
          best_hop[i] = nlargest(2,[ (word_rank(sentence[i:hop]) + best_hop[hop][0][0],hop) for hop in xrange(i+1,min(i+max_word_len+1,N+1)) ])
     start  = 0
     top1 = []
     while start<N:
          top1.append(sentence[start:best_hop[start][0][1]])
          start = best_hop[start][0][1]
     top2 = []
     start = 0
     while start<N:
        if start==0 and len(best_hop[start])>1:
            top2.append(sentence[start:best_hop[start][1][1]])
            start = best_hop[start][1][1]
        else:
            top2.append(sentence[start:best_hop[start][0][1]])
            start = best_hop[start][0][1]
     return [top1,top2]

def all_combine_idx(m,idx,tb):
    if idx==len(m)-1:
        for i in xrange(0,len(m[idx])):
            if tb['n']>MAX_SEARCH_ENTRIES:
                return
            yield [i]
            tb['n']=tb.get('n',0)+1
    else:
        for w in xrange(0,len(m[idx])):
            if tb['n']>MAX_SEARCH_ENTRIES:
                    return
            for sub in all_combine_idx(m,idx+1,tb):
                if tb['n']>MAX_SEARCH_ENTRIES:
                    return
                yield [w]+sub

def all_combine(m,idx):
    tb = {'n':0}
    all_index_list = sorted(all_combine_idx(m,idx,tb),key=lambda x: sum(x))
    if len(m)>1:
        all_index_list = all_index_list[:MAX_SHOW_ENTRIES]
    for column in all_index_list:
        yield "".join(m[i][column[i]] for i in xrange(len(m)))

def pyshort_filter(mixed,ct):
    mixed = mixed.replace("'","")
    m = []
    for chunk in re_eng.split(mixed):
        if not (chunk in py_short):
            m.append([chunk])
        else:
            m.append(py_short[chunk][:ct])
    for c in all_combine(m,0):
        yield c

def guess_words(sentence):
    if len(sentence)>0:
        bucket = {}
        for py_list in dp_cut(sentence):
            m=[]
            for p in py_list:
                if len(p)<6:
                    if len(py_list)==1: #single character, show all candidates
                        span = -1
                    else:
                        span = 6
                else:
                    span = 3
                m.append( p2c.get(p,[p])[:span] )
            for c in all_combine(m,0):
                for cc in pyshort_filter(c, 6):
                    if not cc in bucket:
                        yield cc
                        bucket[cc]=1
        del bucket

if __name__ == "__main__":
    while True:
        py_sentence = raw_input("")
        print ",  ".join( guess_words(py_sentence))

<commit_msg>fix a bug of the amount of showed entries<commit_after>import re
from math import log
from string import ascii_lowercase
from heapq import nlargest

py_freq= {}
p2c = {}
py_short = {}
re_eng = re.compile('([a-zA-Z]+)')
MAX_FREQ = 260000
MAX_SEARCH_ENTRIES = 1000
MAX_SHOW_ENTRIES = 15

for line in open("freq.txt"):
    line = line.rstrip()
    py,freq = line.split(' ')
    freq = float(freq)
    if freq>MAX_FREQ: #cut the over-high frequency
        freq = MAX_FREQ
    py_freq[py] = py_freq.get(py,0)+freq

for line in open("p2c.txt"):
    line = line.decode('utf-8').rstrip()
    py,words = line.split(' ')
    p2c[py] = words.split(',')

for line in open("short.txt"):
    line = line.decode('utf-8').rstrip()
    py,words = line.split(' ')
    py_short[py] = words.split(',')

total = sum(py_freq.values())

py_freq = dict( (k,log(v/total)) for k,v in py_freq.iteritems())

min_freq = min(py_freq.values())
single_letters = set(ascii_lowercase)
print "data loaded."

def word_rank(word):
    if word in single_letters:
        return min_freq-1.0
    elif len(word)==1:
        return 0.0
    return py_freq.get(word,min_freq*20.0)

def dp_cut(sentence):
     max_word_len=20
     best_hop = {}
     N = len(sentence)
     best_hop[N] = [(0,N)]
     for i in xrange(N-1,-1,-1):
          best_hop[i] = nlargest(2,[ (word_rank(sentence[i:hop]) + best_hop[hop][0][0],hop) for hop in xrange(i+1,min(i+max_word_len+1,N+1)) ])
     start  = 0
     top1 = []
     while start<N:
          top1.append(sentence[start:best_hop[start][0][1]])
          start = best_hop[start][0][1]
     top2 = []
     start = 0
     while start<N:
        if start==0 and len(best_hop[start])>1:
            top2.append(sentence[start:best_hop[start][1][1]])
            start = best_hop[start][1][1]
        else:
            top2.append(sentence[start:best_hop[start][0][1]])
            start = best_hop[start][0][1]
     return [top1,top2]

def all_combine_idx(m,idx,tb):
    if idx==len(m)-1:
        for i in xrange(0,len(m[idx])):
            if tb['n']>MAX_SEARCH_ENTRIES:
                return
            yield [i]
            tb['n']=tb.get('n',0)+1
    else:
        for w in xrange(0,len(m[idx])):
            if tb['n']>MAX_SEARCH_ENTRIES:
                    return
            for sub in all_combine_idx(m,idx+1,tb):
                if tb['n']>MAX_SEARCH_ENTRIES:
                    return
                yield [w]+sub

def all_combine(m,idx):
    tb = {'n':0}
    all_index_list = sorted(all_combine_idx(m,idx,tb),key=lambda x: sum(x))
    if len(m)>1:
        all_index_list = all_index_list[:MAX_SHOW_ENTRIES]
    for column in all_index_list:
        yield "".join(m[i][column[i]] for i in xrange(len(m)))

def pyshort_filter(mixed,ct):
    mixed = mixed.replace("'","")
    m = []
    for chunk in re_eng.split(mixed):
        if not (chunk in py_short):
            m.append([chunk])
        else:
            m.append(py_short[chunk][:ct])
    for c in all_combine(m,0):
        yield c

def guess_words(sentence):
    if len(sentence)>0:
        bucket = {}
        showed = 0
        for py_list in dp_cut(sentence):
            if showed>=MAX_SHOW_ENTRIES:
                break
            m=[]
            for p in py_list:
                if len(p)<6:
                    if len(py_list)==1: #single character, show all candidates
                        span = -1
                    else:
                        span = 6
                else:
                    span = 3
                m.append( p2c.get(p,[p])[:span] )
            for c in all_combine(m,0):
                if showed>=MAX_SHOW_ENTRIES:
                    break
                for cc in pyshort_filter(c, 6):
                    if not cc in bucket:
                        yield cc
                        bucket[cc]=1
                        showed+=1
                        if showed>=MAX_SHOW_ENTRIES:
                            break
        del bucket

if __name__ == "__main__":
    while True:
        py_sentence = raw_input("")
        print ",  ".join( guess_words(py_sentence))

<|endoftext|>


<commit_before>from setuptools import setup

try:
    import enum  # noqa
    extra_requires = []
except ImportError:
    extra_requires = ['enum34']

REQUIRES = ['marshmallow>=2.0.0'] + extra_requires

with open('README.md', 'r') as f:
    readme = f.read()

with open('CHANGELOG', 'r') as f:
    changelog = f.read()

if __name__ == '__main__':
    setup(
        name='marshmallow-enum',
        version='1.4.1',
        author='Alec Nikolas Reiter',
        author_email='alecreiter@gmail.com',
        description='Enum field for Marshmallow',
        long_description=readme + '\n\n' + changelog,
        package_data={'': ['LICENSE', 'README.md', 'CHANGELOG']},
        include_package_data=True,
        license='MIT',
        packages=['marshmallow_enum'],
        install_requires=REQUIRES,
    )
<commit_msg>Prepare 1.5 release<commit_after>from setuptools import setup

try:
    import enum  # noqa
    extra_requires = []
except ImportError:
    extra_requires = ['enum34']

REQUIRES = ['marshmallow>=2.0.0'] + extra_requires

with open('README.md', 'r') as f:
    readme = f.read()

with open('CHANGELOG', 'r') as f:
    changelog = f.read()

if __name__ == '__main__':
    setup(
        name='marshmallow-enum',
        version='1.5.0',
        author='Alec Nikolas Reiter',
        author_email='alecreiter@gmail.com',
        description='Enum field for Marshmallow',
        long_description=readme + '\n\n' + changelog,
        package_data={'': ['LICENSE', 'README.md', 'CHANGELOG']},
        include_package_data=True,
        license='MIT',
        packages=['marshmallow_enum'],
        install_requires=REQUIRES,
    )
<|endoftext|>


<commit_before>#! /usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import setup, find_packages

setup(
    name = 'OpenFisca-France',
    version = '20.0.2',
    author = 'OpenFisca Team',
    author_email = 'contact@openfisca.fr',
    classifiers = [
        "Development Status :: 2 - Pre-Alpha",
        "License :: OSI Approved :: GNU Affero General Public License v3",
        "Operating System :: POSIX",
        "Programming Language :: Python",
        "Topic :: Scientific/Engineering :: Information Analysis",
        ],
    description = u'French tax and benefit system for OpenFisca',
    keywords = 'benefit france microsimulation social tax',
    license = 'http://www.fsf.org/licensing/licenses/agpl-3.0.html',
    url = 'https://github.com/openfisca/openfisca-france',

    data_files = [
        ('share/openfisca/openfisca-france', ['CHANGELOG.md', 'LICENSE.AGPL.txt', 'README.md']),
        ],
    extras_require = {
        'api': [
            'OpenFisca-Web-API >= 8.0, < 9.0',
            ],
        'baremes_ipp': [
            'xlrd >= 1.0.0',
            'lxml >= 3.8.0, < 4.0',
            'Biryani[datetimeconv] >= 0.10.4',
            ],
        'inversion_revenus': [
            'scipy >= 0.17',
            ],
        'de_net_a_brut': [
            'scipy >= 0.17',
            ],
        'taxipp': [
            'pandas >= 0.13',
            ],
        'test': [
            'nose',
            'flake8 == 3.4.1',
            'scipy >= 0.17', # Only used to test de_net_a_brut reform
            ],
        },
    include_package_data = True,  # Will read MANIFEST.in
    install_requires = [
        'numpy >= 1.11, < 1.13',
        'OpenFisca-Core >= 21.0.2, < 21.2',
        'PyYAML >= 3.10',
        'requests >= 2.8',
        ],
    message_extractors = {'openfisca_france': [
        ('**.py', 'python', None),
        ]},
    packages = find_packages(exclude=['openfisca_france.tests*']),
    test_suite = 'nose.collector',
    )
<commit_msg>Upgrade core<commit_after>#! /usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import setup, find_packages

setup(
    name = 'OpenFisca-France',
    version = '20.0.2',
    author = 'OpenFisca Team',
    author_email = 'contact@openfisca.fr',
    classifiers = [
        "Development Status :: 2 - Pre-Alpha",
        "License :: OSI Approved :: GNU Affero General Public License v3",
        "Operating System :: POSIX",
        "Programming Language :: Python",
        "Topic :: Scientific/Engineering :: Information Analysis",
        ],
    description = u'French tax and benefit system for OpenFisca',
    keywords = 'benefit france microsimulation social tax',
    license = 'http://www.fsf.org/licensing/licenses/agpl-3.0.html',
    url = 'https://github.com/openfisca/openfisca-france',

    data_files = [
        ('share/openfisca/openfisca-france', ['CHANGELOG.md', 'LICENSE.AGPL.txt', 'README.md']),
        ],
    extras_require = {
        'api': [
            'OpenFisca-Web-API >= 8.0, < 9.0',
            ],
        'baremes_ipp': [
            'xlrd >= 1.0.0',
            'lxml >= 3.8.0, < 4.0',
            'Biryani[datetimeconv] >= 0.10.4',
            ],
        'inversion_revenus': [
            'scipy >= 0.17',
            ],
        'de_net_a_brut': [
            'scipy >= 0.17',
            ],
        'taxipp': [
            'pandas >= 0.13',
            ],
        'test': [
            'nose',
            'flake8 == 3.4.1',
            'scipy >= 0.17', # Only used to test de_net_a_brut reform
            ],
        },
    include_package_data = True,  # Will read MANIFEST.in
    install_requires = [
        'numpy >= 1.11, < 1.13',
        'OpenFisca-Core >= 21.2.1, < 22',
        'PyYAML >= 3.10',
        'requests >= 2.8',
        ],
    message_extractors = {'openfisca_france': [
        ('**.py', 'python', None),
        ]},
    packages = find_packages(exclude=['openfisca_france.tests*']),
    test_suite = 'nose.collector',
    )
<|endoftext|>


<commit_before>#!/usr/bin/env python

#Code by Abinash Sahu

import time
import Queue
import threading
import re
import mechanize
import os
import sys
import webbrowser
import urllib2
import pickle

nodes_to_visit=Queue.Queue()
visited_nodes=[]
max_num_threads=6
node_dict={} #Contains ip-name mapping of nodes in network with ip as key
full_list=[] #Contains list of all links

def check_or_make(folder_path):
    """Check if provided folder exists at the specified location
    otherwise create it there.
    """

    curr_directory=os.getcwd()
    for folder in folder_path.split(os.sep):
        if os.path.isdir(folder):
            os.chdir(folder)
        else:
            os.mkdir(folder)
            os.chdir(folder)
    os.chdir(curr_directory)
    return

class NE:
    def __init__(self, ip):
        self.ip=ip
        self.neighbours=[]
        self.laser_ports={}

        self.baseurl='http://%s:20080/' % (self.ip)

        try:
            br=mechanize.Browser()                                  #Create nechanize browser object
            br.add_password(self.baseurl, username, passw)		    #Get user id and password from command line arguements
            page=br.open(self.baseurl, timeout=10.0).read()		    #Check if NE is accessible
            if 'alarmBanner' in page:
                print "Logged in to %s" % (self.baseurl)

            self.get_laser_data(br)									#Read laser data of STM ports
            if(self.add_neighbours(br)):
                self.backup(br)										#Backup cross-connect info
        except:
            print "\tError reading "+ip
        br.close()
        return(None)

    def add_neighbours(self, br):
        """Goes through the list of IPs  listed as neighbours (please
        keep auto-discover switched ON) and copies their state, IP & STM
        port number.
        """

        #Regex patterns
        name_pattern=r'\-(\S+.*?)\('
        row_pattern=r'Trunk.*[\n]+.*?<SEL'
        ip_status_pattern=r' 	([\S]+).*?	.*?\d+(?:[\d\.]+){3}.*?(\d+(?:[\d\.]+){3}).*?	'
        stm_pattern=r'(\d+\-\d+\-\d+\s)	'

        nbr_ne_status=br.open(self.baseurl+'EMSRequest/ViewTrunk', timeout=10.0).read().rstrip()
        try:
            self.name=re.findall(name_pattern, nbr_ne_status)[0]
            self.name=re.sub('[^\s!-~]', ' ', self.name)

        except:
            print("\tError getting name for %s"%(self.baseurl))
            return()

        node_dict[self.ip]=self.name
        for srch in re.findall(row_pattern,nbr_ne_status):
            match=re.search(ip_status_pattern, srch)
            if match:
                status=str(match.group(1))
                ip=match.group(2)
                stm=str(re.search(stm_pattern, srch).group(1)).strip()
                try:
                    full_list.append([self.ip,ip,status, self.laser_ports[stm]])
                    #print self.laser_ports[stm]
                    self.neighbours.append([ip,status.upper(), self.laser_ports[stm]])
                except:
                    return()
                    #print self.laser_ports, ip, status.upper(), stm
        return(self.name)

    def tell(self):
        """For debugging only """
        return(self.name, self.neighbours)

    def backup(self, br):
        """Saves the node's cross-connects in another HTML file. Will replace
        the last recorded cross-connect saved on the current day. That is to
        say running first time on Wednesday will NOT overwrite Tuesday's data
        but running another time on Wednesday WILL overwrite the first
        cross-connect backup of Wednesday.
        """

        try:
            configs=br.open(self.baseurl+'EMSRequest/ViewConnections', timeout=10.0).read()
            start_copy=configs.find('
Cross')
            configs=configs[start_copy:-1]
            time_backup=str(time.strftime("%H:%M:%S  %d/%m/%y")+":\n\n")
            backup_head="\n<TITLE> Cross-connect backup of "+self.name+" taken on "+time_backup+"</TITLE>\n"
            backup_table_line='
'
            backup_body="Cross-connect backup of "+self.name+" taken on "+time_backup+""
            backup_folder="logs"+os.sep+"backup"+os.sep+time.ctime()[0:3]
            check_or_make(backup_folder)
            filename=str(os.getcwd()+os.sep+backup_folder+os.sep+str(self.name)+".html")
            with open (filename, 'w') as bkpconfig:
                bkpconfig.write(backup_head+backup_body+backup_table_line+configs)
            print("Config file for "+str(self.name)+" written to disk.")
        except:
            print("Error getting config info for "+str(self.ip))
        return()

    def get_laser_data(self, br):
        """Reads the received laser power from different STM ports and
        records them against the ports.
        """

        laser_pattern=r'STM\d+\-(\d.*?)	.*?([\-\d].*?)	'

        try:
            laser_stat_page=br.open(self.baseurl+'EMSRequest/Laser?Submit=View', timeout=10.0).read()

            for srch in re.findall(laser_pattern, laser_stat_page):
                stm=str(srch[0]).strip()
                laser_power=str(srch[1]).strip()
                self.laser_ports[stm]=laser_power
        except:
            print "Error reading laser data for "+self.baseurl
            return(None)
        return()

    def check_online(self, url):
        #For future use :P
        try:
            code=urllib2.urlopen(url, timeout=2).getcode()
        except urllib2.HTTPError as e:
            code=e.code
        except urllib2.URLError:
            code=0
        if code==401 or code==200:
            return True

        return False

def get_node(node_queue, prev_node):
    """Gets a node from the Queue to process and spawn new threads
    if required."""

    th_count=1

    current_node=node_queue.get()
    #ret_str="Getting data for "+(str(current_node))+" came from "+str(prev_node)
    #print(ret_str)
    if not (current_node in visited_nodes):
        visited_nodes.append(current_node)
        node=NE(current_node)
        if(node.neighbours):
            for neighbour in node.neighbours:
                if not(neighbour[0] in visited_nodes):
                    node_queue.put(neighbour[0])
                    th_count+=1
        for i in range(th_count):
            th=threading.Thread(target=get_node, args=(node_queue,current_node, ))
            th.setDaemon(True)
            th.start()
    node_queue.task_done()
    #print('Task Done')
    #exit()
    return()

def make_legend(filename):
    """Uses the IP Cache file to store/retrieve IP <> Name mappings. If
    the cache file exists opens it and updates else creates with the
    available data."""

    wrk_dir=os.path.split(filename)
    if os.path.isfile(wrk_dir[0]+os.sep+'ipcache.tmp'):
        ip_file=open(wrk_dir[0]+os.sep+'ipcache.tmp', 'r')
        ip_dict=pickle.load(ip_file)
        ip_file.close()
        for element in node_dict.keys():
            if not(element in ip_dict.keys()):
                ip_dict[element]=node_dict[element]
    else:
        ip_dict=node_dict
    ip_file=open(wrk_dir[0]+os.sep+'ipcache.tmp', 'w')
    pickle.dump(ip_dict, ip_file)
    ip_file.close()
    return(ip_dict)

def make_html(ne_list, filename, start_time):
    """Save the report as a HTML file"""

    #Keep list of inaccessible nodes
    na_nodes=[]

    #ne_list contains link status of all nodes
    for item in ne_list:
        #Use node names if available else use IP
        try:
            item[0]=node_dict[item[0]]  #Source
            item[1]=node_dict[item[1]]  #Destination
        except:
            pass

    #Prepare the HTML file
    with open(filename, 'w') as htmlfile:
        file_time=str(time.strftime("%H:%M:%S  %d/%m/%y"))
        htmlfile.write('\n\n\t<TITLE>Route Status on '+file_time+'</TITLE>')
        cssStyles='''\n\n
                        '''
        htmlfile.write(cssStyles)
        htmlfile.write("\n\n\nThe status as on "+file_time+":\n\n

\n")
        htmlfile.write("
\n
\t\n
\n\tDESTINATION	\n\tSOURCE	\n\tSTATUS	\n\tPOWER LEVEL (dBm)	\n\t
\n
\n
\n")
        for row in ne_list:

            if 'Down' in str(row[2]):
                status_color='RED>'
            else:
                status_color='GREEN>'

            if float(str(row[3]))<-34.99:
                power_color='RED>'
            elif float(str(row[3]))>-34.99 and float(str(row[3]))<-30.0:
                power_color='ORANGE>'
            else:
                power_color='BLUE>'

            #Row[0] = DEST, Row[1] = SOURCE, Row[2] = STATUS & Row[3] = power
            #If received power is -99 and only IP address in source name
            #put node in not reachable list

            if row[2]==-99 and re.match(r'[\d]+.[\d]+.', row[1]):
                na_nodes.append(str(row[1]))

            htmlfile.write('
\n\t'+str(row[0])+'	\n\t'+str(row[1])+
                           '	\n\t<FONT COLOR='+status_color+str(row[2])+
                           '	\n\t<FONT COLOR='+power_color+str(row[3])+"	\n
\n")
        htmlfile.write("\n
\n
\n
")

        #Make legend section
        ip_dict=make_legend(filename)
        htmlfile.write('
\n'*2)
        legend_col=3
        htmlfile.write('\nIP to Name (from memory):
\n')
        htmlfile.write('

\n'+'\n\tIP ADD	\n\tNE NAME	'*legend_col+'\n
')
        fmt_count=0
        htmlfile.write('\n
')
        for ip_add in sorted(ip_dict.keys()):
            if fmt_count%legend_col==legend_col-1:
                fmt_cntr=1
                fmt_count=0
            else:
                fmt_cntr=0
                fmt_count+=1

            if str(ip_add) in na_nodes:
                legend_ip_fmt='notavailable">'
            else:
                legend_ip_fmt='available">'

            htmlfile.write('\n\t<TD CLASS="'+legend_ip_fmt+str(ip_add)+'	\n\t'+str(ip_dict[ip_add])+'	'+'\n
\n
'*fmt_cntr)

        htmlfile.write('\n
\n

\n\n')

        htmlfile.write("\n
 Visited "+str(len(node_dict.keys()))+" nodes in "+(str(time.time()-start_time))+" seconds.")
        htmlfile.write('\n\n')
        htmlfile.write('\n

Script sourced from The Pyjas project')
        htmlfile.write('\n\n')

    #Display the report in the default browser
    webbrowser.open_new_tab(filename)
    return()

if __name__=='__main__':
    global username, passw

    #Create the 'logs' folder if it doesn't exist
    check_or_make("logs")

    #This is the file name we are going to store the report with
    filename=str(os.getcwd()+os.sep+'logs'+os.sep+str(time.strftime("%d%m%y%H%M%S"))+".html")

    #Just for the stats
    start_time=time.time()

    #Check if all necessary parameters have been provided
    if len(sys.argv)>3:
        start_ip=str(sys.argv[1])
        username=str(sys.argv[2])
        passw=str(sys.argv[3])
    else:
        print('Missing/invalid parameters. Exiting.')
        raw_input()
        sys.exit()

    #Initialize the queue
    nodes_to_visit.put(start_ip)

    #create_threads(max_num_threads, nodes_to_visit)
    get_node(nodes_to_visit, 'START')

    #wait till all threads finished working
    nodes_to_visit.join()

    if len(full_list)>1:
        print("Writing to file...")
        make_html(full_list, filename, start_time)
        print("Log recorded to "+filename+".")
    else:
        print("ERROR : Check LAN connection/settings")
    print("Press ENTER to close this window")

    raw_input()
    exit()
<commit_msg>Fix bugs in last commit, change colours & add link fail highlighting<commit_after>#!/usr/bin/env python

#Code by Abinash Sahu

import time
import Queue
import threading
import re
import mechanize
import os
import sys
import webbrowser
import urllib2
import pickle

nodes_to_visit=Queue.Queue()
visited_nodes=[]
max_num_threads=6
node_dict={} #Contains ip-name mapping of nodes in network with ip as key
full_list=[] #Contains list of all links

def check_or_make(folder_path):
    """Check if provided folder exists at the specified location
    otherwise create it there.
    """

    curr_directory=os.getcwd()
    for folder in folder_path.split(os.sep):
        if os.path.isdir(folder):
            os.chdir(folder)
        else:
            os.mkdir(folder)
            os.chdir(folder)
    os.chdir(curr_directory)
    return

class NE:
    def __init__(self, ip):
        self.ip=ip
        self.neighbours=[]
        self.laser_ports={}

        self.baseurl='http://%s:20080/' % (self.ip)

        try:
            br=mechanize.Browser()                                  #Create nechanize browser object
            br.add_password(self.baseurl, username, passw)		    #Get user id and password from command line arguements
            page=br.open(self.baseurl, timeout=10.0).read()		    #Check if NE is accessible
            if 'alarmBanner' in page:
                print "Logged in to %s" % (self.baseurl)

            self.get_laser_data(br)									#Read laser data of STM ports
            if(self.add_neighbours(br)):
                self.backup(br)										#Backup cross-connect info
        except:
            print "\tError reading "+ip
        br.close()
        return(None)

    def add_neighbours(self, br):
        """Goes through the list of IPs  listed as neighbours (please
        keep auto-discover switched ON) and copies their state, IP & STM
        port number.
        """

        #Regex patterns
        name_pattern=r'\-(\S+.*?)\('
        row_pattern=r'Trunk.*[\n]+.*?<SEL'
        ip_status_pattern=r' 	([\S]+).*?	.*?\d+(?:[\d\.]+){3}.*?(\d+(?:[\d\.]+){3}).*?	'
        stm_pattern=r'(\d+\-\d+\-\d+\s)	'

        nbr_ne_status=br.open(self.baseurl+'EMSRequest/ViewTrunk', timeout=10.0).read().rstrip()
        try:
            self.name=re.findall(name_pattern, nbr_ne_status)[0]
            self.name=re.sub('[^\s!-~]', ' ', self.name)

        except:
            print("\tError getting name for %s"%(self.baseurl))
            return()

        node_dict[self.ip]=self.name
        for srch in re.findall(row_pattern,nbr_ne_status):
            match=re.search(ip_status_pattern, srch)
            if match:
                status=str(match.group(1))
                ip=match.group(2)
                stm=str(re.search(stm_pattern, srch).group(1)).strip()
                try:
                    full_list.append([self.ip,ip,status, self.laser_ports[stm]])
                    #print self.laser_ports[stm]
                    self.neighbours.append([ip,status.upper(), self.laser_ports[stm]])
                except:
                    return()
                    #print self.laser_ports, ip, status.upper(), stm
        return(self.name)

    def tell(self):
        """For debugging only """
        return(self.name, self.neighbours)

    def backup(self, br):
        """Saves the node's cross-connects in another HTML file. Will replace
        the last recorded cross-connect saved on the current day. That is to
        say running first time on Wednesday will NOT overwrite Tuesday's data
        but running another time on Wednesday WILL overwrite the first
        cross-connect backup of Wednesday.
        """

        try:
            configs=br.open(self.baseurl+'EMSRequest/ViewConnections', timeout=10.0).read()
            start_copy=configs.find('
Cross')
            configs=configs[start_copy:-1]
            time_backup=str(time.strftime("%H:%M:%S  %d/%m/%y")+":\n\n")
            backup_head="\n<TITLE> Cross-connect backup of "+self.name+" taken on "+time_backup+"</TITLE>\n"
            backup_table_line='
'
            backup_body="Cross-connect backup of "+self.name+" taken on "+time_backup+""
            backup_folder="logs"+os.sep+"backup"+os.sep+time.ctime()[0:3]
            check_or_make(backup_folder)
            filename=str(os.getcwd()+os.sep+backup_folder+os.sep+str(self.name)+".html")
            with open (filename, 'w') as bkpconfig:
                bkpconfig.write(backup_head+backup_body+backup_table_line+configs)
            print("Config file for "+str(self.name)+" written to disk.")
        except:
            print("Error getting config info for "+str(self.ip))
        return()

    def get_laser_data(self, br):
        """Reads the received laser power from different STM ports and
        records them against the ports.
        """

        laser_pattern=r'STM\d+\-(\d.*?)	.*?([\-\d].*?)	'

        try:
            laser_stat_page=br.open(self.baseurl+'EMSRequest/Laser?Submit=View', timeout=10.0).read()

            for srch in re.findall(laser_pattern, laser_stat_page):
                stm=str(srch[0]).strip()
                laser_power=str(srch[1]).strip()
                self.laser_ports[stm]=laser_power
        except:
            print "Error reading laser data for "+self.baseurl
            return(None)
        return()

    def check_online(self, url):
        #For future use :P
        try:
            code=urllib2.urlopen(url, timeout=2).getcode()
        except urllib2.HTTPError as e:
            code=e.code
        except urllib2.URLError:
            code=0
        if code==401 or code==200:
            return True

        return False

def get_node(node_queue, prev_node):
    """Gets a node from the Queue to process and spawn new threads
    if required."""

    th_count=1

    current_node=node_queue.get()
    #ret_str="Getting data for "+(str(current_node))+" came from "+str(prev_node)
    #print(ret_str)
    if not (current_node in visited_nodes):
        visited_nodes.append(current_node)
        node=NE(current_node)
        if(node.neighbours):
            for neighbour in node.neighbours:
                if not(neighbour[0] in visited_nodes):
                    node_queue.put(neighbour[0])
                    th_count+=1
        for i in range(th_count):
            th=threading.Thread(target=get_node, args=(node_queue,current_node, ))
            th.setDaemon(True)
            th.start()
    node_queue.task_done()
    #print('Task Done')
    #exit()
    return()

def make_legend(filename):
    """Uses the IP Cache file to store/retrieve IP <> Name mappings. If
    the cache file exists opens it and updates else creates with the
    available data."""

    wrk_dir=os.path.split(filename)
    if os.path.isfile(wrk_dir[0]+os.sep+'ipcache.tmp'):
        ip_file=open(wrk_dir[0]+os.sep+'ipcache.tmp', 'r')
        ip_dict=pickle.load(ip_file)
        ip_file.close()
        for element in node_dict.keys():
            if not(element in ip_dict.keys()):
                ip_dict[element]=node_dict[element]
    else:
        ip_dict=node_dict
    ip_file=open(wrk_dir[0]+os.sep+'ipcache.tmp', 'w')
    pickle.dump(ip_dict, ip_file)
    ip_file.close()
    return(ip_dict)

def make_html(ne_list, filename, start_time):
    """Save the report as a HTML file"""

    #Keep list of inaccessible nodes
    na_nodes=[]

    #ne_list contains link status of all nodes
    for item in ne_list:
        #Use node names if available else use IP
        try:
            item[0]=node_dict[item[0]]  #Source
            item[1]=node_dict[item[1]]  #Destination
        except:
            pass

    #Prepare the HTML file
    with open(filename, 'w') as htmlfile:
        file_time=str(time.strftime("%H:%M:%S  %d/%m/%y"))
        htmlfile.write('\n\n\t<TITLE>Route Status on '+file_time+'</TITLE>')
        cssStyles='''\n\n
                        '''
        htmlfile.write(cssStyles)
        htmlfile.write("\n\n\nThe status as on "+file_time+":\n\n

\n")
        htmlfile.write("
\n
\t\n
\n\tDESTINATION	\n\tSOURCE	\n\tSTATUS	\n\tPOWER LEVEL (dBm)	\n\t
\n
\n
\n")
        for row in ne_list:

            #Status formatting
            if 'Down' in str(row[2]):
                status_format='statusDown">'
            else:
                status_format='statusUp">'

            #Power formatting
            if float(str(row[3]))<-34.99:
                power_format='powerDown">'
            elif float(str(row[3]))>-34.99 and float(str(row[3]))<-30.0:
                power_format='powerRisky">'
            else:
                power_format='powerNormal">'

            #Row[0] = DEST, Row[1] = SOURCE, Row[2] = STATUS & Row[3] = power
            #If received power is -99 and only IP address in source name
            #put node in not reachable list & highlight row

            if float(str(row[3]))==-99 and re.match(r'[\d]+.[\d]+.', row[1]):
                na_nodes.append(str(row[1]))
                status_format='nodeDown">'
                power_format='nodeDown">'

            #Node is reachable but link is down - highlight row
            if float(str(row[3]))==-99 and 'Down' in str(row[2]):
                status_format='nodeDown">'
                power_format='nodeDown">'

            htmlfile.write('
\n\t'+str(row[0])+'	\n\t'+str(row[1])+
                           '	\n\t<TD CLASS="'+status_format+str(row[2])+
                           '	\n\t<TD CLASS="'+power_format+str(row[3])+'	\n
\n')
        htmlfile.write("\n
\n
\n
")

        #Make legend section
        ip_dict=make_legend(filename)
        htmlfile.write('
\n'*2)
        legend_col=3
        htmlfile.write('\nIP to Name (from memory):
\n')
        htmlfile.write('

\n'+'\n\tIP ADD	\n\tNE NAME	'*legend_col+'\n
')
        fmt_count=0
        htmlfile.write('\n
')
        for ip_add in sorted(ip_dict.keys()):
            if fmt_count%legend_col==legend_col-1:
                fmt_cntr=1
                fmt_count=0
            else:
                fmt_cntr=0
                fmt_count+=1

            if str(ip_add) in na_nodes:
                legend_ip_fmt='notavailable">'
            else:
                legend_ip_fmt='available">'

            htmlfile.write('\n\t<TD CLASS="'+legend_ip_fmt+str(ip_add)+'	\n\t'+str(ip_dict[ip_add])+'	'+'\n
\n
'*fmt_cntr)

        htmlfile.write('\n
\n

\n\n')

        htmlfile.write("\n
 Visited "+str(len(node_dict.keys()))+" nodes in "+(str(time.time()-start_time))+" seconds.")
        htmlfile.write('\n\n')
        htmlfile.write('\n

Script sourced from The Pyjas project')
        htmlfile.write('\n\n')

    #Display the report in the default browser
    webbrowser.open_new_tab(filename)
    return()

if __name__=='__main__':
    global username, passw

    #Create the 'logs' folder if it doesn't exist
    check_or_make("logs")

    #This is the file name we are going to store the report with
    filename=str(os.getcwd()+os.sep+'logs'+os.sep+str(time.strftime("%d%m%y%H%M%S"))+".html")

    #Just for the stats
    start_time=time.time()

    #Check if all necessary parameters have been provided
    if len(sys.argv)>3:
        start_ip=str(sys.argv[1])
        username=str(sys.argv[2])
        passw=str(sys.argv[3])
    else:
        print('Missing/invalid parameters. Exiting.')
        raw_input()
        sys.exit()

    #Initialize the queue
    nodes_to_visit.put(start_ip)

    #create_threads(max_num_threads, nodes_to_visit)
    get_node(nodes_to_visit, 'START')

    #wait till all threads finished working
    nodes_to_visit.join()

    if len(full_list)>1:
        print("Writing to file...")
        make_html(full_list, filename, start_time)
        print("Log recorded to "+filename+".")
    else:
        print("ERROR : Check LAN connection/settings")
    print("Press ENTER to close this window")

    raw_input()
    exit()
<|endoftext|>


<commit_before>from setuptools import setup, find_packages
from codecs import open
from os import path

here = path.abspath(path.dirname(__file__))

with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
    long_description = f.read()

version = '0.1.6'

setup(
    name='wetransferpy',
    version=version,
    description='WeTransfer command line utility.',
    long_description=long_description,
    author='Sylvain Maziere, Paul Delannoy',
    author_email='sylvain@predat.fr, paul@highwaytv.com',
    license='MIT',
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Intended Audience :: Developers',
        'Topic :: Software Development :: Build Tools',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 2.7',
    ],
    keywords="wetransfer upload download authenticate",
    url='http://github.com/predat/wetransferpy',
    download_url='https://github.com/predat/wetransferpy/tarball/' + version,
    packages=find_packages(exclude=['contrib', 'docs', 'tests']),
    install_requires=[
        "requests",
        "requests_toolbelt",
	"lxml"
    ],
    scripts=['bin/wetransfer-upload','bin/wetransfer-download']
)
<commit_msg>Bump version<commit_after>from setuptools import setup, find_packages
from codecs import open
from os import path

here = path.abspath(path.dirname(__file__))

with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
    long_description = f.read()

version = '0.2'

setup(
    name='wetransferpy',
    version=version,
    description='WeTransfer command line utility.',
    long_description=long_description,
    author='Sylvain Maziere, Paul Delannoy',
    author_email='sylvain@predat.fr, paul@highwaytv.com',
    license='MIT',
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Intended Audience :: Developers',
        'Topic :: Software Development :: Build Tools',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 2.7',
    ],
    keywords="wetransfer upload download authenticate",
    url='http://github.com/predat/wetransferpy',
    download_url='https://github.com/predat/wetransferpy/tarball/' + version,
    packages=find_packages(exclude=['contrib', 'docs', 'tests']),
    install_requires=[
        "requests",
        "requests_toolbelt",
	"lxml"
    ],
    scripts=['bin/wetransfer-upload','bin/wetransfer-download']
)
<|endoftext|>