MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / parse_person

Function parse_person

src/packagedcode/npm.py:1901–2009  ·  view source on GitHub ↗

https://docs.npmjs.com/files/package.json#people-fields-author-contributors A "person" is an object with a "name" field and optionally "url" and "email". Return a name, email, url tuple for a person object A person can be in the form: "author": { "name": "Isaac Z. Sch

(person)

Source from the content-addressed store, hash-verified

1899
1900
1901def parse_person(person):
1902 """
1903 https://docs.npmjs.com/files/package.json#people-fields-author-contributors
1904 A "person" is an object with a "name" field and optionally "url" and "email".
1905
1906 Return a name, email, url tuple for a person object
1907 A person can be in the form:
1908 "author": {
1909 "name": "Isaac Z. Schlueter",
1910 "email": "i@izs.me",
1911 "url": "http://blog.izs.me"
1912 },
1913 or in the form:
1914 "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me)",
1915
1916 Both forms are equivalent.
1917
1918 For example:
1919 >>> author = {
1920 ... "name": "Isaac Z. Schlueter",
1921 ... "email": "i@izs.me",
1922 ... "url": "http://blog.izs.me"
1923 ... }
1924 >>> p = parse_person(author)
1925 >>> assert p == (u'Isaac Z. Schlueter', u'i@izs.me', u'http://blog.izs.me')
1926 >>> p = parse_person('Barney Rubble <b@rubble.com> (http://barnyrubble.tumblr.com/)')
1927 >>> assert p == (u'Barney Rubble', u'b@rubble.com', u'http://barnyrubble.tumblr.com/')
1928 >>> p = parse_person('Barney Rubble <none> (none)')
1929 >>> assert p == (u'Barney Rubble', None, None)
1930 >>> p = parse_person('Barney Rubble ')
1931 >>> assert p == (u'Barney Rubble', None, None)
1932 >>> author = {
1933 ... "name": "Isaac Z. Schlueter",
1934 ... "email": ["i@izs.me", "<jo2@todo.com> "],
1935 ... "url": "http://blog.izs.me"
1936 ... }
1937 >>> p = parse_person(author)
1938 >>> assert p == (u'Isaac Z. Schlueter', u'i@izs.me\\njo2@todo.com', u'http://blog.izs.me')
1939 >>> p = parse_person('<b@rubble.com> (http://barnyrubble.tumblr.com/)')
1940 >>> assert p == (None, u'b@rubble.com', u'http://barnyrubble.tumblr.com/')
1941 """
1942 # TODO: detect if this is a person name or a company name e.g. the type?
1943
1944 name = None
1945 email = None
1946 url = None
1947
1948 if isinstance(person, str):
1949 parsed = person_parser(person)
1950 if not parsed:
1951 parsed = person_parser_no_name(person)
1952 if not parsed:
1953 return person, None, None
1954 else:
1955 name = None
1956 email = parsed.group('email')
1957 url = parsed.group('url')
1958 else:

Callers 1

party_mapperFunction · 0.70

Calls 3

groupMethod · 0.80
getMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected