11# the basic knowledge object, with database awareness, …
22
3- from datetime import datetime , timedelta
43from collections import defaultdict
5- import time
4+ from datetime import datetime , timedelta
5+ import re
66import subprocess
7- import sys
7+ import time
88
99from psycodict .base import PostgresBase
1010from psycodict import DelayCommit
1717from psycopg2 .sql import SQL , Identifier , Placeholder
1818from sage .all import cached_function
1919
20- import re
20+
2121text_keywords = re .compile (r"\b[a-zA-Z0-9-]{3,}\b" )
2222top_knowl_re = re .compile (r"(.*)\.top$" )
2323comment_knowl_re = re .compile (r"(.*)\.(\d+)\.comment$" )
@@ -582,11 +582,8 @@ def code_references(self, knowl):
582582 matches = []
583583 for kid in kids :
584584 try :
585- if sys .version_info [0 ] == 3 :
586- matches .extend (subprocess .check_output (['git' , 'grep' , '--full-name' , '--line-number' , '--context' , '2' , """['"]%s['"]""" % (kid .replace ('.' ,r'\.' ))],encoding = 'utf-8' ).split ('\n --\n ' ))
587- else :
588- matches .extend (subprocess .check_output (['git' , 'grep' , '--full-name' , '--line-number' , '--context' , '2' , """['"]%s['"]""" % (kid .replace ('.' ,r'\.' ))]).split ('\n --\n ' ))
589- except subprocess .CalledProcessError : # no matches
585+ matches .extend (subprocess .check_output (['git' , 'grep' , '--full-name' , '--line-number' , '--context' , '2' , """['"]%s['"]""" % (kid .replace ('.' ,r'\.' ))],encoding = 'utf-8' ).split ('\n --\n ' ))
586+ except subprocess .CalledProcessError : # no matches
590587 pass
591588 return [self ._process_git_grep (match ) for match in matches ]
592589
@@ -600,11 +597,8 @@ def check_sed_safety(self, knowlid):
600597 - -1 if the knowl is referenced but cannot be safely replaced.
601598 """
602599 try :
603- if sys .version_info [0 ] == 3 :
604- matches = subprocess .check_output (['git' , 'grep' , """['"]%s['"]""" % (knowlid .replace ('.' ,r'\.' ))],encoding = 'utf-8' ).split ('\n ' )
605- else :
606- matches = subprocess .check_output (['git' , 'grep' , """['"]%s['"]""" % (knowlid .replace ('.' ,r'\.' ))]).split ('\n ' )
607- except subprocess .CalledProcessError : # no matches
600+ matches = subprocess .check_output (['git' , 'grep' , """['"]%s['"]""" % (knowlid .replace ('.' ,r'\.' ))],encoding = 'utf-8' ).split ('\n ' )
601+ except subprocess .CalledProcessError : # no matches
608602 return 0
609603
610604 easy_matches = subprocess .check_output (['git' , 'grep' , knowlid .replace ('.' ,r'\.' )],encoding = 'utf-8' ).split ('\n ' )
@@ -705,10 +699,7 @@ def broken_links_code(self):
705699 ids that show up in an expression of the form ``KNOWL('BAD_ID')``.
706700 """
707701 all_kids = {k ['id' ] for k in self .get_all_knowls (['id' ])}
708- if sys .version_info [0 ] == 3 :
709- matches = subprocess .check_output (['git' , 'grep' , '-E' , '--full-name' , '--line-number' , '--context' , '2' , link_finder_re .pattern ],encoding = 'utf-8' ).split ('\n --\n ' )
710- else :
711- matches = subprocess .check_output (['git' , 'grep' , '-E' , '--full-name' , '--line-number' , '--context' , '2' , link_finder_re .pattern ]).split ('\n --\n ' )
702+ matches = subprocess .check_output (['git' , 'grep' , '-E' , '--full-name' , '--line-number' , '--context' , '2' , link_finder_re .pattern ],encoding = 'utf-8' ).split ('\n --\n ' )
712703 results = []
713704 for match in matches :
714705 lines = match .split ('\n ' )
0 commit comments