<commit_before>from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from distutils.spawn import find_executable
from distutils import sysconfig
import pkg_resources
import setuptools
import setuptools.command.build_py
import setuptools.command.develop
import setuptools.command.build_ext

import platform
import fnmatch
from collections import namedtuple
import os
import subprocess
import sys
import tempfile
from textwrap import dedent

TOP_DIR = os.path.realpath(os.path.dirname(__file__))
SRC_DIR = os.path.join(TOP_DIR, 'onnx')
TP_DIR = os.path.join(TOP_DIR, 'third_party')
PROTOC = find_executable('protoc')

install_requires = {'six'}
setup_requires = set()
test_requires = set()

################################################################################
# Version
################################################################################

try:
    git_version = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=TOP_DIR).decode('ascii').strip()
except subprocess.CalledProcessError:
    git_version = None

VersionInfo = namedtuple('VersionInfo', ['version', 'git_version'])(
    version='0.2',
    git_version=git_version
)

################################################################################
# Utilities
################################################################################

def log(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

def die(msg):
    log(msg)
    sys.exit(1)

def true_or_die(b, msg):
    if not b:
        die(msg)
    return b

def recursive_glob(directory, pattern):
    return [os.path.join(dirpath, f)
            for dirpath, dirnames, files in os.walk(directory)
            for f in fnmatch.filter(files, pattern)]

################################################################################
# Pre Check
################################################################################

true_or_die(PROTOC, 'Could not find "protoc" executable!')

################################################################################
# Dependencies
################################################################################

class Dependency(object):
    def __init__(self):
        self.include_dirs = []
        self.libraries = []

class Python(Dependency):
    def __init__(self):
        super(Python, self).__init__()
        self.include_dirs = [sysconfig.get_python_inc()]

class Protobuf(Dependency):
    def __init__(self):
        super(Protobuf, self).__init__()
        # TODO: allow user specify protobuf include_dirs libraries with flags
        # and environment variables
        assert os.getenv('CONDA_PREFIX')
        self.libraries = [os.path.join(os.getenv('CONDA_PREFIX'), "Library", "lib", "libprotobuf")]

class Pybind11(Dependency):
    def __init__(self):
        super(Pybind11, self).__init__()
        self.include_dirs = [os.path.join(TP_DIR, 'pybind11', 'include')]

################################################################################
# Customized commands
################################################################################

class ONNXCommand(setuptools.Command):
    user_options = []

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

class build_proto(ONNXCommand):
    def run(self):
        proto_files = recursive_glob(SRC_DIR, '*.proto')

        if not self.dry_run:
            for proto_file in proto_files:
                log('compiling {}'.format(proto_file))
                subprocess.check_call([
                    PROTOC,
                    '--proto_path', SRC_DIR,
                    '--python_out', SRC_DIR,
                    '--cpp_out', SRC_DIR,
                    proto_file
                ])

class create_version(ONNXCommand):
    def run(self):
        with open(os.path.join(SRC_DIR, 'version.py'), 'w') as f:
            f.write(dedent('''
            version = '{version}'
            git_version = '{git_version}'
            '''.format(**dict(VersionInfo._asdict()))))

class build_py(setuptools.command.build_py.build_py):
    def run(self):
        self.run_command('create_version')
        self.run_command('build_proto')
        setuptools.command.build_py.build_py.run(self)

class develop(setuptools.command.develop.develop):
    def run(self):
        self.run_command('create_version')
        setuptools.command.develop.develop.run(self)

class build_ext(setuptools.command.build_ext.build_ext):
    def run(self):
        self.run_command('build_proto')
        for ext in self.extensions:
            ext.pre_run()
        setuptools.command.build_ext.build_ext.run(self)

cmdclass={
    'build_proto': build_proto,
    'create_version': create_version,
    'build_py': build_py,
    'develop': develop,
    'build_ext': build_ext,
}

################################################################################
# Extensions
################################################################################

class ONNXExtension(setuptools.Extension):
    def pre_run(self):
        pass

def create_extension(ExtType, name, sources, dependencies, extra_link_args, extra_objects):
    include_dirs = sum([dep.include_dirs for dep in dependencies], [TOP_DIR])
    libraries = sum([dep.libraries for dep in dependencies], [])
    extra_compile_args=['-std=c++11']
    if sys.platform == 'darwin':
        extra_compile_args.append('-stdlib=libc++')
    if os.getenv('CONDA_PREFIX'):
        include_dirs.append(os.path.join(os.getenv('CONDA_PREFIX'), "include"))
        include_dirs.append(os.path.join(os.getenv('CONDA_PREFIX'), "Library", "Include"))
    if platform.system() == 'Windows':
        extra_compile_args.append('/MT')
    return ExtType(
        name=name,
        sources=sources,
        include_dirs=include_dirs,
        libraries=libraries,
        extra_compile_args=extra_compile_args,
        extra_objects=extra_objects,
        extra_link_args=extra_link_args,
        language='c++',
    )

class ONNXCpp2PyExtension(setuptools.Extension):
    def pre_run(self):
        self.sources = recursive_glob(SRC_DIR, '*.cc')

cpp2py_deps = [Pybind11(), Python()]
cpp2py_link_args = []
cpp2py_extra_objects = []
build_for_release = os.getenv('ONNX_BINARY_BUILD')
if build_for_release and platform.system() == 'Linux':
    # Cribbed from PyTorch
    # get path of libstdc++ and link manually.
    # for reasons unknown, -static-libstdc++ doesn't fully link some symbols
    CXXNAME = os.getenv('CXX', 'g++')
    path = subprocess.check_output([CXXNAME, '-print-file-name=libstdc++.a'])
    path = path[:-1]
    if type(path) != str:  # python 3
        path = path.decode(sys.stdout.encoding)
    cpp2py_link_args += [path]

    # Hard coded look for the static libraries from Conda
    assert os.getenv('CONDA_PREFIX')
    cpp2py_extra_objects.extend([os.path.join(os.getenv('CONDA_PREFIX'), 'lib', 'libprotobuf.a'),
                             os.path.join(os.getenv('CONDA_PREFIX'), 'lib', 'libprotobuf-lite.a')])
else:
    cpp2py_deps.append(Protobuf())

ext_modules = [
    create_extension(ONNXCpp2PyExtension,
                     str('onnx.onnx_cpp2py_export'),
                     sources=[], # sources will be propagated in pre_run
                     dependencies=cpp2py_deps,
                     extra_link_args=cpp2py_link_args,
                     extra_objects=cpp2py_extra_objects)
]

################################################################################
# Packages
################################################################################

# no need to do fancy stuff so far
packages = setuptools.find_packages()

install_requires.update(['protobuf', 'numpy'])

################################################################################
# Test
################################################################################

setup_requires.add('pytest-runner')
test_requires.add('pytest-cov')

################################################################################
# Final
################################################################################

setuptools.setup(
    name="onnx",
    version=VersionInfo.version,
    description="Open Neural Network Exchange",
    ext_modules=ext_modules,
    cmdclass=cmdclass,
    packages=packages,
    install_requires=install_requires,
    setup_requires=setup_requires,
    tests_require=test_requires,
    author='bddppq',
    author_email='jbai@fb.com',
    url='https://github.com/onnx/onnx',
)
<commit_msg>fix build break<commit_after>from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from distutils.spawn import find_executable
from distutils import sysconfig
import pkg_resources
import setuptools
import setuptools.command.build_py
import setuptools.command.develop
import setuptools.command.build_ext

import platform
import fnmatch
from collections import namedtuple
import os
import subprocess
import sys
import tempfile
from textwrap import dedent

TOP_DIR = os.path.realpath(os.path.dirname(__file__))
SRC_DIR = os.path.join(TOP_DIR, 'onnx')
TP_DIR = os.path.join(TOP_DIR, 'third_party')
PROTOC = find_executable('protoc')

install_requires = {'six'}
setup_requires = set()
test_requires = set()

################################################################################
# Version
################################################################################

try:
    git_version = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=TOP_DIR).decode('ascii').strip()
except subprocess.CalledProcessError:
    git_version = None

VersionInfo = namedtuple('VersionInfo', ['version', 'git_version'])(
    version='0.2',
    git_version=git_version
)

################################################################################
# Utilities
################################################################################

