Example #1
0
    def parse(self, spec):
        """Parse a spec string into a populated Spec instance.

        Raise BadSpecError if couldn't parse.
        """
        if os.sep in spec:
            # This is a local thing, let's see what
            if os.path.isdir(spec):
                return Spec(dirname=spec)
            elif os.path.exists(spec):
                return Spec(filename=spec)
            else:
                raise ResourceNotFound(_("cannot find '%s'") % spec)

        # split operator/version and name
        m = re.match(r'(.+?)(?:(==|=|>=|>|<=|<)(.*))?$', spec)
        if m is None:
            raise BadSpecError(
                _("bad format for version specification: '%s'"), spec)

        name = Term(m.group(1))
        op = m.group(2)
        if op == '=':
            op = '=='

        if op is not None:
            ver = SemVer.clean(m.group(3))
        else:
            ver = None

        return Spec(name, op, ver)
Example #2
0
    def parse(self, spec):
        """Parse a spec string into a populated Spec instance.

        Raise BadSpecError if couldn't parse.
        """
        # check if it's a network resource
        if spec.startswith('http://') or spec.startswith('https://'):
            return Spec(url=spec)

        # check if it's a local resource
        if spec.startswith('file://'):
            try_file = unquote_plus(spec[len('file://') :])
        elif os.sep in spec:
            try_file = spec
        else:
            try_file = None

        if try_file:
            # This is a local thing, let's see what
            if os.path.isdir(try_file):
                return Spec(dirname=try_file)
            elif os.path.exists(try_file):
                return Spec(filename=try_file)
            else:
                raise ResourceNotFound(_("cannot find '%s'") % try_file)

        # so we think it's a PGXN spec

        # split operator/version and name
        m = re.match(r'(.+?)(?:(==|=|>=|>|<=|<)(.*))?$', spec)
        if m is None:
            raise BadSpecError(
                _("bad format for version specification: '%s'"), spec
            )

        name = Term(m.group(1))
        op = m.group(2)
        if op == '=':
            op = '=='

        if op is not None:
            ver = SemVer.clean(m.group(3))
        else:
            ver = None

        return Spec(name, op, ver)
Example #3
0
    def parse(self, spec):
        """Parse a spec string into a populated Spec instance.

        Raise BadSpecError if couldn't parse.
        """
        # check if it's a network resource
        if spec.startswith('http://') or spec.startswith('https://'):
            return Spec(url=spec)

        # check if it's a local resource
        if spec.startswith('file://'):
            try_file = urllib.unquote_plus(spec[len('file://'):])
        elif os.sep in spec:
            try_file = spec
        else:
            try_file = None

        if try_file:
            # This is a local thing, let's see what
            if os.path.isdir(try_file):
                return Spec(dirname=try_file)
            elif os.path.exists(try_file):
                return Spec(filename=try_file)
            else:
                raise ResourceNotFound(_("cannot find '%s'") % try_file)

        # so we think it's a PGXN spec

        # split operator/version and name
        m = re.match(r'(.+?)(?:(==|=|>=|>|<=|<)(.*))?$', spec)
        if m is None:
            raise BadSpecError(_("bad format for version specification: '%s'"),
                               spec)

        name = Term(m.group(1))
        op = m.group(2)
        if op == '=':
            op = '=='

        if op is not None:
            ver = SemVer.clean(m.group(3))
        else:
            ver = None

        return Spec(name, op, ver)