Esempio n. 1
0
def setup_html():
    global etree
    try:
        from lxml import etree
    except ImportError:
        print("can't validate the XHTML parts in Jinja2 templates"
              " (no lxml installed)")

    if etree and pv(etree.__version__) < pv('2.0.0'):
        # 2.0.7 and 2.1.x are known to work.
        print("can't validate the XHTML parts in Jinja2 templates"
              " (lxml < 2.0, api incompatibility)")

    if etree:
        # Note: this code derived from trac/tests/functional (FIXME)

        class Resolver(etree.Resolver):
            # ./contrib/jinjachecker.py # <- we live here
            # ./trac/tests/functional/  # <- there are the DTDs
            contrib_dir = dirname(abspath(__file__))
            base_dir = normpath(join(contrib_dir, '../trac/tests/functional'))

            def resolve(self, system_url, public_id, context):
                filename = join(self.base_dir, system_url.split("/")[-1])
                return self.resolve_filename(filename, context)

        parser = etree.XMLParser(dtd_validation=True)
        parser.resolvers.add(Resolver())
        etree.set_default_parser(parser)
    return etree
Esempio n. 2
0
def importorskip(modname, minversion=None):
    """ return imported module if it has at least "minversion" as its
    __version__ attribute.  If no minversion is specified the a skip
    is only triggered if the module can not be imported.
    """
    __tracebackhide__ = True
    compile(modname, '', 'eval') # to catch syntaxerrors
    should_skip = False
    try:
        __import__(modname)
    except ImportError:
        # Do not raise chained exception here(#1485)
        should_skip = True
    if should_skip:
        raise Skipped("could not import %r" %(modname,), allow_module_level=True)
    mod = sys.modules[modname]
    if minversion is None:
        return mod
    verattr = getattr(mod, '__version__', None)
    if minversion is not None:
        try:
            from pkg_resources import parse_version as pv
        except ImportError:
            raise Skipped("we have a required version for %r but can not import "
                          "pkg_resources to parse version strings." % (modname,),
                          allow_module_level=True)
        if verattr is None or pv(verattr) < pv(minversion):
            raise Skipped("module %r has __version__ %r, required is: %r" %(
                          modname, verattr, minversion), allow_module_level=True)
    return mod
Esempio n. 3
0
 def _update_release(self, prj, path):
     prj.releases.all().delete()
     
     self.logger.info("update project release....")
     release_list = []
     
     project_name = os.path.basename(path)        
     for name in os.listdir(path):
         if not name.startswith(project_name): continue
         file, ext = os.path.splitext(name)
         if ext not in ['.zip', '.gz', ]: continue
         if "-" not in file: continue
         xx, version = file.split("-", 1)
         #version = x.replace("-%s" % project_name, "")
         
         #self._update_release(prj, path)
         self.logger.info("version:%s-->%s" % (version, name))
         release_list.append(Release(version=version,
                                     path=name))
         
     from pkg_resources import parse_version as pv
     release_list.sort(lambda x, y: cmp(pv(x.version), pv(y.version)), )
     
     for i in range(len(release_list)):
         release_list[i].release_order = i
         release_list[i].project = prj
         release_list[i].save()
     
     if len(release_list) > 0:
         prj.last_version = release_list[-1].version
     else:
         prj.last_version = None 
Esempio n. 4
0
def importorskip(modname, minversion=None):
    """ return imported module if it has at least "minversion" as its
    __version__ attribute.  If no minversion is specified the a skip
    is only triggered if the module can not be imported.
    """
    __tracebackhide__ = True
    compile(modname, "", "eval")  # to catch syntaxerrors
    try:
        __import__(modname)
    except ImportError:
        skip("could not import %r" % (modname,))
    mod = sys.modules[modname]
    if minversion is None:
        return mod
    verattr = getattr(mod, "__version__", None)
    if minversion is not None:
        try:
            from pkg_resources import parse_version as pv
        except ImportError:
            skip(
                "we have a required version for %r but can not import "
                "no pkg_resources to parse version strings." % (modname,)
            )
        if verattr is None or pv(verattr) < pv(minversion):
            skip("module %r has __version__ %r, required is: %r" % (modname, verattr, minversion))
    return mod