def log(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

def die(msg):
    log(msg)
    sys.exit(1)

def true_or_die(b, msg):
    if not b:
        die(msg)
    return b

def recursive_glob(directory, pattern):
    return [os.path.join(dirpath, f)
            for dirpath, dirnames, files in os.walk(directory)
            for f in fnmatch.filter(files, pattern)]

################################################################################
# Pre Check
################################################################################

true_or_die(PROTOC, 'Could not find "protoc" executable!')

################################################################################
# Dependencies
################################################################################

class Dependency(object):
    def __init__(self):
        self.include_dirs = []
        self.libraries = []

class Python(Dependency):
    def __init__(self):
        super(Python, self).__init__()
        self.include_dirs = [sysconfig.get_python_inc()]

class Protobuf(Dependency):
    def __init__(self):
        super(Protobuf, self).__init__()
        # TODO: allow user specify protobuf include_dirs libraries with flags
        # and environment variables
        if os.getenv('CONDA_PREFIX'):
            self.libraries = [os.path.join(os.getenv('CONDA_PREFIX'), "Library", "lib", "libprotobuf")]
        else:
            self.libraries = ['protobuf']

class Pybind11(Dependency):
    def __init__(self):
        super(Pybind11, self).__init__()
        self.include_dirs = [os.path.join(TP_DIR, 'pybind11', 'include')]

################################################################################
# Customized commands
################################################################################

class ONNXCommand(setuptools.Command):
    user_options = []

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

class build_proto(ONNXCommand):
    def run(self):
        proto_files = recursive_glob(SRC_DIR, '*.proto')

        if not self.dry_run:
            for proto_file in proto_files:
                log('compiling {}'.format(proto_file))
                subprocess.check_call([
                    PROTOC,
                    '--proto_path', SRC_DIR,
                    '--python_out', SRC_DIR,
                    '--cpp_out', SRC_DIR,
                    proto_file
                ])

class create_version(ONNXCommand):
    def run(self):
        with open(os.path.join(SRC_DIR, 'version.py'), 'w') as f:
            f.write(dedent('''
            version = '{version}'
            git_version = '{git_version}'
            '''.format(**dict(VersionInfo._asdict()))))

class build_py(setuptools.command.build_py.build_py):
    def run(self):
        self.run_command('create_version')
        self.run_command('build_proto')
        setuptools.command.build_py.build_py.run(self)

class develop(setuptools.command.develop.develop):
    def run(self):
        self.run_command('create_version')
        setuptools.command.develop.develop.run(self)

class build_ext(setuptools.command.build_ext.build_ext):
    def run(self):
        self.run_command('build_proto')
        for ext in self.extensions:
            ext.pre_run()
        setuptools.command.build_ext.build_ext.run(self)

cmdclass={
    'build_proto': build_proto,
    'create_version': create_version,
    'build_py': build_py,
    'develop': develop,
    'build_ext': build_ext,
}

################################################################################
# Extensions
################################################################################

class ONNXExtension(setuptools.Extension):
    def pre_run(self):
        pass

def create_extension(ExtType, name, sources, dependencies, extra_link_args, extra_objects):
    include_dirs = sum([dep.include_dirs for dep in dependencies], [TOP_DIR])
    libraries = sum([dep.libraries for dep in dependencies], [])
    extra_compile_args=['-std=c++11']
    if sys.platform == 'darwin':
        extra_compile_args.append('-stdlib=libc++')
    if os.getenv('CONDA_PREFIX'):
        include_dirs.append(os.path.join(os.getenv('CONDA_PREFIX'), "include"))
        include_dirs.append(os.path.join(os.getenv('CONDA_PREFIX'), "Library", "Include"))
    if platform.system() == 'Windows':
        extra_compile_args.append('/MT')
    return ExtType(
        name=name,
        sources=sources,
        include_dirs=include_dirs,
        libraries=libraries,
        extra_compile_args=extra_compile_args,
        extra_objects=extra_objects,
        extra_link_args=extra_link_args,
        language='c++',
    )

class ONNXCpp2PyExtension(setuptools.Extension):
    def pre_run(self):
        self.sources = recursive_glob(SRC_DIR, '*.cc')

cpp2py_deps = [Pybind11(), Python()]
cpp2py_link_args = []
cpp2py_extra_objects = []
build_for_release = os.getenv('ONNX_BINARY_BUILD')
if build_for_release and platform.system() == 'Linux':
    # Cribbed from PyTorch
    # get path of libstdc++ and link manually.
    # for reasons unknown, -static-libstdc++ doesn't fully link some symbols
    CXXNAME = os.getenv('CXX', 'g++')
    path = subprocess.check_output([CXXNAME, '-print-file-name=libstdc++.a'])
    path = path[:-1]
    if type(path) != str:  # python 3
        path = path.decode(sys.stdout.encoding)
    cpp2py_link_args += [path]

    # Hard coded look for the static libraries from Conda
    assert os.getenv('CONDA_PREFIX')
    cpp2py_extra_objects.extend([os.path.join(os.getenv('CONDA_PREFIX'), 'lib', 'libprotobuf.a'),
                             os.path.join(os.getenv('CONDA_PREFIX'), 'lib', 'libprotobuf-lite.a')])
else:
    cpp2py_deps.append(Protobuf())

ext_modules = [
    create_extension(ONNXCpp2PyExtension,
                     str('onnx.onnx_cpp2py_export'),
                     sources=[], # sources will be propagated in pre_run
                     dependencies=cpp2py_deps,
                     extra_link_args=cpp2py_link_args,
                     extra_objects=cpp2py_extra_objects)
]

################################################################################
# Packages
################################################################################

# no need to do fancy stuff so far
packages = setuptools.find_packages()

install_requires.update(['protobuf', 'numpy'])

################################################################################
# Test
################################################################################

setup_requires.add('pytest-runner')
test_requires.add('pytest-cov')

################################################################################
# Final
################################################################################

setuptools.setup(
    name="onnx",
    version=VersionInfo.version,
    description="Open Neural Network Exchange",
    ext_modules=ext_modules,
    cmdclass=cmdclass,
    packages=packages,
    install_requires=install_requires,
    setup_requires=setup_requires,
    tests_require=test_requires,
    author='bddppq',
    author_email='jbai@fb.com',
    url='https://github.com/onnx/onnx',
)
<|endoftext|>


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

import os
import sys

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

if sys.argv[-1] == 'publish':
    os.system('python setup.py sdist upload')
    sys.exit()

readme = open('README.md').read()
requirements = ['requests', 'xmltodict', 'arrow']

setup(
    name='pagseguro',
    version='0.1.5.dev0',
    description='Pagseguro API v2 wrapper',
    author='Bruno Rocha',
    author_email='rochacbruno@gmail.com',
    url='https://github.com/rochacbruno/python-pagseguro',
    packages=[
        'pagseguro',
    ],
    package_dir={'pagseguro': 'pagseguro'},
    include_package_data=True,
    install_requires=requirements,
    license='MIT',
    test_suite='runtests',
    zip_safe=False,
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Environment :: Web Environment',
        'Intended Audience :: Developers',
        'Natural Language :: English',
        'License :: OSI Approved :: BSD License',
        '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.3',
    ],
    keywords='pagseguro, payment, payments, credit-card'
)
<commit_msg>no wheel to pypi<commit_after>#!/usr/bin/env python

import os
import sys

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

if sys.argv[-1] == 'publish':
    os.system('python setup.py sdist upload')
    sys.exit()

readme = open('README.md').read()
requirements = ['requests', 'xmltodict', 'arrow']

setup(
    name='pagseguro',
    version='0.1.6.dev0',
    description='Pagseguro API v2 wrapper',
    author='Bruno Rocha',
    author_email='rochacbruno@gmail.com',
    url='https://github.com/rochacbruno/python-pagseguro',
    packages=[
        'pagseguro',
    ],
    package_dir={'pagseguro': 'pagseguro'},
    include_package_data=True,
    install_requires=requirements,
    license='MIT',
    test_suite='runtests',
    zip_safe=False,
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Environment :: Web Environment',
        'Intended Audience :: Developers',
        'Natural Language :: English',
        'License :: OSI Approved :: BSD License',
        '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.3',
    ],
    keywords='pagseguro, payment, payments, credit-card'
)
<|endoftext|>


<commit_before># Changed based on http://projects.csail.mit.edu/spatial/Stanford_Parser. Made by Wei Jia https://github.com/kahitomi/Stanford-parser-Python-Chniese

import jpype

class ParserError(Exception):
    def __init__(self, *args, **margs):
        Exception.__init__(self, *args,**margs)

stanford_parser_classpath = None

def startJvm():
    import os
    os.environ.setdefault("STANFORD_PARSER_CLASSPATH", "/usr/stanford-parser/stanford-parser.jar:/usr/stanford-parser/stanford-parser-3.5.2-models.jar")
    global stanford_parser_classpath
    stanford_parser_home = os.environ["STANFORD_PARSER_HOME"]
    stanford_parser_classpath = os.environ["STANFORD_PARSER_CLASSPATH"]
    JVMPath_8 = os.environ["JAVA8_JVM"]
    jpype.startJVM(JVMPath_8,
                   "-ea"
                   ,("-Djava.class.path=%s" % stanford_parser_classpath))
startJvm() # one jvm per python instance.

class Parser:

    def __init__(self, pcfg_model_fname=None):
        if pcfg_model_fname == None:
            self.pcfg_model_fname = "edu/stanford/nlp/models/lexparser/chinesePCFG.ser.gz"
        else:
            self.pcfg_model_fname = pcfg_model_fname

        self.package_lexparser = jpype.JPackage("edu.stanford.nlp.parser.lexparser")
        LexicalizedParser = jpype.JClass("edu.stanford.nlp.parser.lexparser.LexicalizedParser")
        self.parser = LexicalizedParser.loadModel(self.pcfg_model_fname, ["-maxLength", "80"])

        self.package = jpype.JPackage("edu.stanford.nlp")

        tokenizerFactoryClass = self.package.process.__getattribute__("PTBTokenizer$PTBTokenizerFactory")
        self.tokenizerFactory = tokenizerFactoryClass.newPTBTokenizerFactory(True, True)

        self.tlp = self.parser.getOp().langpack();
        self.gsf = self.tlp.grammaticalStructureFactory()

    def printInfo(self):

        Numberer = self.package.util.Numberer
        print ("Grammar\t" +
               `Numberer.getGlobalNumberer("states").total()` + '\t' +
               `Numberer.getGlobalNumberer("tags").total()` + '\t' +
               `Numberer.getGlobalNumberer("words").total()` + '\t' +
               `self.parser.pparser.ug.numRules()` + '\t' +
               `self.parser.pparser.bg.numRules()` + '\t' +
               `self.parser.pparser.lex.numRules()`)

        print "ParserPack is ", self.parser.op.tlpParams.getClass()
        print "Lexicon is ", self.parser.pd.lex.getClass()
        print "Tags are: ", Numberer.getGlobalNumberer("tags")
        self.parser.op.display()
        print "Test parameters"
        self.parser.op.tlpParams.display()
        self.package_lexparser.Test.display()

    def parseToStanfordDependencies(self, sentence):
        tree = self.parser.parse(sentence)
        dep = self.gsf.newGrammaticalStructure(tree)

        return (tree, dep)

<commit_msg>some changes<commit_after># Changed based on http://projects.csail.mit.edu/spatial/Stanford_Parser. Made by Wei Jia https://github.com/kahitomi/Stanford-parser-Python-Chniese

import jpype

class ParserError(Exception):
    def __init__(self, *args, **margs):
        Exception.__init__(self, *args,**margs)

stanford_parser_classpath = None

def startJvm():
    import os
    os.environ.setdefault("STANFORD_PARSER_CLASSPATH", "/usr/stanford-parser/stanford-parser.jar:/usr/stanford-parser/stanford-parser-3.5.2-models.jar")
    global stanford_parser_classpath
    stanford_parser_home = os.environ["STANFORD_PARSER_HOME"]
    stanford_parser_classpath = os.environ["STANFORD_PARSER_CLASSPATH"]
    JVMPath_8 = os.environ["JAVA8_JVM"]
    jpype.startJVM(JVMPath_8,
                   "-ea"
                   ,("-Djava.class.path=%s" % stanford_parser_classpath))
startJvm() # one jvm per python instance.

class Parser:

    def __init__(self, pcfg_model_fname=None):
        if pcfg_model_fname == None:
            self.pcfg_model_fname = "edu/stanford/nlp/models/lexparser/chinesePCFG.ser.gz"
        else:
            self.pcfg_model_fname = pcfg_model_fname

        self.package_lexparser = jpype.JPackage("edu.stanford.nlp.parser.lexparser")
        LexicalizedParser = jpype.JClass("edu.stanford.nlp.parser.lexparser.LexicalizedParser")
        self.parser = LexicalizedParser.loadModel(self.pcfg_model_fname, ["-maxLength", "80"])

        self.package = jpype.JPackage("edu.stanford.nlp")

        tokenizerFactoryClass = self.package.process.__getattribute__("PTBTokenizer$PTBTokenizerFactory")
        self.tokenizerFactory = tokenizerFactoryClass.newPTBTokenizerFactory(True, True)

        self.tlp = self.parser.getOp().langpack();
        self.gsf = self.tlp.grammaticalStructureFactory()

    def printInfo(self):

        Numberer = self.package.util.Numberer
        print ("Grammar\t" +
               `Numberer.getGlobalNumberer("states").total()` + '\t' +
               `Numberer.getGlobalNumberer("tags").total()` + '\t' +
               `Numberer.getGlobalNumberer("words").total()` + '\t' +
               `self.parser.pparser.ug.numRules()` + '\t' +
               `self.parser.pparser.bg.numRules()` + '\t' +
               `self.parser.pparser.lex.numRules()`)

        print "ParserPack is ", self.parser.op.tlpParams.getClass()
        print "Lexicon is ", self.parser.pd.lex.getClass()
        print "Tags are: ", Numberer.getGlobalNumberer("tags")
        self.parser.op.display()
        print "Test parameters"
        self.parser.op.tlpParams.display()
        self.package_lexparser.Test.display()

    def parseToStanfordDependencies(self, sentence):
        tree = self.parser.parse(sentence)
        dep = self.gsf.newGrammaticalStructure(tree)
        dep = dep.typedDependenciesCCprocessed()

        return (tree, dep)

<|endoftext|>


<commit_before>from setuptools import setup

setup(
    name="django-health-check",
    version='alpha',
    author="Peter J. Farrell",
    author_email="pfarrell@greatbiztools.com",
    description="A simple way to auto discover AJAX_LOOKUP_CHANNELS in settings.py by looking in lookups.py for registered apps.",
    license="MIT",
    url="https://github.com/peterfarrell/django-ajax-selects-autodiscover",
    packages=[
        'ajax_selects_autodiscover',
    ],
    include_package_data=True,
    zip_safe=False,
)<commit_msg>- Added setup.py<commit_after>from setuptools import setup

setup(
    name="django-ajax-selects-autodiscover",
    version='alpha',
    author="Peter J. Farrell",
    author_email="pfarrell@greatbiztools.com",
    description="A simple way to auto discover AJAX_LOOKUP_CHANNELS in settings.py by looking in lookups.py for registered apps.",
    license="MIT",
    url="https://github.com/peterfarrell/django-ajax-selects-autodiscover",
    packages=[
        'ajax_selects_autodiscover',
    ],
    include_package_data=True,
    zip_safe=False,
)<|endoftext|>


<commit_before>import re
from math import ceil

class IndentedTextParser(object):

    class Node(object):
        def __init__(self, text=None):
            self.__children = []
            self.__text = text or ''

        def text(self, text=None):
            if not text:
                return self.__text

            self.__text = text

        def children(self):
            return self.__children

        def append_child(self, child):
            self.__children.append(child)

    def __init__(self):
        self.__indent = 4

    def parse(self, input):
        if not isinstance(input, str):
            raise ValueError('input')

        root = self.__class__.Node()
        input = self.__fix_missing_indents(input)
        self.__parse(input.splitlines(), parent=root, depth=1)
        return root

    def __parse(self, lines, parent=None, depth=0):
        while len(lines) > 0:
            l = lines[0]
            d = self.__get_depth(l)
            if d == depth:
                lines.pop(0)
                child = self.__class__.Node(l.strip())
                parent.append_child(child)
                if len(lines) > 0:
                    d1 = self.__get_depth(lines[0])
                    if d1 > d:
                        self.__parse(lines, parent=child, depth=d1)
                continue
            return

    def __detect_indent(self, input):
        i = 0
        indent = 0
        for it in re.finditer('^((\s+)?)', input, re.MULTILINE | re.DOTALL):
            l = len(it.group(1).split(' ')) - 1
            if indent == 0:
                indent = l
            else:
                if l > indent:
                    if (l % indent) > 0:
                        indent = l
                        continue
                    ni = l - indent
                    if indent == ni:
                        if i >= 3:
                            break
                        i += 1
                    else:
                        indent = ni
                elif indent > l:
                    indent = l
        return indent

    def __fix_missing_indents(self, input):
        fixes = []
        self.__indent = self.__detect_indent(input)
        for line in input.splitlines():
            l = self.__get_indent(line)
            if l > 0:
                if l % self.__indent > 0:
                    c = (self.__indent * ceil(l / self.__indent)) or self.__indent
                    spaces = ''
                    for i in range(0, int(c)):
                        spaces += ' '
                    fixes.append((line, re.sub(r'^\s+', spaces, line),))

        for x in fixes:
            input = input.replace(x[0], x[1])

        return input

    def __get_indent(self, line):
        m = re.search(r'^(\s+).+', line)
        if m:
            spaces = m.groups()[0].split(' ')
            l = len(spaces) - 1
            return l
        return 0

    def __get_depth(self, line):
        sc = self.__get_indent(line)
        return (sc / self.__indent) + 1
<commit_msg>Empty line bug fix.<commit_after>import re
from math import ceil

class IndentedTextParser(object):

    class Node(object):
        def __init__(self, text=None):
            self.__children = []
            self.__text = text or ''

        def text(self, text=None):
            if not text:
                return self.__text

            self.__text = text

        def children(self):
            return self.__children

        def append_child(self, child):
            self.__children.append(child)

    def __init__(self):
        self.__indent = 2

    def parse(self, input):
        if not isinstance(input, str):
            raise ValueError('input')

        root = self.__class__.Node()
        input = self.__fix_missing_indents(input)
        self.__parse(input.splitlines(), parent=root, depth=1)
        return root

    def __parse(self, lines, parent=None, depth=0):
        while len(lines) > 0:
            l = lines[0]
            d = self.__get_depth(l)
            if d == depth:
                lines.pop(0)
                if not l:
                    continue

                child = self.__class__.Node(l.strip())
                parent.append_child(child)
                if len(lines) > 0:
                    while 1:
                        if not len(lines):
                            return
                        elif lines[0]:
                            break

                        lines.pop(0)

                    d1 = self.__get_depth(lines[0])
                    if d1 > d:
                        self.__parse(lines, parent=child, depth=d1)
                continue
            return

    def __detect_indent(self, input):
        i = 0
        indent = 0
        for it in re.finditer('^((\s+)?)', input, re.MULTILINE | re.DOTALL):
            l = len(it.group(1).split(' ')) - 1
            if indent == 0:
                indent = l
            else:
                if l > indent:
                    if (l % indent) > 0:
                        indent = l
                        continue
                    ni = l - indent
                    if indent == ni:
                        if i >= 3:
                            break
                        i += 1
                    else:
                        indent = ni
                elif indent > l:
                    indent = l
        return indent

    def __fix_missing_indents(self, input):
        fixes = []
        self.__indent = self.__detect_indent(input)
        for line in input.splitlines():
            l = self.__get_indent(line)
            if l > 0 and self.__indent > 0:
                if l % self.__indent > 0:
                    c = (self.__indent * ceil(l / self.__indent)) or self.__indent
                    spaces = ''
                    for i in range(0, int(c)):
                        spaces += ' '
                    fixes.append((line, re.sub(r'^\s+', spaces, line),))

        for x in fixes:
            input = input.replace(x[0], x[1])

        return input

    def __get_indent(self, line):
        m = re.search(r'^(\s+).+', line)
        if m:
            spaces = m.groups()[0].split(' ')
            l = len(spaces) - 1
            return l
        return 0

    def __get_depth(self, line):
        sc = self.__get_indent(line)
        return (sc / self.__indent) + 1
<|endoftext|>


<commit_before># -*- coding:utf-8 -*-
from setuptools import setup

setup(
    name        = "mobileclick",
    description = "mobileclick provides baseline methods and utility scripts for the NTCIR-12 MobileClick-2 task",
    author      = "Makoto P. Kato",
    author_email = "kato@dl.kuis.kyoto-u.ac.jp",
    license     = "MIT License",
    url         = "https://github.com/mpkato/mobileclick",
    version='0.1.4',
    packages=[
        'mobileclick',
        'mobileclick.nlp',
        'mobileclick.methods',
        'mobileclick.scripts'
        ],
    install_requires = [
        'BeautifulSoup',
        'nltk>=3.1',
        'numpy'],
    entry_points = {
        'console_scripts': [
            'mobileclick_download_training_data=mobileclick.scripts.mobileclick_download_training_data:main',
            'mobileclick_download_test_data=mobileclick.scripts.mobileclick_download_test_data:main',
            'mobileclick_random_ranking_method=mobileclick.scripts.mobileclick_random_ranking_method:main',
            'mobileclick_lang_model_ranking_method=mobileclick.scripts.mobileclick_lang_model_ranking_method:main'
            ],
    },
    tests_require=['nose']
)
<commit_msg>change the version in setup.py<commit_after># -*- coding:utf-8 -*-
from setuptools import setup

setup(
    name        = "mobileclick",
    description = "mobileclick provides baseline methods and utility scripts for the NTCIR-12 MobileClick-2 task",
    author      = "Makoto P. Kato",
    author_email = "kato@dl.kuis.kyoto-u.ac.jp",
    license     = "MIT License",
    url         = "https://github.com/mpkato/mobileclick",
    version='0.1.5',
    packages=[
        'mobileclick',
        'mobileclick.nlp',
        'mobileclick.methods',
        'mobileclick.scripts'
        ],
    install_requires = [
        'BeautifulSoup',
        'nltk>=3.1',
        'numpy'],
    entry_points = {
        'console_scripts': [
            'mobileclick_download_training_data=mobileclick.scripts.mobileclick_download_training_data:main',
            'mobileclick_download_test_data=mobileclick.scripts.mobileclick_download_test_data:main',
            'mobileclick_random_ranking_method=mobileclick.scripts.mobileclick_random_ranking_method:main',
            'mobileclick_lang_model_ranking_method=mobileclick.scripts.mobileclick_lang_model_ranking_method:main'
            ],
    },
    tests_require=['nose']
)
<|endoftext|>


<commit_before>from setuptools import setup
import os

here = os.path.abspath(os.path.dirname(__file__))
README = open(os.path.join(here, 'README.rst')).read()
CHANGES = open(os.path.join(here, 'CHANGES.rst')).read()

version = "1.0b5-dev"

install_requires = [
    'PyYAML',
    'jinja2',
    'setuptools',
    'ploy>=1.0rc13',
    'ploy_ansible>=1.0b7',
    'ploy_ezjail>=1.0b9',
    'ploy_fabric>=1.0b5',
]

# workaround for installing via buildout, as ansible
# violates its sandbox limitations
try:
    import ansible  # noqa
except ImportError:
    install_requires.append('ansible')

setup(name="bsdploy",
    version=version,
    description="A tool to provision, configure and maintain FreeBSD jails",
    long_description=README + '\n\n\nChanges\n=======\n\n' + CHANGES,
    author='Tom Lazar',
    author_email='tom@tomster.org',
    url='http://github.com/ployground/bsdploy',
    include_package_data=True,
    classifiers=[
        'Development Status :: 4 - Beta',
        'Environment :: Console',
        'Intended Audience :: System Administrators',
        'Operating System :: POSIX :: BSD :: FreeBSD',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 2 :: Only',
        'Topic :: System :: Installation/Setup',
        'Topic :: System :: Systems Administration',
    ],
    license='Beerware Licence',
    zip_safe=False,
    packages=['bsdploy'],
    install_requires=install_requires,
    extras_require={
        'development': [
            'Sphinx',
            'repoze.sphinx.autointerface',
            'coverage',
            'jarn.mkrelease',
            'pytest >= 2.4.2',
            'pytest-flakes',
            'pytest-pep8',
            'tox',
            'mock',
        ],
    },
    entry_points="""
        [console_scripts]
        ploy-download = bsdploy.download:run
        [ansible_paths]
        bsdploy = bsdploy:ansible_paths
        [ploy.plugins]
        bsdploy = bsdploy:plugin
    """)
<commit_msg>Fix indentation.<commit_after>from setuptools import setup
import os

here = os.path.abspath(os.path.dirname(__file__))
README = open(os.path.join(here, 'README.rst')).read()
CHANGES = open(os.path.join(here, 'CHANGES.rst')).read()

version = "1.0b5-dev"

install_requires = [
    'PyYAML',
    'jinja2',
    'setuptools',
    'ploy>=1.0rc13',
    'ploy_ansible>=1.0b7',
    'ploy_ezjail>=1.0b9',
    'ploy_fabric>=1.0b5',
]

# workaround for installing via buildout, as ansible
# violates its sandbox limitations
try:
    import ansible  # noqa
except ImportError:
    install_requires.append('ansible')

setup(
    name="bsdploy",
    version=version,
    description="A tool to provision, configure and maintain FreeBSD jails",
    long_description=README + '\n\n\nChanges\n=======\n\n' + CHANGES,
    author='Tom Lazar',
    author_email='tom@tomster.org',
    url='http://github.com/ployground/bsdploy',
    include_package_data=True,
    classifiers=[
        'Development Status :: 4 - Beta',
        'Environment :: Console',
        'Intended Audience :: System Administrators',
        'Operating System :: POSIX :: BSD :: FreeBSD',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 2 :: Only',
        'Topic :: System :: Installation/Setup',
        'Topic :: System :: Systems Administration',
    ],
    license='Beerware Licence',
    zip_safe=False,
    packages=['bsdploy'],
    install_requires=install_requires,
    extras_require={
        'development': [
            'Sphinx',
            'repoze.sphinx.autointerface',
            'coverage',
            'jarn.mkrelease',
            'pytest >= 2.4.2',
            'pytest-flakes',
            'pytest-pep8',
            'tox',
            'mock',
        ],
    },
    entry_points="""
        [console_scripts]
        ploy-download = bsdploy.download:run
        [ansible_paths]
        bsdploy = bsdploy:ansible_paths
        [ploy.plugins]
        bsdploy = bsdploy:plugin
    """)
<|endoftext|>


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

# Copyright 2012 Clark DuVall
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This is a parser for a new syntax that can be used to write JSOL. Examples
# of this can be found in the syntax/ folder.
# I haven't had a chance to clean this up, so right now its UGLY.

import jsol
import string
import sys

def Error(s):
   print s
   exit(0)

def _ParseString(code):
   buf = ''
   for i in range(len(code)):
      if code[i] == '"' and code[i - 1] != '\\':
         return (code[i + 1:], {'lit': buf})
      if code[i] != '\\' or code[i - 1] == '\\':
         if code[i - 1] == '\\' and code[i] == 'n':
            buf += '\n'
            continue
         buf += code[i]

def _GetParens(code):
   l = 0
   for i in range(len(code)):
      if code[i] == '(':
         l += 1
      if code[i] == ')':
         if l == 0:
            return (code[:i], code[i + 1:])
         l -= 1
   Error('No closing parens')

def _ParseCall(code, name):
   args, rest = _GetParens(code)
   args_list = []
   while len(args.strip()):
      args, arg = _Parse(args)
      args_list.append(arg)
   return (rest, [name] + args_list)

def _ParseCond(if_list, code):
   cond, code = code.split('{', 1)
   if_list.append(_Parse(cond)[1])
   code, statements = _ParseBlock('{' + code)
   if_list.append(statements)
   return code

def _ParseIf(code):
   if_list = ['if']
   code = _ParseCond(if_list, code)
   temp, next = _Parse(code)
   while next == 'elif':
      code = temp
      _ParseCond(if_list, code)
      temp, next = _Parse(code)
   if next == 'else':
      code = temp
      code, statements = _ParseBlock(code)
      if_list.append(statements)
   return (code, if_list)

def _ParseBlock(code):
   code = code.lstrip()
   if code[0] != '{':
      Error('Code block must begin with "{"')
   code = code[1:]
   statements = []
   while code.lstrip()[0] != '}':
      code, statement = _Parse(code)
      statements.append(statement)
   return (code.lstrip()[1:], statements)

def _ParseFunction(code):
   params, rest = code.split(')', 1)
   params = params.split()
   rest, body = _ParseBlock(rest)
   return (rest, { 'params': params, 'def': body })

def _ParseList(code):
   statements = []
   while code.lstrip()[0] != ']':
      code, statement = _Parse(code)
      statements.append(statement)
   return (code.lstrip()[1:], {'lit': statements})

def _ParseDict(code):
   code, d_list = _ParseBlock('{' + code)
   d = {}
   [d.update(x) for x in d_list]
   return (code, {'lit': d})

def _GetNum(num):
   if num == 'null':
      return None
   if num.isdigit():
      return int(num)
   try:
      return float(num)
   except:
      return num

def _Parse(code):
   buf = ''
   has_space = False
   for i in range(1, len(code) + 1):
      c = code[i - 1]
      if c in string.whitespace + ',;':
         has_space = True
         continue
      if has_space and buf or c in [']', '}', ')']:
         if buf == 'if':
            return _ParseIf(code[i - 1:])
         return (code[i - 1:], _GetNum(buf))
      if c == ':':
         rest, result = _Parse(code[i:])
         return (rest, { buf: result })
      if c == '"':
         return _ParseString(code[i:])
      if c == '(':
         if buf == 'def':
            return _ParseFunction(code[i:])
         code, call = _ParseCall(code[i:], buf)
         while len(code.lstrip()) and code.lstrip()[0] == '(':
            code, call = _ParseCall(code.lstrip()[1:], call)
         return (code, call)
      if c == '[':
         return _ParseList(code[i:])
      if c == '{':
         return _ParseDict(code[i:])
      buf += c
      has_space = False
   return (code[i:], _GetNum(buf))

def Parse(code):
   d = {}
   while code:
      code, var = _Parse(code)
      d.update(var)
   return d

if __name__ == '__main__':
   for arg in sys.argv[1:]:
      with open(arg, 'r') as f:
         jsol.Eval(Parse(f.read()))
<commit_msg>Update master<commit_after>#!/usr/bin/env python

# Copyright 2012 Clark DuVall
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This is a parser for a new syntax that can be used to write JSOL. Examples
# of this can be found in the examples/psol directory.
# I haven't had a chance to clean this up, so right now its UGLY.

import jsol
import string
import sys

def Error(s):
   print s
   exit(0)

def _ParseString(code):
   buf = ''
   for i in range(len(code)):
      if code[i] == '"' and code[i - 1] != '\\':
         return (code[i + 1:], {'lit': buf})
      if code[i] != '\\' or code[i - 1] == '\\':
         if code[i - 1] == '\\' and code[i] == 'n':
            buf += '\n'
            continue
         buf += code[i]

def _GetParens(code):
   l = 0
   for i in range(len(code)):
      if code[i] == '(':
         l += 1
      if code[i] == ')':
         if l == 0:
            return (code[:i], code[i + 1:])
         l -= 1
   Error('No closing parens')

def _ParseCall(code, name):
   args, rest = _GetParens(code)
   args_list = []
   while len(args.strip()):
      args, arg = _Parse(args)
      args_list.append(arg)
   return (rest, [name] + args_list)

def _ParseCond(if_list, code):
   cond, code = code.split('{', 1)
   if_list.append(_Parse(cond)[1])
   code, statements = _ParseBlock('{' + code)
   if_list.append(statements)
   return code

