setlr 0.2.10__tar.gz → 0.2.12__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  #!/Users/jimmccusker/opt/ipython/bin/python
2
- # EASY-INSTALL-ENTRY-SCRIPT: 'setlr==0.2.10','console_scripts','setlr'
3
- __requires__ = 'setlr==0.2.10'
2
+ # EASY-INSTALL-ENTRY-SCRIPT: 'setlr==0.2.12','console_scripts','setlr'
3
+ __requires__ = 'setlr==0.2.12'
4
4
  import sys
5
5
  from pkg_resources import load_entry_point
6
6
 
7
7
  if __name__ == '__main__':
8
8
  sys.exit(
9
- load_entry_point('setlr==0.2.10', 'console_scripts', 'setlr')()
9
+ load_entry_point('setlr==0.2.12', 'console_scripts', 'setlr')()
10
10
  )
@@ -1,6 +1,9 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
+ from builtins import str
5
+ from builtins import next
6
+ from builtins import object
4
7
  from rdflib import *
5
8
  from rdflib.util import guess_format
6
9
  import rdflib
@@ -11,7 +14,7 @@ import requests
11
14
  import pandas
12
15
  import re
13
16
  import os
14
- from six import text_type as unicode
17
+ from six import text_type as str
15
18
 
16
19
  from jinja2 import Template
17
20
  from toposort import toposort_flatten
@@ -19,7 +22,7 @@ from numpy import isnan
19
22
  import uuid
20
23
  import tempfile
21
24
  import ijson
22
- from . import iterparse_filter
25
+ import iterparse_filter
23
26
  #import xml.etree.ElementTree as ET
24
27
  import xml.etree.ElementTree
25
28
 
@@ -174,7 +177,7 @@ class FileLikeFromIter(object):
174
177
 
175
178
  def read(self, n=None):
176
179
  if n is None:
177
- return self.data + ''.join(l for l in self.iter)
180
+ return self.data + b''.join(l for l in self.iter)
178
181
  else:
179
182
  while len(self.data) < n:
180
183
  try:
@@ -240,7 +243,8 @@ def read_excel(location, result):
240
243
  )
241
244
  if result.value(csvw.header):
242
245
  args['header'] = [result.value(csvw.header).value]
243
- df = pandas.read_excel(get_content(location, result),encoding='utf-8', **args)
246
+ with get_content(location, result) as f:
247
+ df = pandas.read_excel(f,encoding='utf-8', **args)
244
248
  return df
245
249
 
246
250
  def read_xml(location, result):
@@ -253,8 +257,9 @@ def read_xml(location, result):
253
257
  f.iter_end("/*")
254
258
  for xp in result[setl.xpath]:
255
259
  f.iter_end(xp.value)
256
- for (i, (event, ele)) in enumerate(f.iterparse(get_content(location, result))):
257
- yield i, ele
260
+ with get_content(location, result) as fo:
261
+ for (i, (event, ele)) in enumerate(f.iterparse(fo)):
262
+ yield i, ele
258
263
 
259
264
 
260
265
  def read_json(location, result):
@@ -263,7 +268,8 @@ def read_json(location, result):
263
268
  selector = selector.value
264
269
  else:
265
270
  selector = ""
266
- return enumerate(ijson.items(get_content(location, result), selector))
271
+ with get_content(location, result) as fo:
272
+ return enumerate(ijson.items(fo, selector))
267
273
 
268
274
 