def importorskip(modname, minversion=None):
    """ return imported module if it has at least "minversion" as its
    __version__ attribute.  If no minversion is specified the a skip
    is only triggered if the module can not be imported.
    """
    __tracebackhide__ = True
    compile(modname, '', 'eval') # to catch syntaxerrors
    should_skip = False
    try:
        __import__(modname)
    except ImportError:
        # Do not raise chained exception here(#1485)
        should_skip = True
    if should_skip:
        raise Skipped("could not import %r" %(modname,), allow_module_level=True)
    mod = sys.modules[modname]
    if minversion is None:
        return mod
    verattr = getattr(mod, '__version__', None)
    if minversion is not None:
        try:
            from pkg_resources import parse_version as pv
        except ImportError:
            raise Skipped("we have a required version for %r but can not import "
                          "pkg_resources to parse version strings." % (modname,),
                          allow_module_level=True)
        if verattr is None or pv(verattr) < pv(minversion):
            raise Skipped("module %r has __version__ %r, required is: %r" %(
                          modname, verattr, minversion), allow_module_level=True)
    return mod
Esempio n. 6
0
def importorskip(modname, minversion=None, reason=None):
    """Imports and returns the requested module ``modname``, or skip the current test
    if the module cannot be imported.

    :param str modname: the name of the module to import
    :param str minversion: if given, the imported module ``__version__`` attribute must be
        at least this minimal version, otherwise the test is still skipped.
    :param str reason: if given, this reason is shown as the message when the module
        cannot be imported.
    """
    import warnings

    __tracebackhide__ = True
    compile(modname, "", "eval")  # to catch syntaxerrors
    should_skip = False

    with warnings.catch_warnings():
        # make sure to ignore ImportWarnings that might happen because
        # of existing directories with the same name we're trying to
        # import but without a __init__.py file
        warnings.simplefilter("ignore")
        try:
            __import__(modname)
        except ImportError:
            # Do not raise chained exception here(#1485)
            should_skip = True
    if should_skip:
        if reason is None:
            reason = "could not import %r" % (modname, )
        raise Skipped(reason, allow_module_level=True)
    mod = sys.modules[modname]
    if minversion is None:
        return mod
    verattr = getattr(mod, "__version__", None)
    if minversion is not None:
        try:
            from pkg_resources import parse_version as pv
        except ImportError:
            raise Skipped(
                "we have a required version for %r but can not import "
                "pkg_resources to parse version strings." % (modname, ),
                allow_module_level=True,
            )
        if verattr is None or pv(verattr) < pv(minversion):
            raise Skipped(
                "module %r has __version__ %r, required is: %r" %
                (modname, verattr, minversion),
                allow_module_level=True,
            )
    return mod
Esempio n. 7
0
def importorskip(modname, minversion=None, reason=None):
    """Imports and returns the requested module ``modname``, or skip the current test
    if the module cannot be imported.

    :param str modname: the name of the module to import
    :param str minversion: if given, the imported module ``__version__`` attribute must be
        at least this minimal version, otherwise the test is still skipped.
    :param str reason: if given, this reason is shown as the message when the module
        cannot be imported.
    """
    import warnings

    __tracebackhide__ = True
    compile(modname, "", "eval")  # to catch syntaxerrors
    should_skip = False

    with warnings.catch_warnings():
        # make sure to ignore ImportWarnings that might happen because
        # of existing directories with the same name we're trying to
        # import but without a __init__.py file
        warnings.simplefilter("ignore")
        try:
            __import__(modname)
        except ImportError:
            # Do not raise chained exception here(#1485)
            should_skip = True
    if should_skip:
        if reason is None:
            reason = "could not import %r" % (modname,)
        raise Skipped(reason, allow_module_level=True)
    mod = sys.modules[modname]
    if minversion is None:
        return mod
    verattr = getattr(mod, "__version__", None)
    if minversion is not None:
        try:
            from pkg_resources import parse_version as pv
        except ImportError:
            raise Skipped(
                "we have a required version for %r but can not import "
                "pkg_resources to parse version strings." % (modname,),
                allow_module_level=True,
            )
        if verattr is None or pv(verattr) < pv(minversion):
            raise Skipped(
                "module %r has __version__ %r, required is: %r"
                % (modname, verattr, minversion),
                allow_module_level=True,
            )
    return mod
Esempio n. 8
0
def parse_version(version):
    """
    >>> parse_version('foo')
    Traceback (most recent call last):
    ...
    Exception: Bad version foo
    >>> parse_version('0.0.0-foo')
    Traceback (most recent call last):
    ...
    Exception: Bad version 0.0.0-foo
    """
    if isinstance(version, SetuptoolsVersion):
        return version
    matches = re.match('(?P<release>(\d+(\.\d+)+))#(?P<remains>.+)?$', version)
    if matches:
        # 1.2.0#1-rc1 implies -> 1.3.0.a1.dev1
        release = matches.group('release')
        output = increment_release(release)

        remains = matches.group('remains')
        alpha, _, tail = remains.partition('-')
        if tail.startswith('rc'):
            tail = 'dev%s' % tail[2:]
        if alpha:
            output += '.a%s' % alpha
        if tail:
            output += '.%s' % tail
        version = output
    version = pv(version)
    if isinstance(version, SetuptoolsVersion):
        return version
    raise ValueError('Bad version %r' % version)
Esempio n. 9
0
def importorskip(modname, minversion=None):
    """ return imported module if it has at least "minversion" as its
    __version__ attribute.  If no minversion is specified the a skip
    is only triggered if the module can not be imported.
    """
    import warnings

    __tracebackhide__ = True
    compile(modname, "", "eval")  # to catch syntaxerrors
    should_skip = False

    with warnings.catch_warnings():
        # make sure to ignore ImportWarnings that might happen because
        # of existing directories with the same name we're trying to
        # import but without a __init__.py file
        warnings.simplefilter("ignore")
        try:
            __import__(modname)
        except ImportError:
            # Do not raise chained exception here(#1485)
            should_skip = True
    if should_skip:
        raise Skipped("could not import %r" % (modname, ),
                      allow_module_level=True)
    mod = sys.modules[modname]
    if minversion is None:
        return mod
    verattr = getattr(mod, "__version__", None)
    if minversion is not None:
        try:
            from pkg_resources import parse_version as pv
        except ImportError:
            raise Skipped(
                "we have a required version for %r but can not import "
                "pkg_resources to parse version strings." % (modname, ),
                allow_module_level=True,
            )
        if verattr is None or pv(verattr) < pv(minversion):
            raise Skipped(
                "module %r has __version__ %r, required is: %r" %
                (modname, verattr, minversion),
                allow_module_level=True,
            )
    return mod
Esempio n. 10
0
def importorskip(modname, minversion=None):
    """ return imported module if it has at least "minversion" as its
    __version__ attribute.  If no minversion is specified the a skip
    is only triggered if the module can not be imported.
    """
    import warnings

    __tracebackhide__ = True
    compile(modname, "", "eval")  # to catch syntaxerrors
    should_skip = False

    with warnings.catch_warnings():
        # make sure to ignore ImportWarnings that might happen because
        # of existing directories with the same name we're trying to
        # import but without a __init__.py file
        warnings.simplefilter("ignore")
        try:
            __import__(modname)
        except ImportError:
            # Do not raise chained exception here(#1485)
            should_skip = True
    if should_skip:
        raise Skipped("could not import %r" % (modname,), allow_module_level=True)
    mod = sys.modules[modname]
    if minversion is None:
        return mod
    verattr = getattr(mod, "__version__", None)
    if minversion is not None:
        try:
            from pkg_resources import parse_version as pv
        except ImportError:
            raise Skipped(
                "we have a required version for %r but can not import "
                "pkg_resources to parse version strings." % (modname,),
                allow_module_level=True,
            )
        if verattr is None or pv(verattr) < pv(minversion):
            raise Skipped(
                "module %r has __version__ %r, required is: %r"
                % (modname, verattr, minversion),
                allow_module_level=True,
            )
    return mod
Esempio n. 11
0
    # setup short names to reduce typing
    # This twill browser (and the tc commands that use it) are essentially
    # global, and not tied to our test fixture.
    tc = twill.commands
    b = _BrowserProxy()

    # Setup XHTML validation for all retrieved pages
    try:
        from lxml import etree
    except ImportError:
        print("SKIP: validation of XHTML output in functional tests"
              " (no lxml installed)")
        etree = None

    if etree and pv(etree.__version__) < pv('2.0.0'):
        # 2.0.7 and 2.1.x are known to work.
        print("SKIP: validation of XHTML output in functional tests"
              " (lxml < 2.0, api incompatibility)")
        etree = None

    if etree:
        class _Resolver(etree.Resolver):
            base_dir = dirname(abspath(__file__))

            def resolve(self, system_url, public_id, context):
                return self.resolve_filename(join(self.base_dir,
                                                  system_url.split("/")[-1]),
                                             context)

        _parser = etree.XMLParser(dtd_validation=True)
Esempio n. 12
0
""" Extensions to TF RNN class by una_dinosaria"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import tensorflow as tf

from tensorflow.contrib.rnn.python.ops.core_rnn_cell import RNNCell

# The import for LSTMStateTuple changes in TF >= 1.2.0
from pkg_resources import parse_version as pv
if pv(tf.__version__) >= pv('1.2.0'):
    from tensorflow.contrib.rnn import LSTMStateTuple
else:
    from tensorflow.contrib.rnn.python.ops.core_rnn_cell import LSTMStateTuple
del pv


class ResidualWrapper(RNNCell):
    """Operator adding residual connections to a given cell."""
    def __init__(self, cell):
        """Create a cell with added residual connection.
        Args:
            cell: an RNNCell. The input is added to the output.
        Raises:
            TypeError: if cell is not an RNNCell.
        """
        if not isinstance(cell, RNNCell):
            raise TypeError("The parameter cell is not a RNNCell.")
Esempio n. 13
0
def adjustable_box_or_forced():
  "For set_aspect(), adjustable='box-forced' replaced by 'box' since mpl 2.2.0."
  from pkg_resources import parse_version as pv
  return 'box-forced' if pv(mpl.__version__) < pv("2.2.0") else 'box'
Esempio n. 14
0
            setattr(twill.get_browser(), name, value)

    # setup short names to reduce typing
    # This twill browser (and the tc commands that use it) are essentially
    # global, and not tied to our test fixture.
    tc = twill.commands
    b = _BrowserProxy()

    # Setup XHTML validation for all retrieved pages
    try:
        from lxml import etree
    except ImportError:
        print "SKIP: validation of XHTML output in functional tests " "(no lxml installed)"
        etree = None

    if etree and pv(etree.__version__) < pv("2.0.0"):
        # 2.0.7 and 2.1.x are known to work.
        print "SKIP: validation of XHTML output in functional tests " "(lxml < 2.0, api incompatibility)"
        etree = None

    if etree:

        class _Resolver(etree.Resolver):
            base_dir = dirname(abspath(__file__))

            def resolve(self, system_url, public_id, context):
                return self.resolve_filename(join(self.base_dir, system_url.split("/")[-1]), context)

        _parser = etree.XMLParser(dtd_validation=True)
        _parser.resolvers.add(_Resolver())
        etree.set_default_parser(_parser)
Esempio n. 15
0
#        can only be a unicode string and is encoded using the user's default
#        system code-page, e.g. typically CP1250 on eastern European Windows,
#        CP1252 on western European Windows, UTF-8 on Linux or any other)
#      - setuptools 3.5 works around the issue by overriding relevant distutils
#        functionality, allowing the use of non-ASCII characters, but only for
#        Python 3.1
#  * Python 3.2.2+ - unicode string
#      - unicode strings containing non-ASCII characters supported since Python
#        commit fb4d2e6d393e96baac13c4efc216e361bf12c293

can_not_use_non_ASCII_meta_data = (3,) <= sys.version_info < (3, 2, 2)
if (can_not_use_non_ASCII_meta_data and using_setuptools and
        sys.version_info[:2] == (3, 1)):
    from setuptools import __version__ as setuptools_version
    from pkg_resources import parse_version as pv
    can_not_use_non_ASCII_meta_data = pv(setuptools_version) < pv("3.5")

# Wrap long_description at 72 characters since the PKG-INFO package
# distribution metadata file stores this text with an 8 space indentation.
long_description = """
---------------------------------------
Lightweight SOAP client (Jurko's fork).
---------------------------------------

  Based on the original 'suds' project by Jeff Ortel (jortel at redhat
dot com) hosted at 'http://fedorahosted.org/suds'.

  'Suds' is a lightweight SOAP-based web service client for Python
licensed under LGPL (see the LICENSE.txt file included in the
distribution).
Esempio n. 16
0
#        can only be a unicode string and is encoded using the user's default
#        system code-page, e.g. typically CP1250 on eastern European Windows,
#        CP1252 on western European Windows, UTF-8 on Linux or any other)
#      - setuptools 3.5 works around the issue by overriding relevant distutils
#        functionality, allowing the use of non-ASCII characters, but only for
#        Python 3.1
#  * Python 3.2.2+ - unicode string
#      - unicode strings containing non-ASCII characters supported since Python
#        commit fb4d2e6d393e96baac13c4efc216e361bf12c293

can_not_use_non_ASCII_meta_data = (3,) <= sys.version_info < (3, 2, 2)
if (can_not_use_non_ASCII_meta_data and using_setuptools and
        sys.version_info[:2] == (3, 1)):
    from setuptools import __version__ as setuptools_version
    from pkg_resources import parse_version as pv
    can_not_use_non_ASCII_meta_data = pv(setuptools_version) < pv("3.5")

# Wrap long_description at 72 characters since the PKG-INFO package
# distribution metadata file stores this text with an 8 space indentation.
long_description = """
---------------------------------------
Lightweight SOAP client (Community fork).
---------------------------------------

  Based on the original 'suds' project by Jeff Ortel (jortel at redhat
dot com) hosted at 'http://fedorahosted.org/suds'.

  'Suds' is a lightweight SOAP-based web service client for Python
licensed under LGPL (see the LICENSE.txt file included in the
distribution).
"""
Esempio n. 17
0
def main():
    parser = ArgumentParser(
        description='Download and extract external .awb assets')
    parser.add_argument(dest="output",
                        help="Extracted Data Destination (MUST BE A FOLDER)",
                        metavar="OUTPUT")
    parser.add_argument(
        "-r",
        "--region",
        dest="region",
        default="CN",
        help="Choose the region of the assets (EN/CN), default: CN",
        metavar="REGION",
        choices=["EN", "CN"])
    parser.add_argument("-v",
                        "--version",
                        dest="version",
                        default=None,
                        help="Choose the version of the AWB ext_assets",
                        metavar="VERSION")
    parser.add_argument("-t",
                        "--test",
                        action="store_true",
                        dest="test",
                        default=False,
                        help="Test mode, only download 3 files.")
    options = parser.parse_args()

    url = {
        "CN": "http://c.dal.heitao2014.com/dal/ext_assets/release_android/",
        "EN":
        "http://c-ml.datealive.com/dal_global/ext_assets/release_android/"
    }
    # http://c-ml.datealive.com/dal_global/release_android/
    # http://c-dal-ml.heitaoglobal.com/dal_global/release_android/
    url = url[options.region]

    content = urllib.request.urlopen(url).read().decode("utf-8")
    stripped = re.sub('<[^<]+?>', '', content)

    # getting highest version ext_assets
    if options.version is None:
        ver = re.findall(r"(\d.+)\/", stripped)
        ver_pv = [pv(i) for i in ver]
        ver = ver[ver_pv.index(max(ver_pv))]
    else:
        ver = options.version
    # get the file list
    extlist = posixpath.join(ver, "extlist.json")
    filelist = json.loads(
        urllib.request.urlopen(urllib.parse.urljoin(
            url, extlist)).read().decode("utf-8"))
    urls = [(os.path.join(options.output, "dl_tmp", f"{f}.awb"),
             urllib.parse.urljoin(url, posixpath.join(ver, f"{f}.awb")))
            for f in filelist]
    if options.test:
        urls = urls[:3]

    # download external assets
    results = ThreadPool(16).imap_unordered(fetch_url, urls)
    for i in results:
        print(f"Downloaded {i}")

    # extract awb files
    file_list = []
    for root, _, files in os.walk(os.path.join(options.output, "dl_tmp")):
        for name in files:
            file_list.append((os.path.join(root, name), options.output))
    results = ThreadPool(16).imap_unordered(extract_awb, file_list)
    for i, j in results:
        print(f"Extracted {i} to {j}")

    # delete tmp download folder
    rmtree(os.path.join(options.output, "dl_tmp"))