def _ParseIf(code):
   if_list = ['if']
   code = _ParseCond(if_list, code)
   temp, next = _Parse(code)
   while next == 'elif':
      code = temp
      _ParseCond(if_list, code)
      temp, next = _Parse(code)
   if next == 'else':
      code = temp
      code, statements = _ParseBlock(code)
      if_list.append(statements)
   return (code, if_list)

def _ParseBlock(code):
   code = code.lstrip()
   if code[0] != '{':
      Error('Code block must begin with "{"')
   code = code[1:]
   statements = []
   while code.lstrip()[0] != '}':
      code, statement = _Parse(code)
      statements.append(statement)
   return (code.lstrip()[1:], statements)

def _ParseFunction(code):
   params, rest = code.split(')', 1)
   params = params.split()
   rest, body = _ParseBlock(rest)
   return (rest, { 'params': params, 'def': body })

def _ParseList(code):
   statements = []
   while code.lstrip()[0] != ']':
      code, statement = _Parse(code)
      statements.append(statement)
   return (code.lstrip()[1:], {'lit': statements})

def _ParseDict(code):
   code, d_list = _ParseBlock('{' + code)
   d = {}
   [d.update(x) for x in d_list]
   return (code, {'lit': d})

def _GetNum(num):
   if num == 'null':
      return None
   if num.isdigit():
      return int(num)
   try:
      return float(num)
   except:
      return num

def _Parse(code):
   buf = ''
   has_space = False
   for i in range(1, len(code) + 1):
      c = code[i - 1]
      if c in string.whitespace + ',;':
         has_space = True
         continue
      if has_space and buf or c in [']', '}', ')']:
         if buf == 'if':
            return _ParseIf(code[i - 1:])
         return (code[i - 1:], _GetNum(buf))
      if c == ':':
         rest, result = _Parse(code[i:])
         return (rest, { buf: result })
      if c == '"':
         return _ParseString(code[i:])
      if c == '(':
         if buf == 'def':
            return _ParseFunction(code[i:])
         code, call = _ParseCall(code[i:], buf)
         while len(code.lstrip()) and code.lstrip()[0] == '(':
            code, call = _ParseCall(code.lstrip()[1:], call)
         return (code, call)
      if c == '[':
         return _ParseList(code[i:])
      if c == '{':
         return _ParseDict(code[i:])
      buf += c
      has_space = False
   return (code[i:], _GetNum(buf))

def Parse(code):
   d = {}
   while code:
      code, var = _Parse(code)
      d.update(var)
   return d

if __name__ == '__main__':
   for arg in sys.argv[1:]:
      with open(arg, 'r') as f:
         jsol.Eval(Parse(f.read()))
<|endoftext|>


<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

# setup from TinERP
#   taken from straw http://www.nongnu.org/straw/index.html
#   taken from gnomolicious http://www.nongnu.org/gnomolicious/
#   adapted by Nicolas Évrard <nicoe@altern.org>
#

import sys
import os
from os.path import join, isfile, basename
import glob

from pprint import pprint as pp

from setuptools import setup as official_setup, find_packages
from setuptools.command.install import install
from distutils.sysconfig import get_python_lib

has_py2exe = False
if os.name == 'nt':
    import py2exe
    has_py2exe = True

sys.path.append(join(os.path.abspath(os.path.dirname(__file__)), "bin"))

execfile(join('bin', 'release.py'))

if 'bdist_rpm' in sys.argv:
    version = version.split('-')[0]

# get python short version
py_short_version = '%s.%s' % sys.version_info[:2]

# backports os.walk with followlinks from python 2.6
def walk_followlinks(top, topdown=True, onerror=None, followlinks=False):
    from os.path import join, isdir, islink
    from os import listdir, error

    try:
        names = listdir(top)
    except error, err:
        if onerror is not None:
            onerror(err)
        return

    dirs, nondirs = [], []
    for name in names:
        if isdir(join(top, name)):
            dirs.append(name)
        else:
            nondirs.append(name)

    if topdown:
        yield top, dirs, nondirs
    for name in dirs:
        path = join(top, name)
        if followlinks or not islink(path):
            for x in walk_followlinks(path, topdown, onerror, followlinks):
                yield x
    if not topdown:
        yield top, dirs, nondirs

if sys.version_info < (2, 6):
    os.walk = walk_followlinks

def find_addons():
    for root, _, names in os.walk(join('bin', 'addons'), followlinks=True):
        if '__openerp__.py' in names or '__terp__.py' in names:
            yield basename(root), root

def data_files():
    '''Build list of data files to be installed'''
    files = []
    if os.name == 'nt':
        os.chdir('bin')
        for (dp, dn, names) in os.walk('addons'):
            files.append((dp, map(lambda x: join('bin', dp, x), names)))
        os.chdir('..')
        #for root, _, names in os.walk(join('bin','addons')):
        #    files.append((root, [join(root, name) for name in names]))
        for root, _, names in os.walk('doc'):
            files.append((root, [join(root, name) for name in names]))
        #for root, _, names in os.walk('pixmaps'):
        #    files.append((root, [join(root, name) for name in names]))
        files.append(('.', [join('bin', 'import_xml.rng'),]))
    else:
        man_directory = join('share', 'man')
        files.append((join(man_directory, 'man1'), ['man/openerp-server.1']))
        files.append((join(man_directory, 'man5'), ['man/openerp_serverrc.5']))

        doc_directory = join('share', 'doc', 'openerp-server-%s' % version)
        files.append((doc_directory, filter(isfile, glob.glob('doc/*'))))
        files.append((join(doc_directory, 'migrate', '3.3.0-3.4.0'),
                      filter(isfile, glob.glob('doc/migrate/3.3.0-3.4.0/*'))))
        files.append((join(doc_directory, 'migrate', '3.4.0-4.0.0'),
                      filter(isfile, glob.glob('doc/migrate/3.4.0-4.0.0/*'))))

        openerp_site_packages = join(get_python_lib(prefix=''), 'openerp-server')

        files.append((openerp_site_packages, [join('bin', 'import_xml.rng'),]))

        if sys.version_info[0:2] == (2,5):
            files.append((openerp_site_packages, [ join('python25-compat','BaseHTTPServer.py'),
                                                   join('python25-compat','SimpleXMLRPCServer.py'),
                                                   join('python25-compat','SocketServer.py')]))

        for addonname, add_path in find_addons():
            addon_path = join(get_python_lib(prefix=''), 'openerp-server','addons', addonname)
            for root, dirs, innerfiles in os.walk(add_path):
                innerfiles = filter(lambda fil: os.path.splitext(fil)[1] not in ('.pyc', '.pyd', '.pyo'), innerfiles)
                if innerfiles:
                    res = os.path.normpath(join(addon_path, root.replace(join(add_path), '.')))
                    files.extend(((res, map(lambda fil: join(root, fil),
                                            innerfiles)),))

    return files

f = file('openerp-server','w')
f.write("""#!/bin/sh
echo "Error: the content of this file should have been replaced during "
echo "installation\n"
exit 1
""")
f.close()

def find_package_dirs():
    package_dirs = {'openerp-server': 'bin'}
    for mod, path in find_addons():
        package_dirs['openerp-server.addons.' + mod] = path
    return package_dirs

class openerp_server_install(install):
    def run(self):
        # create startup script
        start_script = "#!/bin/sh\ncd %s\nexec %s ./openerp-server.py $@\n"\
            % (join(self.install_libbase, "openerp-server"), sys.executable)
        # write script
        f = open('openerp-server', 'w')
        f.write(start_script)
        f.close()
        install.run(self)

options = {
    "py2exe": {
        "compressed": 1,
        "optimize": 2,
        "dist_dir": 'dist',
        "packages": [
                 "lxml", "lxml.builder", "lxml._elementpath", "lxml.etree",
                 "lxml.objectify", "decimal", "xml", "xml", "xml.dom", "xml.xpath",
                 "encodings", "dateutil", "wizard", "pychart", "PIL", "pyparsing",
                 "pydot", "asyncore","asynchat", "reportlab", "vobject",
                 "HTMLParser", "select", "mako", "poplib",
                 "imaplib", "smtplib", "email", "yaml", "DAV",
                 ],
        "excludes" : ["Tkconstants","Tkinter","tcl"],
    }
}

def setup(**kwargs):
    #pp(kwargs)
    return official_setup(**kwargs)

setup(name             = name,
      version          = version,
      description      = description,
      long_description = long_desc,
      url              = url,
      author           = author,
      author_email     = author_email,
      classifiers      = filter(None, classifiers.split("\n")),
      license          = license,
      data_files       = data_files(),
      cmdclass         = {
          'install' : openerp_server_install,
      },
      scripts          = ['openerp-server'],
      packages = [
          '.'.join(['openerp-server'] + package.split('.')[1:])
          for package in find_packages()
      ],
      include_package_data = True,
      package_data = {
          '': ['*.yml', '*.xml', '*.po', '*.pot', '*.csv'],
      },
      package_dir      = find_package_dirs(),
      console = [
          {
              "script": join("bin", "openerp-server.py"),
              "icon_resources": [(1, join("pixmaps","openerp-icon.ico"))]
          }
      ],
      options = options,
      install_requires = [
          'lxml',
          'mako',
          'python-dateutil',
          'psycopg2',
          'pychart',
          'pydot',
          'pytz',
          'reportlab',
          'caldav',
          'pyyaml',
          #'django',
          'pywebdav'
          #'cx_Oracle',
          #'mysqldb',
          'feedparser',
          #'bsddb3',
          'egenix-mx-base'
      ],
      extras_require={
          'SSL' : ['pyopenssl'],
      }
)

<commit_msg>[REF] Add the uuid library in the dependencies and remove the commented code<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

# setup from TinERP
#   taken from straw http://www.nongnu.org/straw/index.html
#   taken from gnomolicious http://www.nongnu.org/gnomolicious/
#   adapted by Nicolas Évrard <nicoe@altern.org>
#

import sys
import os
from os.path import join, isfile, basename
import glob

from pprint import pprint as pp

from setuptools import setup, find_packages
from setuptools.command.install import install
from distutils.sysconfig import get_python_lib

has_py2exe = False
if os.name == 'nt':
    import py2exe
    has_py2exe = True

