Return a tuple of (namespace, name) given a package name. Namespace is the "scope" of a scoped package. / and @ can be url-quoted and will be unquoted. For example: >>> nsn = split_scoped_package_name('@linclark/pkg') >>> assert ('@linclark', 'pkg') == nsn, nsn >>> nsn
(name)
| 1558 | |
| 1559 | |
| 1560 | def split_scoped_package_name(name): |
| 1561 | """ |
| 1562 | Return a tuple of (namespace, name) given a package name. |
| 1563 | Namespace is the "scope" of a scoped package. |
| 1564 | / and @ can be url-quoted and will be unquoted. |
| 1565 | |
| 1566 | For example: |
| 1567 | >>> nsn = split_scoped_package_name('@linclark/pkg') |
| 1568 | >>> assert ('@linclark', 'pkg') == nsn, nsn |
| 1569 | >>> nsn = split_scoped_package_name('@linclark%2fpkg') |
| 1570 | >>> assert ('@linclark', 'pkg') == nsn, nsn |
| 1571 | >>> nsn = split_scoped_package_name('angular') |
| 1572 | >>> assert (None, 'angular') == nsn, nsn |
| 1573 | >>> nsn = split_scoped_package_name('%40angular%2fthat') |
| 1574 | >>> assert ('@angular', 'that') == nsn, nsn |
| 1575 | >>> nsn = split_scoped_package_name('%40angular') |
| 1576 | >>> assert ('@angular', None) == nsn, nsn |
| 1577 | >>> nsn = split_scoped_package_name('@angular') |
| 1578 | >>> assert ('@angular', None) == nsn, nsn |
| 1579 | >>> nsn = split_scoped_package_name('angular/') |
| 1580 | >>> assert (None, 'angular') == nsn, nsn |
| 1581 | >>> nsn = split_scoped_package_name('%2fangular%2f/ ') |
| 1582 | >>> assert (None, 'angular') == nsn, nsn |
| 1583 | """ |
| 1584 | if not name: |
| 1585 | return None, None |
| 1586 | |
| 1587 | name = name and name.strip() |
| 1588 | if not name: |
| 1589 | return None, None |
| 1590 | |
| 1591 | # FIXME: this legacy percent encoding/decoding should no longer be needed |
| 1592 | name = name.replace('%40', '@').replace('%2f', '/').replace('%2F', '/') |
| 1593 | name = name.rstrip('@').strip('/').strip() |
| 1594 | if not name: |
| 1595 | return None, None |
| 1596 | |
| 1597 | # this should never happen: wee only have a scope. |
| 1598 | # TODO: raise an exception? |
| 1599 | if is_scoped_package(name) and '/' not in name: |
| 1600 | return name, None |
| 1601 | |
| 1602 | ns, _, name = name.rpartition('/') |
| 1603 | ns = ns.strip() or None |
| 1604 | name = name.strip() or None |
| 1605 | return ns, name |
| 1606 | |
| 1607 | |
| 1608 | def get_declared_licenses(license_object): |
no test coverage detected