aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-06-17 21:52:42 +0000
committerAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-06-17 21:52:42 +0000
commitdb7bfd57b931bd4ca4c605efd2fd8f069533d8be (patch)
tree7ef6825b0796ee62b7bf46498aca64a19e0d5f5a
parentba8ccc378f9edc8bc94895b7cc3d785338d2cdbb (diff)
downloadpaludis-db7bfd57b931bd4ca4c605efd2fd8f069533d8be.tar.gz
paludis-db7bfd57b931bd4ca4c605efd2fd8f069533d8be.tar.xz
Bring *DepSpec and PortageDepParser up to date.
-rw-r--r--python/Makefile.am5
-rw-r--r--python/dep_spec.cc680
-rw-r--r--python/dep_spec.hh223
-rwxr-xr-xpython/dep_spec_TEST.py72
-rw-r--r--python/portage_dep_parser.cc53
-rwxr-xr-xpython/portage_dep_parser_TEST.py99
6 files changed, 979 insertions, 153 deletions
diff --git a/python/Makefile.am b/python/Makefile.am
index cf6bd22..5bc5abf 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -41,10 +41,10 @@ IF_PYTHON_QA_TESTS =
IF_PYTHON_SOURCES = \
contents.cc \
- dep_spec.cc \
+ dep_spec.hh dep_spec.cc \
eapi.cc \
environment.cc \
- exception.cc \
+ exception.hh exception.cc \
fs_entry.cc \
mask_reasons.cc \
name.cc \
@@ -62,7 +62,6 @@ IF_PYTHON_QA_SOURCES =
EXTRA_DIST = $(IF_PYTHON_TESTS) $(IF_PYTHON_SOURCES) \
$(IF_PYTHON_QA_TESTS) $(IF_PYTHON_QA_SOURCES) \
- exception.hh \
paludis_python.hh \
paludis_python_so.cc \
environment_TEST_setup.sh environment_TEST_cleanup.sh \
diff --git a/python/dep_spec.cc b/python/dep_spec.cc
index b753403..6acb941 100644
--- a/python/dep_spec.cc
+++ b/python/dep_spec.cc
@@ -18,13 +18,585 @@
*/
#include <paludis_python.hh>
+
+#include <dep_spec.hh>
+#include <paludis/dep_tag.hh>
+#include <paludis/version_requirements.hh>
+#include <paludis/util/private_implementation_pattern-impl.hh>
+#include <paludis/util/visitor-impl.hh>
+#include <paludis/util/collection_concrete.hh>
+#include <paludis/util/save.hh>
+#include <paludis/util/stringify.hh>
#include <libwrapiter/libwrapiter_forward_iterator.hh>
-#include <paludis/dep_spec.hh>
+#include <libwrapiter/libwrapiter_output_iterator.hh>
+#include <list>
using namespace paludis;
using namespace paludis::python;
namespace bp = boost::python;
+
+PythonDepSpec::PythonDepSpec()
+{
+}
+
+PythonDepSpec::~PythonDepSpec()
+{
+}
+
+const PythonUseDepSpec *
+PythonDepSpec::as_use_dep_spec() const
+{
+ return 0;
+}
+
+const PythonPackageDepSpec *
+PythonDepSpec::as_package_dep_spec() const
+{
+ return 0;
+}
+
+namespace paludis
+{
+ template<>
+ struct Implementation<PythonCompositeDepSpec>
+ {
+ std::list<tr1::shared_ptr<const PythonDepSpec> > children;
+ };
+
+ template<>
+ struct Implementation<PythonPackageDepSpec>
+ {
+ tr1::shared_ptr<const QualifiedPackageName> package_ptr;
+ tr1::shared_ptr<const CategoryNamePart> category_name_part_ptr;
+ tr1::shared_ptr<const PackageNamePart> package_name_part_ptr;
+ tr1::shared_ptr<VersionRequirements> version_requirements;
+ VersionRequirementsMode version_requirements_mode;
+ tr1::shared_ptr<const SlotName> slot;
+ tr1::shared_ptr<const RepositoryName> repository;
+ tr1::shared_ptr<const UseRequirements> use_requirements;
+ tr1::shared_ptr<const DepTag> tag;
+ const std::string str;
+
+ Implementation(
+ const tr1::shared_ptr<const QualifiedPackageName> & q,
+ const tr1::shared_ptr<const CategoryNamePart> & c,
+ const tr1::shared_ptr<const PackageNamePart> & p,
+ const tr1::shared_ptr<VersionRequirements> & v,
+ const VersionRequirementsMode m,
+ const tr1::shared_ptr<const SlotName> & s,
+ const tr1::shared_ptr<const RepositoryName> & r,
+ const tr1::shared_ptr<const UseRequirements> & u,
+ const tr1::shared_ptr<const DepTag> & t,
+ const std::string & st) :
+ package_ptr(q),
+ category_name_part_ptr(c),
+ package_name_part_ptr(p),
+ version_requirements(v),
+ version_requirements_mode(m),
+ slot(s),
+ repository(r),
+ use_requirements(u),
+ tag(t),
+ str(st)
+ {
+ }
+ };
+}
+
+PythonCompositeDepSpec::PythonCompositeDepSpec() :
+ PrivateImplementationPattern<PythonCompositeDepSpec>(new Implementation<PythonCompositeDepSpec>)
+{
+}
+
+PythonCompositeDepSpec::~PythonCompositeDepSpec()
+{
+}
+
+void
+PythonCompositeDepSpec::add_child(const tr1::shared_ptr<const PythonDepSpec> c)
+{
+ _imp->children.push_back(c);
+}
+
+PythonCompositeDepSpec::Iterator
+PythonCompositeDepSpec::begin() const
+{
+ return Iterator(_imp->children.begin());
+}
+
+PythonCompositeDepSpec::Iterator
+PythonCompositeDepSpec::end() const
+{
+ return Iterator(_imp->children.end());
+}
+
+PythonAnyDepSpec::PythonAnyDepSpec()
+{
+}
+
+PythonAnyDepSpec::PythonAnyDepSpec(const AnyDepSpec &)
+{
+}
+
+PythonAllDepSpec::PythonAllDepSpec()
+{
+}
+
+PythonAllDepSpec::PythonAllDepSpec(const AllDepSpec &)
+{
+}
+
+PythonUseDepSpec::PythonUseDepSpec(const UseFlagName & our_flag, bool is_inverse) :
+ _flag(our_flag),
+ _inverse(is_inverse)
+{
+}
+
+PythonUseDepSpec::PythonUseDepSpec(const UseDepSpec & d) :
+ _flag(d.flag()),
+ _inverse(d.inverse())
+{
+}
+
+const PythonUseDepSpec *
+PythonUseDepSpec::as_use_dep_spec() const
+{
+ return this;
+}
+
+UseFlagName
+PythonUseDepSpec::flag() const
+{
+ return _flag;
+}
+
+bool
+PythonUseDepSpec::inverse() const
+{
+ return _inverse;
+}
+
+PythonStringDepSpec::PythonStringDepSpec(const std::string & s) :
+ _str(s)
+{
+}
+
+PythonStringDepSpec::PythonStringDepSpec(const StringDepSpec & d) :
+ _str(d.text())
+{
+}
+
+PythonStringDepSpec::~PythonStringDepSpec()
+{
+}
+
+void
+PythonStringDepSpec::set_text(const std::string & t)
+{
+ _str = t;
+}
+
+std::string
+PythonStringDepSpec::text() const
+{
+ return _str;
+}
+
+template <typename T_>
+tr1::shared_ptr<T_>
+deep_copy(const tr1::shared_ptr<const T_> & x)
+{
+ if (x)
+ return tr1::shared_ptr<T_>(new T_(*x));
+ else
+ return tr1::shared_ptr<T_>();
+}
+
+PythonPackageDepSpec::PythonPackageDepSpec(const PackageDepSpec & p) :
+ PythonStringDepSpec(p.text()),
+ PrivateImplementationPattern<PythonPackageDepSpec>(new Implementation<PythonPackageDepSpec>(
+ deep_copy(p.package_ptr()),
+ deep_copy(p.category_name_part_ptr()),
+ deep_copy(p.package_name_part_ptr()),
+ tr1::shared_ptr<VersionRequirements>(new VersionRequirements::Concrete),
+ p.version_requirements_mode(),
+ deep_copy(p.slot_ptr()),
+ deep_copy(p.repository_ptr()),
+ deep_copy(p.use_requirements_ptr()),
+ tr1::shared_ptr<const DepTag>(p.tag()),
+ stringify(p)))
+{
+ if (p.version_requirements_ptr())
+ {
+ std::copy(p.version_requirements_ptr()->begin(), p.version_requirements_ptr()->end(),
+ _imp->version_requirements->inserter());
+ }
+}
+
+PythonPackageDepSpec::PythonPackageDepSpec(const PythonPackageDepSpec & p) :
+ PythonStringDepSpec(p.text()),
+ PrivateImplementationPattern<PythonPackageDepSpec>(new Implementation<PythonPackageDepSpec>(
+ deep_copy(p.package_ptr()),
+ deep_copy(p.category_name_part_ptr()),
+ deep_copy(p.package_name_part_ptr()),
+ tr1::shared_ptr<VersionRequirements>(new VersionRequirements::Concrete),
+ p.version_requirements_mode(),
+ deep_copy(p.slot_ptr()),
+ deep_copy(p.repository_ptr()),
+ deep_copy(p.use_requirements_ptr()),
+ tr1::shared_ptr<const DepTag>(p.tag()),
+ p.py_str()))
+{
+ std::copy(p.version_requirements_ptr()->begin(), p.version_requirements_ptr()->end(),
+ _imp->version_requirements->inserter());
+}
+
+PythonPackageDepSpec::~PythonPackageDepSpec()
+{
+}
+
+tr1::shared_ptr<const PythonPackageDepSpec>
+PythonPackageDepSpec::make_from_string(const std::string & ss, const PackageDepSpecParseMode p)
+{
+ return tr1::shared_ptr<PythonPackageDepSpec>(new PythonPackageDepSpec(PackageDepSpec(ss, p)));
+}
+
+const PythonPackageDepSpec *
+PythonPackageDepSpec::as_package_dep_spec() const
+{
+ return this;
+}
+
+const tr1::shared_ptr<const PythonPackageDepSpec>
+PythonPackageDepSpec::without_use_requirements() const
+{
+ PackageDepSpec p(
+ deep_copy(package_ptr()),
+ deep_copy(category_name_part_ptr()),
+ deep_copy(package_name_part_ptr()),
+ tr1::shared_ptr<VersionRequirements>(new VersionRequirements::Concrete),
+ version_requirements_mode(),
+ deep_copy(slot_ptr()),
+ deep_copy(repository_ptr()),
+ deep_copy(use_requirements_ptr()),
+ tr1::shared_ptr<const DepTag>(tag())
+ );
+
+ if (version_requirements_ptr())
+ {
+ std::copy(version_requirements_ptr()->begin(), version_requirements_ptr()->end(),
+ p.version_requirements_ptr()->inserter());
+ }
+
+ return tr1::shared_ptr<PythonPackageDepSpec>(new PythonPackageDepSpec(*p.without_use_requirements()));
+}
+
+tr1::shared_ptr<const QualifiedPackageName>
+PythonPackageDepSpec::package_ptr() const
+{
+ return _imp->package_ptr;
+}
+
+tr1::shared_ptr<const PackageNamePart>
+PythonPackageDepSpec::package_name_part_ptr() const
+{
+ return _imp->package_name_part_ptr;
+}
+
+tr1::shared_ptr<const CategoryNamePart>
+PythonPackageDepSpec::category_name_part_ptr() const
+{
+ return _imp->category_name_part_ptr;
+}
+
+tr1::shared_ptr<const VersionRequirements>
+PythonPackageDepSpec::version_requirements_ptr() const
+{
+ return _imp->version_requirements;
+}
+
+VersionRequirementsMode
+PythonPackageDepSpec::version_requirements_mode() const
+{
+ return _imp->version_requirements_mode;
+}
+
+void
+PythonPackageDepSpec::set_version_requirements_mode(const VersionRequirementsMode m)
+{
+ _imp->version_requirements_mode = m;
+}
+
+tr1::shared_ptr<const SlotName>
+PythonPackageDepSpec::slot_ptr() const
+{
+ return _imp->slot;
+}
+
+tr1::shared_ptr<const RepositoryName>
+PythonPackageDepSpec::repository_ptr() const
+{
+ return _imp->repository;
+}
+
+tr1::shared_ptr<const UseRequirements>
+PythonPackageDepSpec::use_requirements_ptr() const
+{
+ return _imp->use_requirements;
+}
+
+tr1::shared_ptr<const DepTag>
+PythonPackageDepSpec::tag() const
+{
+ return _imp->tag;
+}
+
+std::string
+PythonPackageDepSpec::py_str() const
+{
+ return _imp->str;
+}
+
+void
+PythonPackageDepSpec::set_tag(const tr1::shared_ptr<const DepTag> & s)
+{
+ _imp->tag = s;
+}
+
+PythonPlainTextDepSpec::PythonPlainTextDepSpec(const std::string & s) :
+ PythonStringDepSpec(s)
+{
+}
+
+PythonPlainTextDepSpec::PythonPlainTextDepSpec(const PlainTextDepSpec & d) :
+ PythonStringDepSpec(d.text())
+{
+}
+
+PythonBlockDepSpec::PythonBlockDepSpec(tr1::shared_ptr<const PythonPackageDepSpec> & a) :
+ PythonStringDepSpec("!" + a->text()),
+ _spec(a)
+{
+}
+
+PythonBlockDepSpec::PythonBlockDepSpec(const BlockDepSpec & d) :
+ PythonStringDepSpec(d.text()),
+ _spec(tr1::shared_ptr<const PythonPackageDepSpec>(new PythonPackageDepSpec(*d.blocked_spec())))
+{
+}
+
+tr1::shared_ptr<const PythonPackageDepSpec>
+PythonBlockDepSpec::blocked_spec() const
+{
+ return _spec;
+}
+
+PythonURIDepSpec::PythonURIDepSpec(const std::string & s) :
+ PythonStringDepSpec(s)
+{
+}
+
+PythonURIDepSpec::PythonURIDepSpec(const URIDepSpec & d) :
+ PythonStringDepSpec(d.text())
+{
+}
+
+std::string
+PythonURIDepSpec::original_url() const
+{
+ std::string::size_type p(text().find(" -> "));
+ if (std::string::npos == p)
+ return text();
+ else
+ return text().substr(0, p);
+}
+
+std::string
+PythonURIDepSpec::renamed_url_suffix() const
+{
+ std::string::size_type p(text().find(" -> "));
+ if (std::string::npos == p)
+ return "";
+ else
+ return text().substr(p + 4);
+}
+
+DepSpecVisitor::DepSpecVisitor() :
+ _current_parent(new PythonAllDepSpec())
+{
+}
+
+DepSpecVisitor::~DepSpecVisitor()
+{
+}
+
+void
+DepSpecVisitor::visit_sequence(const AllDepSpec & d,
+ GenericSpecTree::ConstSequenceIterator cur,
+ GenericSpecTree::ConstSequenceIterator end)
+{
+ tr1::shared_ptr<PythonAllDepSpec> py_cds(new PythonAllDepSpec(d));
+ _current_parent->add_child(py_cds);
+ Save<tr1::shared_ptr<PythonCompositeDepSpec> > old_parent(&_current_parent, py_cds);
+ std::for_each(cur, end, accept_visitor(*this));
+}
+
+void
+DepSpecVisitor::visit_sequence(const AnyDepSpec & d,
+ GenericSpecTree::ConstSequenceIterator cur,
+ GenericSpecTree::ConstSequenceIterator end)
+{
+ tr1::shared_ptr<PythonAnyDepSpec> py_cds(new PythonAnyDepSpec(d));
+ _current_parent->add_child(py_cds);
+ Save<tr1::shared_ptr<PythonCompositeDepSpec> > old_parent(&_current_parent, py_cds);
+ std::for_each(cur, end, accept_visitor(*this));
+}
+
+void
+DepSpecVisitor::visit_sequence(const UseDepSpec & d,
+ GenericSpecTree::ConstSequenceIterator cur,
+ GenericSpecTree::ConstSequenceIterator end)
+{
+ tr1::shared_ptr<PythonUseDepSpec> py_cds(new PythonUseDepSpec(d));
+ _current_parent->add_child(py_cds);
+ Save<tr1::shared_ptr<PythonCompositeDepSpec> > old_parent(&_current_parent, py_cds);
+ std::for_each(cur, end, accept_visitor(*this));
+}
+
+void
+DepSpecVisitor::visit_leaf(const PackageDepSpec & d)
+{
+ _current_parent->add_child(tr1::shared_ptr<PythonPackageDepSpec>(new PythonPackageDepSpec(d)));
+}
+
+void
+DepSpecVisitor::visit_leaf(const PlainTextDepSpec & d)
+{
+ _current_parent->add_child(tr1::shared_ptr<PythonPlainTextDepSpec>(new PythonPlainTextDepSpec(d)));
+}
+
+void
+DepSpecVisitor::visit_leaf(const URIDepSpec & d)
+{
+ _current_parent->add_child(tr1::shared_ptr<PythonURIDepSpec>(new PythonURIDepSpec(d)));
+}
+
+void
+DepSpecVisitor::visit_leaf(const BlockDepSpec & d)
+{
+ _current_parent->add_child(tr1::shared_ptr<PythonBlockDepSpec>(new PythonBlockDepSpec(d)));
+}
+
+const tr1::shared_ptr<const PythonDepSpec>
+DepSpecVisitor::result() const
+{
+ return *_current_parent->begin();
+}
+
+template <typename N_>
+struct tree_to_python
+{
+ static PyObject *
+ convert(const N_ & n)
+ {
+ DepSpecVisitor v;
+ n->accept(v);
+ return bp::incref(bp::object(v.result()).ptr());
+ }
+};
+
+template <typename T_>
+void register_tree_to_python()
+{
+ bp::to_python_converter<tr1::shared_ptr<typename T_::ConstItem>,
+ tree_to_python<tr1::shared_ptr<typename T_::ConstItem> > >();
+}
+
+
+struct PackageDepSpecFromPython
+{
+ PackageDepSpecFromPython()
+ {
+ bp::converter::registry::push_back(&convertible, &construct,
+ boost::python::type_id<PackageDepSpec>());
+ }
+
+ static void *
+ convertible(PyObject * obj_ptr)
+ {
+ return obj_ptr;
+ }
+
+ static void
+ construct(PyObject * obj_ptr, bp::converter::rvalue_from_python_stage1_data * data)
+ {
+ typedef bp::converter::rvalue_from_python_storage<PythonPackageDepSpec> Storage;
+ void * storage = reinterpret_cast<Storage *>(data)->storage.bytes;
+ PythonPackageDepSpec p = bp::extract<PythonPackageDepSpec>(obj_ptr);
+ new (storage) PackageDepSpec(
+ deep_copy(p.package_ptr()),
+ deep_copy(p.category_name_part_ptr()),
+ deep_copy(p.package_name_part_ptr()),
+ tr1::shared_ptr<VersionRequirements>(new VersionRequirements::Concrete),
+ p.version_requirements_mode(),
+ deep_copy(p.slot_ptr()),
+ deep_copy(p.repository_ptr()),
+ deep_copy(p.use_requirements_ptr()),
+ tr1::shared_ptr<const DepTag>(p.tag())
+ );
+
+ if (p.version_requirements_ptr())
+ {
+ std::copy(p.version_requirements_ptr()->begin(), p.version_requirements_ptr()->end(),
+ reinterpret_cast<PackageDepSpec *>(storage)->version_requirements_ptr()->inserter());
+ }
+ data->convertible = storage;
+ }
+};
+
+struct PackageDepSpecSPFromPython
+{
+ PackageDepSpecSPFromPython()
+ {
+ bp::converter::registry::push_back(&convertible, &construct,
+ boost::python::type_id<tr1::shared_ptr<const PackageDepSpec> >());
+ }
+
+ static void *
+ convertible(PyObject * obj_ptr)
+ {
+ return obj_ptr;
+ }
+
+ static void
+ construct(PyObject * obj_ptr, bp::converter::rvalue_from_python_stage1_data * data)
+ {
+ typedef bp::converter::rvalue_from_python_storage<PythonPackageDepSpec> Storage;
+ void * storage = reinterpret_cast<Storage *>(data)->storage.bytes;
+
+ PythonPackageDepSpec p = bp::extract<PythonPackageDepSpec>(obj_ptr);
+
+ new (storage) tr1::shared_ptr<PackageDepSpec>(new PackageDepSpec(
+ deep_copy(p.package_ptr()),
+ deep_copy(p.category_name_part_ptr()),
+ deep_copy(p.package_name_part_ptr()),
+ tr1::shared_ptr<VersionRequirements>(new VersionRequirements::Concrete),
+ p.version_requirements_mode(),
+ deep_copy(p.slot_ptr()),
+ deep_copy(p.repository_ptr()),
+ deep_copy(p.use_requirements_ptr()),
+ tr1::shared_ptr<const DepTag>(p.tag())
+ ));
+ if (p.version_requirements_ptr())
+ {
+ std::copy(p.version_requirements_ptr()->begin(), p.version_requirements_ptr()->end(),
+ (*reinterpret_cast<tr1::shared_ptr<PackageDepSpec> *>(storage))->version_requirements_ptr()->inserter());
+ }
+ data->convertible = storage;
+ }
+};
+
void PALUDIS_VISIBLE expose_dep_spec()
{
ExceptionRegister::get_instance()->add_exception<PackageDepSpecError>
@@ -32,36 +604,50 @@ void PALUDIS_VISIBLE expose_dep_spec()
enum_auto("PackageDepSpecParseMode", last_pds_pm);
- register_shared_ptrs_to_python<DepSpec>();
- bp::class_<DepSpec, boost::noncopyable>
+ register_tree_to_python<DependencySpecTree>();
+ register_tree_to_python<ProvideSpecTree>();
+ register_tree_to_python<RestrictSpecTree>();
+ register_tree_to_python<URISpecTree>();
+ register_tree_to_python<LicenseSpecTree>();
+
+ register_shared_ptrs_to_python<PythonDepSpec>();
+ bp::class_<PythonDepSpec, boost::noncopyable>
ds("DepSpec",
"Base class for a dependency spec.",
bp::no_init
);
- ds.def("as_use_dep_spec", &DepSpec::as_use_dep_spec,
+ ds.def("as_use_dep_spec", &PythonDepSpec::as_use_dep_spec,
bp::return_value_policy<bp::reference_existing_object>(),
"as_use_dep_spec() -> UseDepSpec\n"
"Return us as a UseDepSpec, or None if we are not a UseDepSpec."
);
- ds.def("as_package_dep_spec", &DepSpec::as_package_dep_spec,
+ ds.def("as_package_dep_spec", &PythonDepSpec::as_package_dep_spec,
bp::return_value_policy<bp::reference_existing_object>(),
"as_package_dep_spec() -> PackageDepSpec\n"
- "Return us as a PackageDepSpec, or None if we are not a UseDepSpec."
+ "Return us as a PackageDepSpec, or None if we are not a PackageDepSpec."
);
- bp::class_<AnyDepSpec, bp::bases<DepSpec>, boost::noncopyable>
+ register_shared_ptrs_to_python<PythonCompositeDepSpec>();
+ bp::class_<PythonCompositeDepSpec, bp::bases<PythonDepSpec>, boost::noncopyable>
+ cds("CompositeDepSpec",
+ "Iterable class for dependency specs that have a number of child dependency specs.",
+ bp::no_init
+ );
+ cds.def("__iter__", bp::range(&PythonCompositeDepSpec::begin, &PythonCompositeDepSpec::end));
+
+ bp::class_<PythonAnyDepSpec, bp::bases<PythonCompositeDepSpec>, boost::noncopyable>
anyds("AnyDepSpec",
"Represents a \"|| ( )\" dependency block.",
bp::no_init
);
- bp::class_<AllDepSpec, bp::bases<DepSpec>, boost::noncopyable>
+ bp::class_<PythonAllDepSpec, bp::bases<PythonCompositeDepSpec>, boost::noncopyable>
allds("AllDepSpec",
"Represents a ( first second third ) or top level group of dependency specs.",
bp::no_init
);
- bp::class_<UseDepSpec, bp::bases<DepSpec>, boost::noncopyable>
+ bp::class_<PythonUseDepSpec, bp::bases<PythonCompositeDepSpec>, boost::noncopyable>
useds("UseDepSpec",
"Represents a use? ( ) dependency spec.",
bp::no_init
@@ -75,14 +661,20 @@ void PALUDIS_VISIBLE expose_dep_spec()
"Are we a ! flag?"
);
- bp::class_<StringDepSpec, bp::bases<DepSpec>, boost::noncopyable>
+ bp::class_<PythonStringDepSpec, bp::bases<PythonDepSpec>, boost::noncopyable>
strds("StringDepSpec",
"A StringDepSpec represents a non-composite dep spec with an associated piece of text.",
bp::no_init
);
+ strds.add_property("text", &PythonStringDepSpec::text,
+ "[ro] string\n"
+ "Our text."
+ );
bp::to_python_converter<std::pair<const UseFlagName, UseFlagState>,
pair_to_tuple<const UseFlagName, UseFlagState> >();
+
+ register_shared_ptrs_to_python<UseRequirements>();
bp::class_<UseRequirements>
ur("UseRequirements",
"A selection of USE flag requirements.",
@@ -93,67 +685,91 @@ void PALUDIS_VISIBLE expose_dep_spec()
"What state is desired for a particular use flag?"
);
ur.def("__iter__", bp::range(&UseRequirements::begin, &UseRequirements::end));
- register_shared_ptrs_to_python<UseRequirements>();
- bp::class_<PackageDepSpec, tr1::shared_ptr<const PackageDepSpec>, bp::bases<StringDepSpec> >
+
+ PackageDepSpecFromPython();
+ PackageDepSpecSPFromPython();
+ bp::implicitly_convertible<PackageDepSpec, PythonPackageDepSpec>();
+
+ bp::class_<PythonPackageDepSpec, tr1::shared_ptr<const PythonPackageDepSpec>, bp::bases<PythonStringDepSpec> >
pkgds("PackageDepSpec",
"A PackageDepSpec represents a package name (for example, 'app-editors/vim'),"
" possibly with associated version and SLOT restrictions.",
- bp::init<const std::string &, const PackageDepSpecParseMode>(
- "__init__(string, PackageDepSpecParseMode)"
- )
+ bp::no_init
);
- pkgds.add_property("package", &PackageDepSpec::package_ptr,
+ pkgds.def("__init__", bp::make_constructor(&PythonPackageDepSpec::make_from_string),
+ "__init__(string, PackageDepSpecParseMode)"
+ );
+ pkgds.add_property("package", &PythonPackageDepSpec::package_ptr,
"[ro] QualifiedPackageName\n"
"Qualified package name."
);
- pkgds.add_property("package_name_part", &PackageDepSpec::package_name_part_ptr,
+ pkgds.add_property("package_name_part", &PythonPackageDepSpec::package_name_part_ptr,
"[ro] PackageNamePart\n"
"Package name part (may be None)"
);
- pkgds.add_property("category_name_part", &PackageDepSpec::category_name_part_ptr,
+ pkgds.add_property("category_name_part", &PythonPackageDepSpec::category_name_part_ptr,
"[ro] CategoryNamePart\n"
"Category name part (may be None)."
);
- tr1::shared_ptr<const VersionRequirements> (PackageDepSpec::*version_requirements)() const =
- &PackageDepSpec::version_requirements_ptr;
- pkgds.add_property("version_requirements", version_requirements,
+ pkgds.add_property("version_requirements", &PythonPackageDepSpec::version_requirements_ptr,
"[ro] VersionRequirements\n"
"Version requirements (may be None)."
);
- pkgds.add_property("version_requirements_mode", &PackageDepSpec::version_requirements_mode,
+ pkgds.add_property("version_requirements_mode", &PythonPackageDepSpec::version_requirements_mode,
"[ro] VersionRequirementsMode\n"
"Version requirements mode."
);
- pkgds.add_property("slot", &PackageDepSpec::slot_ptr,
+ pkgds.add_property("slot", &PythonPackageDepSpec::slot_ptr,
"[ro] SlotName\n"
"Slot name (may be None)."
);
- pkgds.add_property("repository", &PackageDepSpec::repository_ptr,
+ pkgds.add_property("repository", &PythonPackageDepSpec::repository_ptr,
"[ro] RepositoryName\n"
"Repository name (may be None)."
);
- pkgds.add_property("use_requirements", &PackageDepSpec::use_requirements_ptr,
+ pkgds.add_property("use_requirements", &PythonPackageDepSpec::use_requirements_ptr,
"[ro] UseRequirements\n"
"Use requirements (may be None)."
- );
- pkgds.def(bp::self_ns::str(bp::self));
+ );
+ pkgds.def("without_use_requirements", &PythonPackageDepSpec::without_use_requirements,
+ "without_use_requirements() -> PackageDepSpec\n"
+ "Fetch a copy of ourself without the USE requirements."
+ );
+ pkgds.def("__str__", &PythonPackageDepSpec::py_str);
- bp::class_<PlainTextDepSpec, bp::bases<StringDepSpec>, boost::noncopyable >
+ bp::class_<PythonPlainTextDepSpec, bp::bases<PythonStringDepSpec>, boost::noncopyable>
ptds("PlainTextDepSpec",
"A PlainTextDepSpec represents a plain text entry (for example, a URI in SRC_URI).",
bp::init<const std::string &>("__init__(string)")
);
- ptds.def(bp::self_ns::str(bp::self));
+ ptds.def("__str__", &PythonPlainTextDepSpec::text);
- bp::class_<BlockDepSpec, bp::bases<StringDepSpec>, boost::noncopyable >
+ bp::class_<PythonURIDepSpec, bp::bases<PythonStringDepSpec>, boost::noncopyable>
+ uds("URIDepSpec",
+ "A URIDepSpec represents a URI part.",
+ bp::init<const std::string &>("__init__(str)")
+ );
+ uds.add_property("original_url", &PythonURIDepSpec::original_url,
+ "[ro] str"
+ );
+ uds.add_property("renamed_url_suffix", &PythonURIDepSpec::renamed_url_suffix,
+ "[ro] str"
+ );
+
+ bp::class_<PythonBlockDepSpec, bp::bases<PythonStringDepSpec>, boost::noncopyable >
bds("BlockDepSpec",
- "A BlockDepSpec represents a block on a package name (for example, 'app-editors/vim'),"
+ "A BlockDepSpec represents a block on a package name (for example, 'app-editors/vim'), \n"
"possibly with associated version and SLOT restrictions.",
bp::init<tr1::shared_ptr<const PackageDepSpec> >("__init__(PackageDepSpec)")
);
- bds.add_property("blocked_spec", &BlockDepSpec::blocked_spec,
+ bds.add_property("blocked_spec", &PythonBlockDepSpec::blocked_spec,
"[ro] PackageDepSpec\n"
"The spec we're blocking."
);
+ //Work around epydoc bug - http://sf.net/tracker/index.php?func=detail&aid=1738417&group_id=32455&atid=405618
+ bds.add_property("text", &PythonBlockDepSpec::text,
+ "[ro] string\n"
+ "Our text."
+ );
}
diff --git a/python/dep_spec.hh b/python/dep_spec.hh
new file mode 100644
index 0000000..943f3c5
--- /dev/null
+++ b/python/dep_spec.hh
@@ -0,0 +1,223 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Piotr Jaroszyński <peper@gentoo.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_PYTHON_DEP_SPEC_HH
+#define PALUDIS_GUARD_PYTHON_DEP_SPEC_HH 1
+
+#include <paludis/dep_spec.hh>
+
+namespace paludis
+{
+ namespace python
+ {
+ class PythonDepSpec;
+ class PythonPackageDepSpec;
+ class PythonPlainTextDepSpec;
+ class PythonURIDepSpec;
+ class PythonAllDepSpec;
+ class PythonAnyDepSpec;
+ class PythonUseDepSpec;
+ class PythonBlockDepSpec;
+
+ class PALUDIS_VISIBLE PythonDepSpec :
+ private InstantiationPolicy<PythonDepSpec, instantiation_method::NonCopyableTag>
+ {
+ protected:
+ PythonDepSpec();
+
+ public:
+ virtual ~PythonDepSpec();
+
+ virtual const PythonUseDepSpec * as_use_dep_spec() const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+
+ virtual const PythonPackageDepSpec * as_package_dep_spec() const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+ };
+
+ class PALUDIS_VISIBLE PythonCompositeDepSpec :
+ public PythonDepSpec,
+ private PrivateImplementationPattern<PythonCompositeDepSpec>
+ {
+ protected:
+ PythonCompositeDepSpec();
+
+ public:
+ ~PythonCompositeDepSpec();
+
+ void add_child(const tr1::shared_ptr<const PythonDepSpec>);
+
+ typedef libwrapiter::ForwardIterator<PythonCompositeDepSpec,
+ const tr1::shared_ptr<const PythonDepSpec> > Iterator;
+
+ Iterator begin() const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+ Iterator end() const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+ };
+
+ class PALUDIS_VISIBLE PythonAnyDepSpec :
+ public PythonCompositeDepSpec
+ {
+ public:
+ PythonAnyDepSpec();
+ PythonAnyDepSpec(const AnyDepSpec &);
+ };
+
+ class PALUDIS_VISIBLE PythonAllDepSpec :
+ public PythonCompositeDepSpec
+ {
+ public:
+ PythonAllDepSpec();
+ PythonAllDepSpec(const AllDepSpec &);
+ };
+
+ class PALUDIS_VISIBLE PythonUseDepSpec :
+ public PythonCompositeDepSpec
+ {
+ private:
+ const UseFlagName _flag;
+ const bool _inverse;
+
+ public:
+ PythonUseDepSpec(const UseFlagName &, bool);
+ PythonUseDepSpec(const UseDepSpec &);
+
+ UseFlagName flag() const;
+ bool inverse() const;
+ virtual const PythonUseDepSpec * as_use_dep_spec() const;
+ };
+
+ class PALUDIS_VISIBLE PythonStringDepSpec :
+ public PythonDepSpec
+ {
+ private:
+ std::string _str;
+
+ protected:
+ PythonStringDepSpec(const std::string &);
+ PythonStringDepSpec(const StringDepSpec &);
+ ~PythonStringDepSpec();
+
+ void set_text(const std::string &);
+
+ public:
+ std::string text() const;
+ };
+
+ class PALUDIS_VISIBLE PythonPackageDepSpec :
+ public PythonStringDepSpec,
+ private PrivateImplementationPattern<PythonPackageDepSpec>
+ {
+ public:
+ PythonPackageDepSpec(const PackageDepSpec &);
+ PythonPackageDepSpec(const PythonPackageDepSpec &);
+ ~PythonPackageDepSpec();
+
+ static tr1::shared_ptr<const PythonPackageDepSpec>
+ make_from_string(const std::string &, const PackageDepSpecParseMode);
+
+ tr1::shared_ptr<const QualifiedPackageName> package_ptr() const;
+ tr1::shared_ptr<const PackageNamePart> package_name_part_ptr() const;
+ tr1::shared_ptr<const CategoryNamePart> category_name_part_ptr() const;
+ tr1::shared_ptr<const VersionRequirements> version_requirements_ptr() const;
+ VersionRequirementsMode version_requirements_mode() const;
+ void set_version_requirements_mode(const VersionRequirementsMode m);
+ tr1::shared_ptr<const SlotName> slot_ptr() const;
+ tr1::shared_ptr<const RepositoryName> repository_ptr() const;
+ tr1::shared_ptr<const UseRequirements> use_requirements_ptr() const;
+ tr1::shared_ptr<const DepTag> tag() const;
+ void set_tag(const tr1::shared_ptr<const DepTag> & s);
+ const tr1::shared_ptr<const PythonPackageDepSpec> without_use_requirements() const;
+
+ std::string py_str() const;
+
+ virtual const PythonPackageDepSpec * as_package_dep_spec() const;
+ };
+
+ class PALUDIS_VISIBLE PythonPlainTextDepSpec :
+ public PythonStringDepSpec
+ {
+ public:
+ PythonPlainTextDepSpec(const std::string &);
+ PythonPlainTextDepSpec(const PlainTextDepSpec &);
+ };
+
+ class PALUDIS_VISIBLE PythonURIDepSpec :
+ public PythonStringDepSpec
+ {
+ public:
+ PythonURIDepSpec(const std::string &);
+ PythonURIDepSpec(const URIDepSpec &);
+
+ std::string original_url() const;
+ std::string renamed_url_suffix() const;
+ };
+
+ class PALUDIS_VISIBLE PythonBlockDepSpec :
+ public PythonStringDepSpec
+ {
+ private:
+ tr1::shared_ptr<const PythonPackageDepSpec> _spec;
+
+ public:
+ PythonBlockDepSpec(tr1::shared_ptr<const PythonPackageDepSpec> &);
+ PythonBlockDepSpec(const BlockDepSpec &);
+
+ tr1::shared_ptr<const PythonPackageDepSpec> blocked_spec() const;
+ };
+
+ class DepSpecVisitor :
+ public ConstVisitor<GenericSpecTree>,
+ private InstantiationPolicy<DepSpecVisitor, instantiation_method::NonCopyableTag>
+ {
+ private:
+ tr1::shared_ptr<PythonCompositeDepSpec> _current_parent;
+
+ public:
+ DepSpecVisitor();
+
+ virtual ~DepSpecVisitor();
+
+ const tr1::shared_ptr<const PythonDepSpec> result() const;
+
+ void visit_sequence(const AllDepSpec &,
+ GenericSpecTree::ConstSequenceIterator,
+ GenericSpecTree::ConstSequenceIterator);
+
+ void visit_sequence(const AnyDepSpec &,
+ GenericSpecTree::ConstSequenceIterator,
+ GenericSpecTree::ConstSequenceIterator);
+
+ void visit_sequence(const UseDepSpec &,
+ GenericSpecTree::ConstSequenceIterator,
+ GenericSpecTree::ConstSequenceIterator);
+
+ void visit_leaf(const PackageDepSpec &);
+
+ void visit_leaf(const PlainTextDepSpec &);
+
+ void visit_leaf(const BlockDepSpec &);
+
+ void visit_leaf(const URIDepSpec &);
+ };
+ }
+}
+
+#endif
diff --git a/python/dep_spec_TEST.py b/python/dep_spec_TEST.py
index ac6a194..35051f6 100755
--- a/python/dep_spec_TEST.py
+++ b/python/dep_spec_TEST.py
@@ -68,38 +68,46 @@ class TestCase_1_DepSpecs(unittest.TestCase):
self.get_depspecs()
self.assertEquals(self.pds.version_requirements_mode, VersionRequirementsMode.AND)
-# def test_09_use_requirements(self):
-# spec = PortageDepParser.parse_depend("foo/monkey[foo]", PackageDepSpecParseMode.PERMISSIVE)
-# ur = iter(iter(spec).next().use_requirements).next()
-# self.assertEquals(str(ur[0]), "foo")
-# self.assertEquals(ur[1], UseFlagState.ENABLED)
-#
-# def test_10_composites(self):
-# spec = PortageDepParser.parse_depend("|| ( foo/bar foo/baz ) foo/monkey",
-# PackageDepSpecParseMode.PERMISSIVE)
-#
-# self.assert_(isinstance(spec, CompositeDepSpec))
-# self.assert_(isinstance(spec, AllDepSpec))
-#
-# self.assertEqual(len(list(spec)), 2)
-#
-# for i, subspec1 in enumerate(spec):
-# if i == 0:
-# self.assert_(isinstance(subspec1, AnyDepSpec))
-# for j, subspec2 in enumerate(subspec1):
-# if j == 0:
-# self.assert_(isinstance(subspec2, PackageDepSpec))
-# self.assertEquals(str(subspec2), "foo/bar")
-# elif j == 1:
-# self.assert_(isinstance(subspec2, PackageDepSpec))
-# self.assertEquals(str(subspec2), "foo/baz")
-# else:
-# self.assertEquals("Too many items", "OK")
-# elif i == 1:
-# self.assert_(isinstance(subspec1, PackageDepSpec))
-# self.assertEquals(str(subspec1), "foo/monkey")
-# else:
-# self.assertEquals("Too many items", "OK")
+ def test_09_use_requirements(self):
+ eapi = EAPIData.instance.eapi_from_string("paludis-1")
+ spec = PortageDepParser.parse_depend("foo/monkey[foo]", eapi)
+ ur = iter(iter(spec).next().use_requirements).next()
+ self.assertEquals(str(ur[0]), "foo")
+ self.assertEquals(ur[1], UseFlagState.ENABLED)
+
+ def test_10_without_use_requirements(self):
+ eapi = EAPIData.instance.eapi_from_string("paludis-1")
+ spec = PortageDepParser.parse_depend("foo/monkey[foo]", eapi)
+ pds = iter(spec).next().without_use_requirements()
+ self.assertEquals(pds.use_requirements, None)
+ self.assertEquals(str(pds), "foo/monkey")
+
+ def test_11_composites(self):
+ eapi = EAPIData.instance.eapi_from_string("0")
+ spec = PortageDepParser.parse_depend("|| ( foo/bar foo/baz ) foo/monkey", eapi)
+
+ self.assert_(isinstance(spec, CompositeDepSpec))
+ self.assert_(isinstance(spec, AllDepSpec))
+
+ self.assertEqual(len(list(spec)), 2)
+
+ for i, subspec1 in enumerate(spec):
+ if i == 0:
+ self.assert_(isinstance(subspec1, AnyDepSpec))
+ for j, subspec2 in enumerate(subspec1):
+ if j == 0:
+ self.assert_(isinstance(subspec2, PackageDepSpec))
+ self.assertEquals(str(subspec2), "foo/bar")
+ elif j == 1:
+ self.assert_(isinstance(subspec2, PackageDepSpec))
+ self.assertEquals(str(subspec2), "foo/baz")
+ else:
+ self.assertEquals("Too many items", "OK")
+ elif i == 1:
+ self.assert_(isinstance(subspec1, PackageDepSpec))
+ self.assertEquals(str(subspec1), "foo/monkey")
+ else:
+ self.assertEquals("Too many items", "OK")
if __name__ == "__main__":
unittest.main()
diff --git a/python/portage_dep_parser.cc b/python/portage_dep_parser.cc
index 38776c4..cb9c44e 100644
--- a/python/portage_dep_parser.cc
+++ b/python/portage_dep_parser.cc
@@ -18,8 +18,10 @@
*/
#include <paludis_python.hh>
+#include <dep_spec.hh>
#include <paludis/portage_dep_parser.hh>
+#include <paludis/eapi.hh>
using namespace paludis;
using namespace paludis::python;
@@ -29,51 +31,42 @@ void PALUDIS_VISIBLE expose_portage_dep_parser()
{
ExceptionRegister::get_instance()->add_exception<DepStringError>
("DepStringError", "BaseException");
+ ExceptionRegister::get_instance()->add_exception<DepStringLexError>
+ ("DepStringLexError", "DepStrinError");
ExceptionRegister::get_instance()->add_exception<DepStringParseError>
("DepStringParseError", "DepStringError");
ExceptionRegister::get_instance()->add_exception<DepStringNestingError>
("DepStringNestingError", "DepStringParseError");
-#if CIARANM_REMOVED_THIS
bp::class_<PortageDepParser, boost::noncopyable>
pdp("PortageDepParser",
"The PortageDepParser converts string representations "
"of a dependency specification into a DepSpec instance.",
bp::no_init
);
- pdp.def("parse", &PortageDepParser::parse,
- "parse(string, Policy) -> CompositeDepSpec\n"
- "Parse a given dependency string, and return an appropriate DepSpec tree."
- );
- pdp.staticmethod("parse");
pdp.def("parse_depend", &PortageDepParser::parse_depend,
- "parse_depend(string, PackageDepSpecParseMode) -> CompositeDepSpec\n"
- "Convenience wrapper for parse for depend strings, for VersionMetadata."
+ "parse_depend(string, EAPI) -> CompositeDepSpec\n"
+ "Parse a dependency heirarchy."
);
pdp.staticmethod("parse_depend");
+ pdp.def("parse_provide", &PortageDepParser::parse_provide,
+ "parse_provide(string, EAPI) -> CompositeDepSpec\n"
+ "Parse a provide heirarchy."
+ );
+ pdp.staticmethod("parse_provide");
+ pdp.def("parse_restrict", &PortageDepParser::parse_restrict,
+ "parse_restrict(string, EAPI) -> CompositeDepSpec\n"
+ "Parse a restrict."
+ );
+ pdp.staticmethod("parse_restrict");
+ pdp.def("parse_uri", &PortageDepParser::parse_uri,
+ "parse_uri(string, EAPI) -> CompositeDepSpec\n"
+ "Parse a uri heirarchy."
+ );
+ pdp.staticmethod("parse_uri");
pdp.def("parse_license", &PortageDepParser::parse_license,
- "parse_license(string) -> CompositeDepSpec\n"
- "Convenience wrapper for parse for license strings, for VersionMetadata."
+ "parse_license(string, EAPI) -> CompositeDepSpec\n"
+ "Parse a license heirarchy."
);
pdp.staticmethod("parse_license");
-
- bp::scope s = pdp;
- bp::class_<PortageDepParser::Policy>
- pdpp("Policy",
- "The Policy class describes how to convert a string representation"
- "of a dependency specification into a DepSpec instance.",
- bp::no_init
- );
- pdpp.def("text_is_text_dep_spec", &PortageDepParser::Policy::text_is_text_dep_spec,
- "text_is_text_dep_spec(permit_any_deps_boolean) -> Policy\n"
- "Returns a new policy for a PlainTextDepSpec."
- );
- pdpp.staticmethod("text_is_text_dep_spec");
- pdpp.def("text_is_package_dep_spec", &PortageDepParser::Policy::text_is_package_dep_spec,
- "text_is_package_dep_spec(permit_any_deps_boolean, PackageDepSpecParseMode) -> Policy\n"
- "Returns a new policy for a PackageDepSpec."
- );
- pdpp.staticmethod("text_is_package_dep_spec");
- pdpp.add_property("permit_any_deps", &PortageDepParser::Policy::permit_any_deps);
-#endif
}
diff --git a/python/portage_dep_parser_TEST.py b/python/portage_dep_parser_TEST.py
index 6988fe6..ac51fe3 100755
--- a/python/portage_dep_parser_TEST.py
+++ b/python/portage_dep_parser_TEST.py
@@ -21,62 +21,49 @@
from paludis import *
import unittest
-#class TestCase_01_PortageDepParser_Policy(unittest.TestCase):
-# def test_01_init_error(self):
-# self.assertRaises(Exception, PortageDepParser.Policy)
-#
-# def test_02_create_text(self):
-# PortageDepParser.Policy.text_is_text_dep_spec(True)
-#
-# def test_03_create_package(self):
-# PortageDepParser.Policy.text_is_package_dep_spec(True, PackageDepSpecParseMode.PERMISSIVE)
-#
-#class TestCase_02_PortageDepParser(unittest.TestCase):
-# def get_policies(self):
-# self.text_true = PortageDepParser.Policy.text_is_text_dep_spec(True)
-# self.text_false = PortageDepParser.Policy.text_is_text_dep_spec(False)
-# self.package_true = PortageDepParser.Policy.text_is_package_dep_spec(True, PackageDepSpecParseMode.PERMISSIVE)
-# self.package_false = PortageDepParser.Policy.text_is_package_dep_spec(False, PackageDepSpecParseMode.PERMISSIVE)
-#
-# def test_01_init_error(self):
-# self.assertRaises(Exception, PortageDepParser)
-#
-# def test_02_parse(self):
-# self.get_policies()
-#
-# spec1 = PortageDepParser.parse("foo/boo", self.text_true)
-# self.assert_(isinstance(spec1, AllDepSpec))
-# self.assert_(isinstance(iter(spec1).next(), PlainTextDepSpec))
-# self.assertEquals(len(list(spec1)), 1)
-# self.assertEquals(str(iter(spec1).next()), "foo/boo")
-#
-# spec2 = PortageDepParser.parse("foo/boo", self.text_false)
-# self.assert_(isinstance(spec2, AllDepSpec))
-# self.assert_(isinstance(iter(spec2).next(), PlainTextDepSpec))
-# self.assertEquals(len(list(spec2)), 1)
-# self.assertEquals(str(iter(spec2).next()), "foo/boo")
-#
-# spec3 = PortageDepParser.parse("foo/boo", self.package_true)
-# self.assert_(isinstance(spec3, AllDepSpec))
-# self.assert_(isinstance(iter(spec3).next(), PackageDepSpec))
-# self.assertEquals(len(list(spec3)), 1)
-# self.assertEquals(str(iter(spec3).next()), "foo/boo")
-#
-# spec4 = PortageDepParser.parse("foo/boo", self.package_false)
-# self.assert_(isinstance(spec4, AllDepSpec))
-# self.assert_(isinstance(iter(spec4).next(), PackageDepSpec))
-# self.assertEquals(len(list(spec4)), 1)
-# self.assertEquals(str(iter(spec4).next()), "foo/boo")
-#
-# PortageDepParser.parse("|| ( foo/boo )", self.text_true)
-# PortageDepParser.parse("|| ( foo/boo )", self.package_true)
-#
-# def test_03_exceptions(self):
-# self.get_policies()
-#
-# self.assertRaises(DepStringParseError, PortageDepParser.parse, "|| ( foo/boo )", self.text_false)
-# self.assertRaises(DepStringParseError, PortageDepParser.parse, "|| ( foo/boo )", self.package_false)
-# self.assertRaises(DepStringNestingError, PortageDepParser.parse, "|| ( foo/boo", self.package_true)
+class TestCase_01_PortageDepParser(unittest.TestCase):
+ def setUp(self):
+ global eapi
+ eapi = EAPIData.instance.eapi_from_string("0")
+
+ def test_01_init_error(self):
+ self.assertRaises(Exception, PortageDepParser)
+
+ def test_02_parse_depend(self):
+ spec = PortageDepParser.parse_depend("foo/boo", eapi)
+ self.assert_(isinstance(spec, AllDepSpec))
+ self.assert_(isinstance(iter(spec).next(), PackageDepSpec))
+ self.assertEquals(len(list(spec)), 1)
+
+ def test_03_parse_provide(self):
+ spec = PortageDepParser.parse_provide("foo/boo", eapi)
+ self.assert_(isinstance(spec, AllDepSpec))
+ self.assert_(isinstance(iter(spec).next(), PackageDepSpec))
+ self.assertEquals(len(list(spec)), 1)
+
+ def test_04_parse_restrict(self):
+ spec = PortageDepParser.parse_restrict("foo/boo", eapi)
+ self.assert_(isinstance(spec, AllDepSpec))
+ self.assert_(isinstance(iter(spec).next(), PlainTextDepSpec))
+ self.assertEquals(len(list(spec)), 1)
+
+ def test_05_parse_uri(self):
+ spec = PortageDepParser.parse_uri("http://foo/boo", eapi)
+ self.assert_(isinstance(spec, AllDepSpec))
+ self.assert_(isinstance(iter(spec).next(), URIDepSpec))
+ self.assertEquals(len(list(spec)), 1)
+
+
+ def test_06_parse_license(self):
+ spec = PortageDepParser.parse_license("FOO_LICENSE", eapi)
+ self.assert_(isinstance(spec, AllDepSpec))
+ self.assert_(isinstance(iter(spec).next(), PlainTextDepSpec))
+ self.assertEquals(len(list(spec)), 1)
+
+ def test_07_exceptions(self):
+ self.assertRaises(DepStringLexError, PortageDepParser.parse_depend, "(foo/boo )", eapi)
+ self.assertRaises(DepStringNestingError, PortageDepParser.parse_license, "|| ( foo/boo ", eapi)
+ self.assertRaises(DepStringParseError, PortageDepParser.parse_provide, "|| ( foo/boo )", eapi)
if __name__ == "__main__":
unittest.main()