sys.path.append(join(os.path.abspath(os.path.dirname(__file__)), "bin"))

execfile(join('bin', 'release.py'))

if 'bdist_rpm' in sys.argv:
    version = version.split('-')[0]

# get python short version
py_short_version = '%s.%s' % sys.version_info[:2]

# backports os.walk with followlinks from python 2.6
def walk_followlinks(top, topdown=True, onerror=None, followlinks=False):
    from os.path import join, isdir, islink
    from os import listdir, error

    try:
        names = listdir(top)
    except error, err:
        if onerror is not None:
            onerror(err)
        return

    dirs, nondirs = [], []
    for name in names:
        if isdir(join(top, name)):
            dirs.append(name)
        else:
            nondirs.append(name)

    if topdown:
        yield top, dirs, nondirs
    for name in dirs:
        path = join(top, name)
        if followlinks or not islink(path):
            for x in walk_followlinks(path, topdown, onerror, followlinks):
                yield x
    if not topdown:
        yield top, dirs, nondirs

if sys.version_info < (2, 6):
    os.walk = walk_followlinks

def find_addons():
    for root, _, names in os.walk(join('bin', 'addons'), followlinks=True):
        if '__openerp__.py' in names or '__terp__.py' in names:
            yield basename(root), root

def data_files():
    '''Build list of data files to be installed'''
    files = []
    if os.name == 'nt':
        os.chdir('bin')
        for (dp, dn, names) in os.walk('addons'):
            files.append((dp, map(lambda x: join('bin', dp, x), names)))
        os.chdir('..')
        #for root, _, names in os.walk(join('bin','addons')):
        #    files.append((root, [join(root, name) for name in names]))
        for root, _, names in os.walk('doc'):
            files.append((root, [join(root, name) for name in names]))
        #for root, _, names in os.walk('pixmaps'):
        #    files.append((root, [join(root, name) for name in names]))
        files.append(('.', [join('bin', 'import_xml.rng'),]))
    else:
        man_directory = join('share', 'man')
        files.append((join(man_directory, 'man1'), ['man/openerp-server.1']))
        files.append((join(man_directory, 'man5'), ['man/openerp_serverrc.5']))

        doc_directory = join('share', 'doc', 'openerp-server-%s' % version)
        files.append((doc_directory, filter(isfile, glob.glob('doc/*'))))
        files.append((join(doc_directory, 'migrate', '3.3.0-3.4.0'),
                      filter(isfile, glob.glob('doc/migrate/3.3.0-3.4.0/*'))))
        files.append((join(doc_directory, 'migrate', '3.4.0-4.0.0'),
                      filter(isfile, glob.glob('doc/migrate/3.4.0-4.0.0/*'))))

        openerp_site_packages = join(get_python_lib(prefix=''), 'openerp-server')

        files.append((openerp_site_packages, [join('bin', 'import_xml.rng'),]))

        if sys.version_info[0:2] == (2,5):
            files.append((openerp_site_packages, [ join('python25-compat','BaseHTTPServer.py'),
                                                   join('python25-compat','SimpleXMLRPCServer.py'),
                                                   join('python25-compat','SocketServer.py')]))

        for addonname, add_path in find_addons():
            addon_path = join(get_python_lib(prefix=''), 'openerp-server','addons', addonname)
            for root, dirs, innerfiles in os.walk(add_path):
                innerfiles = filter(lambda fil: os.path.splitext(fil)[1] not in ('.pyc', '.pyd', '.pyo'), innerfiles)
                if innerfiles:
                    res = os.path.normpath(join(addon_path, root.replace(join(add_path), '.')))
                    files.extend(((res, map(lambda fil: join(root, fil),
                                            innerfiles)),))

    return files

f = file('openerp-server','w')
f.write("""#!/bin/sh
echo "Error: the content of this file should have been replaced during "
echo "installation\n"
exit 1
""")
f.close()

def find_package_dirs():
    package_dirs = {'openerp-server': 'bin'}
    for mod, path in find_addons():
        package_dirs['openerp-server.addons.' + mod] = path
    return package_dirs

class openerp_server_install(install):
    def run(self):
        # create startup script
        start_script = "#!/bin/sh\ncd %s\nexec %s ./openerp-server.py $@\n"\
            % (join(self.install_libbase, "openerp-server"), sys.executable)
        # write script
        f = open('openerp-server', 'w')
        f.write(start_script)
        f.close()
        install.run(self)

options = {
    "py2exe": {
        "compressed": 1,
        "optimize": 2,
        "dist_dir": 'dist',
        "packages": [
            "lxml", "lxml.builder", "lxml._elementpath", "lxml.etree",
            "lxml.objectify", "decimal", "xml", "xml", "xml.dom", "xml.xpath",
            "encodings", "dateutil", "wizard", "pychart", "PIL", "pyparsing",
            "pydot", "asyncore","asynchat", "reportlab", "vobject",
            "HTMLParser", "select", "mako", "poplib",
            "imaplib", "smtplib", "email", "yaml", "DAV",
            "uuid",
        ],
        "excludes" : ["Tkconstants","Tkinter","tcl"],
    }
}

setup(name             = name,
      version          = version,
      description      = description,
      long_description = long_desc,
      url              = url,
      author           = author,
      author_email     = author_email,
      classifiers      = filter(None, classifiers.split("\n")),
      license          = license,
      data_files       = data_files(),
      cmdclass         = {
          'install' : openerp_server_install,
      },
      scripts          = ['openerp-server'],
      packages = [
          '.'.join(['openerp-server'] + package.split('.')[1:])
          for package in find_packages()
      ],
      include_package_data = True,
      package_data = {
          '': ['*.yml', '*.xml', '*.po', '*.pot', '*.csv'],
      },
      package_dir      = find_package_dirs(),
      console = [
          {
              "script": join("bin", "openerp-server.py"),
              "icon_resources": [(1, join("pixmaps","openerp-icon.ico"))]
          }
      ],
      options = options,
      install_requires = [
          'lxml',
          'mako',
          'python-dateutil',
          'psycopg2',
          'pychart',
          'pydot',
          'pytz',
          'reportlab',
          'caldav',
          'pyyaml',
          'pywebdav'
          'feedparser',
      ],
      extras_require={
          'SSL' : ['pyopenssl'],
      }
)

<|endoftext|>


<commit_before>import urllib.request
import urllib.parse

# x = urllib.request.urlopen('https://google.com/')
# print(x.read())

# https://www.google.com/search?q=Monthy+Python

url = 'https://google.com/search'
get = {
    'q' : 'Monthy Python'
}

data = urllib.parse.urlencode(get) # Encodes to url format
data = data.encode('utf-8') # Converts to binary utf-8

# req  = urllib.request.Request(url, data) # POST
# req  = urllib.request.Request(url + '?' + data.decode("utf-8")) # GET

try:
    resp = urllib.request.urlopen(req)
    print(resp.read())

except Exception as e:
    print(str(e))<commit_msg>Added headers example.<commit_after>import urllib.request
import urllib.parse

# x = urllib.request.urlopen('https://google.com/')
# print(x.read())

# https://www.google.com/search?q=Monthy+Python

url = 'https://google.com/search'
get = {
    'q' : 'Monthy Python'
}

headers = {
    'User-Agent' : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/43.0.2357.130 Chrome/43.0.2357.130 Safari/537.36'
}

data = urllib.parse.urlencode(get) # Encodes to url format
data = data.encode('utf-8') # Converts to binary utf-8

# req  = urllib.request.Request(url, data) # POST
req  = urllib.request.Request(url + '?' + data.decode("utf-8"), headers=headers) # GET

try:
    resp = urllib.request.urlopen(req)
    print(resp.read())

except Exception as e:
    print(str(e)) # 403 forbidden???
                  # Google thinks that you are a robot...
                  # ...because you do not have anything in HEADERS<|endoftext|>


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

# Copyright (c) 2012 Denis Zalevskiy
# Licensed under MIT License

from cor import *

nomatch = const('nomatch')
empty = const('empty')
end = const('end')

def ignore(*x): return empty
def value(x): return x
def first(x): return x[0]
second = nth(1)
def list2str(x): return ''.join(x)

is_parser_trace = True
debug_indent_level = 0
debug_indent_sym = '  '

def __indent_plus():
    global debug_indent_level
    debug_indent_level += 1

def __indent_minus(*args):
    global debug_indent_level
    debug_indent_level -= 1

debug_indent = Scope(__indent_plus, __indent_minus)

def debug_print(msg, *args, **kwargs):
    global debug_indent_sym, debug_indent_level
    print debug_indent_sym * debug_indent_level, \
        msg.format(*args, **kwargs)

def parser(name):
    def mk_name(name):
        return ''.join(['?', name])
    def deco(fn):
        global is_parser_trace
        fn.__name__ = mk_name(name)
        def wrapper(*args, **kwargs):
            global debug_indent
            debug_print("{}({}) {{", fn.__name__,
                        printable_args(*args, **kwargs))
            with debug_indent:
                res = fn(*args, **kwargs)
            debug_print("}} => {}", printable_args(res))
            return res
        if is_parser_trace:
            wrapper.__name__ = mk_name(name)
            return wrapper
        else:
            return fn
    return deco

class InfiniteInput(object):

    len_limit = 1024 * 64

    def __init__(self, src, begin = 0, end = None):
        self.__s = src
        self.__begin = begin
        self.__is_endless = end is None
        if end is None:
            self._end = lambda : len(src)
        elif callable(end):
            self._end = end
        else:
            self._end = lambda: end

    def __get_slice(self, k):
        start, stop = k.start, k.stop
        if not (k.step is None or k.step == 1):
            raise Err("Can't handle step != 1")
        start = self.__begin if start is None else self.__begin + start
        end = self._end if stop is None else self.__begin + stop
        return InfiniteInput(self.__s, start, end)

    def __getitem__(self, i):
        if isinstance(i, slice):
            return self.__get_slice(i)
        end = self._end()
        i = self.__begin + i
        if i < end:
            return self.__s[i]
        elif i > self.len_limit:
            raise Exception("Length limit is reached")
        else:
            return nomatch

    def __str__(self):
        return str(self.__s[self.__begin:self._end()])

    def __repr__(self):
        return ''.join(['"', str(self), '"'])

    def __len__(self):
        return self._end() - self.__begin

    def __iter__(self):
        def gen():
            pos = self.__begin
            while pos != self._end():
                yield self[pos]
                pos += 1
        return gen

    def as_string(self):
        if isinstance(self.__s, str):
            if self.__begin == 0 and self.__is_endless:
                return self.__s
            elif self.__is_endless:
                return self.__s[self.__begin:]
            else:
                return self.__s[self.__begin:self._end()]
        else:
            res = [x for x in self.__s]
            res.append(chr(0))
            return ''.join(res)

