Skip to content

Commit

Permalink
Merge pull request #114 from manu-chroma/master
Browse files Browse the repository at this point in the history
minor refactor: create utils.py
  • Loading branch information
mr-c committed Jun 24, 2017
2 parents d370602 + 8372fe2 commit 9d9317e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 30 deletions.
8 changes: 0 additions & 8 deletions schema_salad/add_dictlist.py

This file was deleted.

11 changes: 0 additions & 11 deletions schema_salad/aslist.py

This file was deleted.

2 changes: 1 addition & 1 deletion schema_salad/jsonld_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from rdflib.namespace import RDF, RDFS
import urlparse
import logging
from .aslist import aslist
from schema_salad.utils import aslist
from typing import (cast, Any, Dict, Iterable, List, Optional, Text, Tuple,
Union)
from .ref_resolver import Loader, ContextType
Expand Down
3 changes: 1 addition & 2 deletions schema_salad/makedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from StringIO import StringIO
import logging
import urlparse
from .aslist import aslist
from .add_dictlist import add_dictlist
from schema_salad.utils import add_dictlist, aslist
import re
import argparse
from typing import cast, Any, Dict, IO, List, Optional, Set, Text, Union
Expand Down
3 changes: 1 addition & 2 deletions schema_salad/ref_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
from StringIO import StringIO

from . import validate
from .aslist import aslist
from .flatten import flatten
from schema_salad.utils import aslist, flatten
from .sourceline import SourceLine, add_lc_filename, relname

import requests
Expand Down
4 changes: 1 addition & 3 deletions schema_salad/schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import avro
import copy
from .add_dictlist import add_dictlist
from schema_salad.utils import add_dictlist, aslist, flatten
import sys
import pprint
from pkg_resources import resource_stream
Expand All @@ -15,9 +15,7 @@
from avro.schema import Names, SchemaParseException
from . import ref_resolver
from .ref_resolver import Loader, DocumentType
from .flatten import flatten
import logging
from .aslist import aslist
from . import jsonld_context
from .sourceline import SourceLine, strip_dup_lineno, add_lc_filename, bullets, relname
from typing import cast, Any, AnyStr, Dict, List, Set, Tuple, TypeVar, Union
Expand Down
21 changes: 18 additions & 3 deletions schema_salad/flatten.py → schema_salad/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import sys
from typing import Any, Tuple
from __future__ import absolute_import

from typing import Any, Dict, List


def add_dictlist(di, key, val): # type: (Dict, Any, Any) -> None
if key not in di:
di[key] = []
di[key].append(val)

# http://rightfootin.blogspot.com/2006/09/more-on-python-flatten.html

def aslist(l): # type: (Any) -> List
"""Convenience function to wrap single items and lists, and return lists unchanged."""

if isinstance(l, list):
return l
else:
return [l]

# http://rightfootin.blogspot.com/2006/09/more-on-python-flatten.html

def flatten(l, ltypes=(list, tuple)):
# type: (Any, Any) -> Any
Expand Down

0 comments on commit 9d9317e

Please sign in to comment.