269
275
  extractors = {
@@ -458,7 +464,7 @@ def process_row(row, template, rowname, table, resources, transform, variables):
458
464
  if isinstance(value, dict):
459
465
  if '@if' in value:
460
466
  try:
461
- fn = get_function(value['@if'], env.keys())
467
+ fn = get_function(value['@if'], list(env.keys()))
462
468
  incl = fn(**env)
463
469
  if incl is None or not incl:
464
470
  continue
@@ -471,12 +477,12 @@ def process_row(row, template, rowname, table, resources, transform, variables):
471
477
  except Exception as e:
472
478
  trace = sys.exc_info()[2]
473
479
  logger.error("Error in conditional %s\nRelevant Environment:", value['@if'])
474
- for key, v in env.items():
480
+ for key, v in list(env.items()):
475
481
  #if key in value['@if']:
476
482
  if hasattr(v, 'findall'):
477
483
  v = xml.etree.ElementTree.tostring(v)
478
484
  logger.error(key + "\t" + str(v)[:1000])
479
- raise(e, None, trace)
485
+ raise e
480
486
  if '@for' in value:
481
487
  f = value['@for']
482
488
  if isinstance(f, list):
@@ -489,7 +495,7 @@ def process_row(row, template, rowname, table, resources, transform, variables):
489
495
  else:
490
496
  del val['@for']
491
497
  try:
492
- fn = get_function(expression, env.keys())
498
+ fn = get_function(expression, list(env.keys()))
493
499
  values = fn(**env)
494
500
  if values is not None:
495
501
  for v in values:
@@ -505,8 +511,8 @@ def process_row(row, template, rowname, table, resources, transform, variables):
505
511
  except Exception as e:
506
512
  trace = sys.exc_info()[2]
507
513
  logger.error("Error in @for: %s", value['@for'])
508
- logger.error("Locals: %s", env.keys())
509
- raise(e, None, trace)
514
+ logger.error("Locals: %s", list(env.keys()))
515
+ raise e
510
516
  continue
511
517
  if '@with' in value:
512
518
  f = value['@with']
@@ -520,7 +526,7 @@ def process_row(row, template, rowname, table, resources, transform, variables):
520
526
  else:
521
527
  del val['@with']
522
528
  try:
523
- fn = get_function(expression, env.keys())
529
+ fn = get_function(expression, list(env.keys()))
524
530
  v = fn(**env)
525
531
  if v is not None:
526
532
  if len(variable_list) == 1:
@@ -535,11 +541,11 @@ def process_row(row, template, rowname, table, resources, transform, variables):
535
541
  except Exception as e:
536
542
  trace = sys.exc_info()[2]
537
543
  logger.error("Error in with: %s", value['@with'])
538
- logger.error("Locals: %s", env.keys())
539
- raise(e, None, trace)
544
+ logger.error("Locals: %s", list(env.keys()))
545
+ raise e
540
546
  continue
541
547
  this = {}
542
- for child in value.items():
548
+ for child in list(value.items()):
543
549
  if child[0] == '@if':
544
550
  continue
545
551
  if child[0] == '@for':
@@ -549,20 +555,20 @@ def process_row(row, template, rowname, table, resources, transform, variables):
549
555
  this = []
550
556
  for child in value:
551
557
  todo.append((child, this, env))
552
- elif isinstance(value, unicode):
558
+ elif isinstance(value, str):
553
559
  try:
554
- template = get_template(unicode(value))
560
+ template = get_template(str(value))
555
561
  this = template.render(**env)
556
562
  except Exception as e:
557
563
  trace = sys.exc_info()[2]
558
564
  logger.error("Error in template %s %s", value, type(value))
559
565
  logger.error("Relevant Environment:")
560
- for key, v in env.items():
566
+ for key, v in list(env.items()):
561
567
  #if key in value:
562
568
  if hasattr(v, 'findall'):
563
569
  v = xml.etree.ElementTree.tostring(v)
564
570
  logger.error(key + "\t" + str(v)[:1000])
565
- raise(e, None, trace)
571
+ raise e
566
572
  else:
567
573
  this = value
568
574
 
@@ -607,7 +613,7 @@ def json_transform(transform, resources):
607
613
  line = int(re.search("line ([0-9]+)", e.message).group(1))
608
614
  logger.error("Error in parsing JSON Template at line %d:", line)
609
615
  logger.error('\n'.join(["%d: %s"%(i+line-3, x) for i, x in enumerate(s.split("\n")[line-3:line+4])]))
610
- raise(e, None, trace)
616
+ raise e
611
617
  context = transform.value(setl.hasContext)
612
618
  if context is not None:
613
619
  context = json.loads(context.value)
@@ -648,7 +654,7 @@ def json_transform(transform, resources):
648
654
  logger.error("Error on %s %s", rowname, row)
649
655
  else:
650
656
  logger.error("Error on %s", rowname)
651
- raise(e, None, trace)
657
+ raise e
652
658
 
653
659
  resources[generated.identifier] = result
654
660
 
@@ -3,8 +3,13 @@
3
3
  For details see:
4
4
  http://dalkescientific.com/writings/diary/archive/2006/11/06/iterparse_filter.html
5
5
  """
6
+ from __future__ import print_function
6
7
  # I have got to rearrange my site to use shorter URLs.
7
8
 
9
+ from future import standard_library
10
+ standard_library.install_aliases()
11
+ from builtins import zip
12
+ from builtins import object
8
13
  __version__ = "0.9-experimental"
9
14
 
10
15
  import re
@@ -543,7 +548,7 @@ def test_syntax():
543
548
  (xpath, tag_list, got, bool(expect)))
544
549
 
545
550
  def test_filtering():
546
- import cStringIO as StringIO
551
+ import io as StringIO
547
552
  f = StringIO.StringIO("""\
548
553
  <A><AA>
549
554
  <B xmlns="http://z/"><C/><spam:D xmlns:spam="http://spam/">eggs</spam:D></B>
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.1
2
2
  Name: setlr
3
- Version: 0.2.10
3
+ Version: 0.2.12
4
4
  Summary: setlr is a tool for Semantic Extraction, Transformation, and Loading.
5
5
  Home-page: http://packages.python.org/setlr
6
6
  Author: Jim McCusker
@@ -0,0 +1 @@
1
+ {"is_release": false, "git_version": "0b4b76f"}
@@ -3,7 +3,7 @@ cython
3
3
  numpy
4
4
  rdflib
5
5
  rdflib-jsonld
6
- pandas
6
+ pandas==0.22.0
7
7
  requests
8
8
  toposort
9
9
  beautifulsoup4
@@ -1 +0,0 @@
1
- {"is_release": false, "git_version": "a559233"}