def source(src, begin = 0, end = None):
    return InfiniteInput(src, begin, end)

def _match(name, s, conv):
    @parser(name)
    def fn(src):
        v = src[0]
        return (1, conv(v)) if v == s else nomatch
    return fn

def _match_symbol(name, s, conv):
    if isinstance(s, str):
        if len(s) != 1:
            raise Exception("len != 1")
    elif s != nomatch:
        raise Exception("Not a string")
    return _match(name, s, conv)

def _match_string(name, s, conv):
    if not isinstance(s, str):
        raise Exception("Not a string")
    slen = len(s)
    @parser(name)
    def fn(src):
        if len(src) < slen:
            return nomatch
        v = src[0:slen].as_string()
        return (slen, conv(v)) if v == s else nomatch
    return fn

def _match_iterable(name, pat, conv):
    if not is_iterable(pat):
        raise Exception("Don't know what to do with {}".format(seq))

    seq = [x for x in pat] if isinstance(pat, str) else pat
    @parser(name)
    def fn(src):
        v = src[0]
        return (1, conv(v)) if v in seq else nomatch
    return fn

def _match_any(name, tests, conv):
    @parser(name)
    def fn(src):
        for test in tests:
            res = test(src)
            if res == nomatch:
                continue
            return (res[0], conv(res[1]))
        return nomatch
    return fn

def _match_seq(name, tests, conv):
    @parser(name)
    def fn(src):
        total = []
        pos = 0
        for test in tests:
            res = test(src[pos:])
            if res == nomatch:
                return nomatch
            if res[1] != empty:
                total.append(res[1])
            pos += res[0]
        return pos, conv(total)
    return fn

def _one_more(name, test, conv):
    @parser(name)
    def fn(src):
        total = []
        pos = 0
        res = test(src)
        if res == nomatch:
            return res
        while res != nomatch:
            total.append(res[1])
            pos += res[0]
            res = test(src[pos:])
        return pos, conv(total)
    return fn

def _zero_more(name, test, conv):
    @parser(name)
    def fn(src):
        total = []
        pos = 0
        res = test(src)
        while res != nomatch:
            total.append(res[1])
            pos += res[0]
            res = test(src[pos:])
        return pos, conv(total)
    return fn

def _0_1(name, test, conv):
    @parser(name)
    def fn(src):
        pos = 0
        res = test(src)
        return res[0], conv(res[1]) if res != nomatch else (0, empty)
    return fn

def _ne(name, test, conv):
    @parser(name)
    def fn(src):
        res = test(src)
        return (1, conv(src[0])) if res == nomatch else nomatch
    return fn

def _lookup(name, test, conv):
    @parser(name)
    def fn(src):
        res = test(src)
        return nomatch if res == nomatch else (0, res[1])
    return fn

def is_str(c):
    return isinstance(c, str) or c == nomatch

class ParseInfo(tuple):
    def __new__(cls, *args):
        return tuple.__new__(cls, args)

def __mk_fn_parser(name, rule, action):
    fn, data = rule
    if not is_str(data):
        if isinstance(data, ParseInfo):
            data = mk_parser(data)
        if is_iterable(data):
            data = [mk_parser(x) for x in data]
        else:
            data = mk_parser(data)
    return fn(name, data, action)

def __extract_rule(entity):
    if isinstance(entity, ParseInfo):
        return entity
    elif is_str(entity):
        return sym(entity)
    else:
        return nomatch

def __extract_rule_action(data, name = "?"):
    res = __extract_rule(data)
    if res != nomatch:
        return name, res, value
    elif is_iterable(data) and len(data) == 2:
        res = __extract_rule(data[0])
        if res != nomatch:
            return name, res, data[1]
    elif callable(data):
        return __extract_rule_action(data(), data.__name__)

    raise Err("Don't know how to extract from {}", data)

def __mk_parser(name, rule, action):
    if isinstance(rule, ParseInfo):
        return __mk_fn_parser(name, rule, action)

    raise Err("Do not know what to do with {}", rule)

def mk_parser(top, name = ""):
    return __mk_parser(*__extract_rule_action(top, name))

def __normalize(v):
    if callable(v):
        return v
    if is_str(v):
        fn = lambda: (v, value)
        fn.__name__ = ''.join(('!', v))
        return fn
    raise Err("Don't know how to normalize {}", v)

def r0_inf(test):
    return ParseInfo(_zero_more, __normalize(test))
def r0_1(test):
    return ParseInfo(_0_1, __normalize(test))
def r1_inf(test):
    return ParseInfo(_one_more, __normalize(test))
def seq(*tests):
    return ParseInfo(_match_seq, tests)
def choice(*tests):
    return ParseInfo(_match_any, tests)
def ne(test):
    return ParseInfo(_ne, __normalize(test))
def eof():
    return nomatch, ignore
def sym(c): return ParseInfo(_match_symbol, c) \
        if c == nomatch or len(c) == 1 \
        else ParseInfo(_match_iterable, c)

def lookup(rule):
    def rule_fn():
        return ParseInfo(_lookup, rule), ignore
    rule_fn.__name__ = '_'.join(['lookup', parser.__name__])
    return rule_fn
<commit_msg>parser tracing improvements<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (c) 2012 Denis Zalevskiy
# Licensed under MIT License

from cor import *

nomatch = const('nomatch')
empty = const('empty')
end = const('end')

def ignore(*x): return empty
def value(x): return x
def first(x): return x[0]
second = nth(1)
third = nth(2)
def list2str(x): return ''.join(x)

is_parser_trace = True
debug_indent_level = 0
debug_indent_sym = '  '

def __indent_plus():
    global debug_indent_level
    debug_indent_level += 1

def __indent_minus(*args):
    global debug_indent_level
    debug_indent_level -= 1

debug_indent = Scope(__indent_plus, __indent_minus)

def debug_print(msg, *args, **kwargs):
    global debug_indent_sym, debug_indent_level
    log("{}{}", debug_indent_sym * debug_indent_level, \
            msg.format(*args, **kwargs))

def parser(name):
    def mk_name(name):
        return ''.join(['?', name])
    def deco(fn):
        global is_parser_trace
        fn.__name__ = mk_name(name)
        def wrapper(src):
            global debug_indent
            pr = src if len(src) < 20 else ''.join([str(src[:20]), '...'])
            debug_print("{}({}) {{", fn.__name__, repr(pr))
            with debug_indent:
                res = fn(src)
            debug_print("}} => {}", printable_args(res))
            return res
        if is_parser_trace:
            wrapper.__name__ = mk_name(name)
            return wrapper
        else:
            return fn
    return deco

class InfiniteInput(object):

    len_limit = 1024 * 64

    def __init__(self, src, begin = 0, end = None):
        self.__s = src
        self.__begin = begin
        self.__is_endless = end is None
        if end is None:
            self._end = lambda: len(src)
        else:
            self._end = lambda: end

    def __get_slice(self, k):
        start, stop = k.start, k.stop
        if not (k.step is None or k.step == 1):
            raise Err("Can't handle step != 1")
        start = self.__begin if start is None else self.__begin + start
        end = self._end if stop is None else self.__begin + stop
        return InfiniteInput(self.__s, start, end)

    def __getitem__(self, i):
        if isinstance(i, slice):
            return self.__get_slice(i)
        end = self._end()
        i = self.__begin + i
        if i < end:
            return self.__s[i]
        elif i > self.len_limit:
            raise Exception("Length limit is reached")
        else:
            return nomatch

    def __str__(self):
        return str(self.__s[self.__begin:self._end()])

    def __repr__(self):
        return ''.join(['"', str(self), '"'])

    def __len__(self):
        return self._end() - self.__begin

    def __iter__(self):
        def gen():
            pos = self.__begin
            while pos != self._end():
                yield self[pos]
                pos += 1
        return gen

    def as_string(self):
        if isinstance(self.__s, str):
            if self.__begin == 0 and self.__is_endless:
                return self.__s
            elif self.__is_endless:
                return self.__s[self.__begin:]
            else:
                return self.__s[self.__begin:self._end()]
        else:
            res = [x for x in self.__s]
            res.append(chr(0))
            return ''.join(res)

def source(src, begin = 0, end = None):
    return InfiniteInput(src, begin, end)

def _match(name, s, conv):
    @parser(name)
    def fn(src):
        v = src[0]
        return (1, conv(v)) if v == s else nomatch
    return fn

def _match_symbol(name, s, conv):
    if isinstance(s, str):
        if len(s) != 1:
            raise Exception("len != 1")
    elif s != nomatch:
        raise Exception("Not a string")
    return _match(name, s, conv)

def _match_string(name, s, conv):
    if not isinstance(s, str):
        raise Exception("Not a string")
    slen = len(s)
    @parser(name)
    def fn(src):
        if len(src) < slen:
            return nomatch
        v = src[0:slen].as_string()
        return (slen, conv(v)) if v == s else nomatch
    return fn

def _match_iterable(name, pat, conv):
    if not is_iterable(pat):
        raise Exception("Don't know what to do with {}".format(seq))

    seq = [x for x in pat] if isinstance(pat, str) else pat
    @parser(name)
    def fn(src):
        v = src[0]
        return (1, conv(v)) if v in seq else nomatch
    return fn

def _match_any(name, tests, conv):
    @parser(name)
    def fn(src):
        for test in tests:
            res = test(src)
            if res == nomatch:
                continue
            return (res[0], conv(res[1]))
        return nomatch
    return fn

