Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
Merge branch 'name-fixing' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmeneghello committed Nov 1, 2013
2 parents 4f30e62 + a7e3ff8 commit 2823370
Show file tree
Hide file tree
Showing 18 changed files with 515 additions and 268 deletions.
4 changes: 2 additions & 2 deletions api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import re
import regex

import bottle
from bottle import request, response
Expand All @@ -21,7 +21,7 @@ def api():
# reform s|search into ^s$|^search$
# if we don't, 's' matches 'caps' (s)
r = '|'.join(['^{0}$'.format(r) for r in r.split('|')])
if re.search(r, function):
if regex.search(r, function):
dataset = dict()
dataset['get_link'] = get_link
data = func(dataset)
Expand Down
10 changes: 5 additions & 5 deletions lib/nntplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
# - support HDR

# Imports
import re
import regex
import socket
import collections
import datetime
Expand Down Expand Up @@ -700,7 +700,7 @@ def list(self, group_pattern=None, *, file=None):
return resp, self._grouplist(lines)

def _getdescriptions(self, group_pattern, return_all):
line_pat = re.compile('^(?P<group>[^ \t]+)[ \t]+(.*)$')
line_pat = regex.compile('^(?P<group>[^ \t]+)[ \t]+(.*)$')
# Try the more std (acc. to RFC2980) LIST NEWSGROUPS first
resp, lines = self._longcmdstring('LIST NEWSGROUPS ' + group_pattern)
if not resp.startswith('215'):
Expand Down Expand Up @@ -875,7 +875,7 @@ def xhdr(self, hdr, str, *, file=None):
- resp: server response if successful
- list: list of (nr, value) strings
"""
pat = re.compile('^([0-9]+) ?(.*)\n?')
pat = regex.compile('^([0-9]+) ?(.*)\n?')
resp, lines = self._longcmdstring('XHDR {0} {1}'.format(hdr, str), file)
def remove_number(line):
m = pat.match(line)
Expand Down Expand Up @@ -951,7 +951,7 @@ def xgtitle(self, group, *, file=None):
warnings.warn("The XGTITLE extension is not actively used, "
"use descriptions() instead",
DeprecationWarning, 2)
line_pat = re.compile('^([^ \t]+)[ \t]+(.*)$')
line_pat = regex.compile('^([^ \t]+)[ \t]+(.*)$')
resp, raw_lines = self._longcmdstring('XGTITLE ' + group, file)
lines = []
for raw_line in raw_lines:
Expand Down Expand Up @@ -1253,4 +1253,4 @@ def cut(s, lim):
)

s.quit()


2 changes: 0 additions & 2 deletions lib/rar.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ def _getContents(self):
if head_type == 0x73:
#TODO: Try to factor this out to reduce time spent in syscalls.
self.fp.seek(offset + 2) # Seek to just after HEAD_CRC
#FIXME: Check header CRC on all blocks.
assert self._check_crc(self.fp.read(11), head_crc)

# TODO: Rework handling of file headers.
elif head_type == 0x74:
Expand Down
26 changes: 13 additions & 13 deletions pynab/binaries.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import re
import regex
import time
import datetime
import pytz
Expand Down Expand Up @@ -104,28 +104,28 @@ def process():
# where(), but it's slow as hell because it's processed by the JS engine
relevant_groups = db.parts.distinct('group_name')
for part in db.parts.find({'group_name': {'$in': relevant_groups}}, exhaust=True):
for regex in db.regexes.find({'group_name': {'$in': [part['group_name'], '*']}}).sort('ordinal', 1):
for reg in db.regexes.find({'group_name': {'$in': [part['group_name'], '*']}}).sort('ordinal', 1):
# convert php-style regex to python
# ie. /(\w+)/i -> (\w+), re.I
# ie. /(\w+)/i -> (\w+), regex.I
# no need to handle s, as it doesn't exist in python

# why not store it as python to begin with? some regex
# shouldn't be case-insensitive, and this notation allows for that
r = regex['regex']
r = reg['regex']
flags = r[r.rfind('/') + 1:]
r = r[r.find('/') + 1:r.rfind('/')]
regex_flags = re.I if 'i' in flags else 0
regex_flags = regex.I if 'i' in flags else 0

try:
result = re.search(r, part['subject'], regex_flags)
result = regex.search(r, part['subject'], regex_flags)
except:
log.error('Broken regex detected. _id: {:d}, removing...'.format(regex['_id']))
db.regexes.remove({'_id': regex['_id']})
log.error('Broken regex detected. _id: {:d}, removing...'.format(reg['_id']))
db.regexes.remove({'_id': reg['_id']})
continue

match = result.groupdict() if result else None
if match:
log.debug('Matched part {} to {}.'.format(part['subject'], regex['regex']))
log.debug('Matched part {} to {}.'.format(part['subject'], reg['regex']))
# remove whitespace in dict values
match = {k: v.strip() for k, v in match.items()}

Expand All @@ -146,7 +146,7 @@ def process():
# segment numbers have been stripped by this point, so don't worry
# about accidentally hitting those instead
if not match.get('parts'):
result = re.search('(\d{1,3}\/\d{1,3})', part['subject'])
result = regex.search('(\d{1,3}\/\d{1,3})', part['subject'])
if result:
match['parts'] = result.group(1)

Expand Down Expand Up @@ -175,8 +175,8 @@ def process():
'posted_by': part['posted_by'],
'group_name': part['group_name'],
'xref': part['xref'],
'regex_id': regex['_id'],
'category_id': regex['category_id'],
'regex_id': reg['_id'],
'category_id': reg['category_id'],
'req_id': match.get('reqid'),
'total_parts': int(total),
'parts': {current: part}
Expand Down Expand Up @@ -210,7 +210,7 @@ def parse_xref(xref):
groups = []
raw_groups = xref.split(' ')
for raw_group in raw_groups:
result = re.search('^([a-z0-9\.\-_]+):(\d+)?$', raw_group, re.I)
result = regex.search('^([a-z0-9\.\-_]+):(\d+)?$', raw_group, regex.I)
if result:
groups.append(result.group(1))
return groups
Loading

0 comments on commit 2823370

Please sign in to comment.