def _match_seq(name, tests, conv):
    @parser(name)
    def fn(src):
        total = []
        pos = 0
        for test in tests:
            res = test(src[pos:])
            if res == nomatch:
                return nomatch
            if res[1] != empty:
                total.append(res[1])
            pos += res[0]
        return pos, conv(total)
    return fn

def _one_more(name, test, conv):
    @parser(name)
    def fn(src):
        total = []
        pos = 0
        res = test(src)
        if res == nomatch:
            return res
        while res != nomatch:
            total.append(res[1])
            pos += res[0]
            res = test(src[pos:])
        return pos, conv(total)
    return fn

def _zero_more(name, test, conv):
    @parser(name)
    def fn(src):
        total = []
        pos = 0
        res = test(src)
        while res != nomatch:
            total.append(res[1])
            pos += res[0]
            res = test(src[pos:])
        return pos, conv(total)
    return fn

def _0_1(name, test, conv):
    @parser(name)
    def fn(src):
        pos = 0
        res = test(src)
        return res[0], conv(res[1]) if res != nomatch else (0, empty)
    return fn

def _ne(name, test, conv):
    @parser(name)
    def fn(src):
        res = test(src)
        return (1, conv(src[0])) if res == nomatch else nomatch
    return fn

def _lookup(name, test, conv):
    @parser(name)
    def fn(src):
        res = test(src)
        return nomatch if res == nomatch else (0, res[1])
    return fn

def is_str(c):
    return isinstance(c, str) or c == nomatch

class ParseInfo(tuple):
    def __new__(cls, *args):
        return tuple.__new__(cls, args)

def __mk_fn_parser(name, rule, action):
    fn, data = rule
    if not is_str(data):
        if isinstance(data, ParseInfo):
            data = mk_parser(data)
        if is_iterable(data):
            data = [mk_parser(x) for x in data]
        else:
            data = mk_parser(data)
    return fn(name, data, action)

def __extract_rule(entity):
    if isinstance(entity, ParseInfo):
        return entity
    elif is_str(entity):
        return sym(entity)
    else:
        return nomatch

def __extract_rule_action(data, name = "?"):
    res = __extract_rule(data)
    if res != nomatch:
        return name, res, value
    elif is_iterable(data) and len(data) == 2:
        res = __extract_rule(data[0])
        if res != nomatch:
            return name, res, data[1]
    elif callable(data):
        return __extract_rule_action(data(), data.__name__)

    raise Err("Don't know how to extract from {}", data)

def __mk_parser(name, rule, action):
    if isinstance(rule, ParseInfo):
        return __mk_fn_parser(name, rule, action)

    raise Err("Do not know what to do with {}", rule)

def mk_parser(top, name = ""):
    return __mk_parser(*__extract_rule_action(top, name))

def __normalize(v):
    if callable(v):
        return v
    if is_str(v):
        fn = lambda: (v, value)
        fn.__name__ = ''.join(('!', v))
        return fn
    raise Err("Don't know how to normalize {}", v)

def r0_inf(test):
    return ParseInfo(_zero_more, __normalize(test))
def r0_1(test):
    return ParseInfo(_0_1, __normalize(test))
def r1_inf(test):
    return ParseInfo(_one_more, __normalize(test))
def seq(*tests):
    return ParseInfo(_match_seq, tests)
def choice(*tests):
    return ParseInfo(_match_any, tests)
def ne(test):
    return ParseInfo(_ne, __normalize(test))
def eof():
    return nomatch, ignore
def sym(c): return ParseInfo(_match_symbol, c) \
        if c == nomatch or len(c) == 1 \
        else ParseInfo(_match_iterable, c)

def lookup(rule):
    def rule_fn():
        return ParseInfo(_lookup, rule), ignore
    rule_fn.__name__ = '_'.join(['lookup', parser.__name__])
    return rule_fn
<|endoftext|>


<commit_before>from __future__ import print_function
from pprint import pprint
from rply import ParserGenerator, LexerGenerator
from rply.token import BaseBox

lg = LexerGenerator()
lg.add("LPAREN", r"\(")
lg.add("RPAREN", r"\)")
lg.add("ATOM", r"[^\s()]+")
lg.ignore(r"\s+")

pg = ParserGenerator(["LPAREN", "RPAREN", "ATOM"])

@pg.error
def error_handler(token):
    raise ValueError("unexpected %s" % token.gettokentype())

@pg.production("main : sexpr")
def main(p):
    return p[0]

@pg.production("sexpr : LPAREN expr RPAREN")
def sexpr(p):
    return BoxSexpr(p[1])

@pg.production("expr : ATOM")
def atom(p):
    return BoxAtom(p[0].getstr())

@pg.production("expr : ATOM sexpr")
@pg.production("expr : ATOM expr")
def sexpr(p):
    return BoxExpr(BoxAtom(p[0].getstr()), p[1])

lexer = lg.build()
parser = pg.build()

class BoxSexpr(BaseBox):
    def __init__(self, expr):
        self.expr = expr

    def expr(self):
        return self.expr

    def __str__(self):
        return "( %s )" % (self.expr)

class BoxExpr(BaseBox):
    def __init__(self, atom, expr):
        self.atom = atom
        self.expr = expr

    def atom(self):
        return self.atom

    def expr(self):
        return self.expr

    def __str__(self):
        return "%s . ( %s )" % (self.atom, self.expr)

class BoxAtom(BaseBox):
    def __init__(self, atom):
        self.atom = atom

    def atom(self):
        return self.atom

    def __str__(self):
        return "%s" % (self.atom)

print(parser.parse(lexer.lex("(+ 1 (* 3 2))")))
<commit_msg>quote + simpler recursive descent (less boxing)<commit_after>from __future__ import print_function
from rply import ParserGenerator, LexerGenerator
from rply.token import BaseBox

lg = LexerGenerator()
lg.add("LPAREN", r"\(")
lg.add("RPAREN", r"\)")
lg.add("QUOTE", r"'")
lg.add("ATOM", r"[^\s()]+")
lg.ignore(r"\s+")

pg = ParserGenerator(["QUOTE", "LPAREN", "RPAREN", "ATOM"])

@pg.error
def error_handler(token):
    type = token.gettokentype()
    pos = token.getsourcepos()
    raise ValueError("unexpected %s at (%s, %s)" %
                     (type, pos.lineno, pos.colno))

@pg.production("main : sexpr")
def main(p):
    return p[0]

@pg.production("sexpr : ATOM")
@pg.production("sexpr : QUOTE sexpr")
@pg.production("sexpr : LPAREN list RPAREN")
def sexpr(p):
    if p[0].gettokentype() == "ATOM":
        return BoxAtom(p[0].getstr())
    elif p[0].gettokentype() == "QUOTE":
        return BoxQuote(p[1])
    else:
        return p[1]

@pg.production("list : sexpr")
@pg.production("list : sexpr list")
def list(p):
    if len(p) == 1:
        return BoxPair(p[0])
    else:
        return BoxPair(p[0], p[1])

lexer = lg.build()
parser = pg.build()

class BoxQuote(BaseBox):
    def __init__(self, sexpr):
        self.sexpr = sexpr

    def sexpr(self):
        return self.sexpr

    def __str__(self):
        return "' %s" % self.sexpr

class BoxPair(BaseBox):
    def __init__(self, x, y=None):
        self.x = x
        self.y = y

    def __str__(self):
        if self.y is None:
            y = "NIL"
        else:
            y = self.y
        return "(%s . %s)" % (self.x, y)

class BoxAtom(BaseBox):
    def __init__(self, atom):
        self.atom = atom

    def atom(self):
        return self.atom

    def __str__(self):
        return "%s" % (self.atom)

print(parser.parse(lexer.lex("1")))
print(parser.parse(lexer.lex("'1")))
print(parser.parse(lexer.lex("+")))
print(parser.parse(lexer.lex("'+")))
print(parser.parse(lexer.lex("(+ 1 2)")))
print(parser.parse(lexer.lex("'(+ 1 2)")))
print(parser.parse(lexer.lex("(+ 1 (* 3 2))")))
print(parser.parse(lexer.lex("'(+ 1 (* 3 2))")))
print(parser.parse(lexer.lex("(+ (* 4 5) (* 3 2))")))
print(parser.parse(lexer.lex("(+ '(* 4 5) (* 3 2))")))
<|endoftext|>


<commit_before>import os
from setuptools import setup

try:
    from pypandoc import convert
    read_md = lambda f: convert(f, 'rst')
except ImportError:
    print("warning: pypandoc module not found, could not convert Markdown to RST")
    read_md = lambda f: open(f, 'r').read()

from gelfclient import __version__
setup(
    name = "gelfclient",
    version = __version__,
    author = "Chris McClymont",
    author_email = "chris@mcclymont.it",
    description = "A UDP client for sending message in the Graylog Extended Log Format (GELF)",
    license = "Apache v2",
    keywords = "gelf, graylog, graylog2, logging",
    url = "http://github.com/orionvm/python-gelfclient",
    packages = ['gelfclient'],
    long_description=read_md('README.md'),
    classifiers=[
        "Development Status :: 3 - Alpha",
        "Topic :: Utilities",
        "Topic :: System :: Logging"
    ],
    setup_requires= [
        'six>=1.9'
    ],
    install_requires=[
        'six>=1.9',
    ],
     test_suite='gelfclient.tests',
)
<commit_msg>Remove unnecessary six dependency<commit_after>import os
from setuptools import setup

try:
    from pypandoc import convert
    read_md = lambda f: convert(f, 'rst')
except ImportError:
    print("warning: pypandoc module not found, could not convert Markdown to RST")
    read_md = lambda f: open(f, 'r').read()

from gelfclient import __version__
setup(
    name = "gelfclient",
    version = __version__,
    author = "Chris McClymont",
    author_email = "chris@mcclymont.it",
    description = "A UDP client for sending message in the Graylog Extended Log Format (GELF)",
    license = "Apache v2",
    keywords = "gelf, graylog, graylog2, logging",
    url = "http://github.com/orionvm/python-gelfclient",
    packages = ['gelfclient'],
    long_description=read_md('README.md'),
    classifiers=[
        "Development Status :: 3 - Alpha",
        "Topic :: Utilities",
        "Topic :: System :: Logging"
    ],
    test_suite='gelfclient.tests',
)
<|endoftext|>