diff options
author | McCabe Maxsted | 2009-01-14 07:56:23 -0700 |
---|---|---|
committer | McCabe Maxsted | 2009-01-14 07:56:23 -0700 |
commit | c25939480d6134c200a14ecab23eee60b175596f (patch) | |
tree | 0ed050b7005f87062e11fe1044c3a1c838ecc412 /linden/indra/lib | |
parent | Added the 'Return to World' inventory option (diff) | |
download | meta-impy-c25939480d6134c200a14ecab23eee60b175596f.zip meta-impy-c25939480d6134c200a14ecab23eee60b175596f.tar.gz meta-impy-c25939480d6134c200a14ecab23eee60b175596f.tar.bz2 meta-impy-c25939480d6134c200a14ecab23eee60b175596f.tar.xz |
Updated llmessage
Diffstat (limited to 'linden/indra/lib')
-rw-r--r-- | linden/indra/lib/python/indra/ipc/llsdhttp.py | 2 | ||||
-rw-r--r-- | linden/indra/lib/python/indra/ipc/mysql_pool.py | 23 | ||||
-rw-r--r-- | linden/indra/lib/python/indra/ipc/servicebuilder.py | 29 | ||||
-rw-r--r-- | linden/indra/lib/python/indra/ipc/siesta.py | 4 | ||||
-rw-r--r-- | linden/indra/lib/python/indra/util/llmanifest.py | 3 | ||||
-rw-r--r-- | linden/indra/lib/python/indra/util/llversion.py | 5 | ||||
-rw-r--r-- | linden/indra/lib/python/indra/util/named_query.py | 37 |
7 files changed, 71 insertions, 32 deletions
diff --git a/linden/indra/lib/python/indra/ipc/llsdhttp.py b/linden/indra/lib/python/indra/ipc/llsdhttp.py index 1cf1146..ed64899 100644 --- a/linden/indra/lib/python/indra/ipc/llsdhttp.py +++ b/linden/indra/lib/python/indra/ipc/llsdhttp.py | |||
@@ -51,6 +51,8 @@ request_ = suite.request_ | |||
51 | # import every httpc error exception into our namespace for convenience | 51 | # import every httpc error exception into our namespace for convenience |
52 | for x in httpc.status_to_error_map.itervalues(): | 52 | for x in httpc.status_to_error_map.itervalues(): |
53 | globals()[x.__name__] = x | 53 | globals()[x.__name__] = x |
54 | ConnectionError = httpc.ConnectionError | ||
55 | Retriable = httpc.Retriable | ||
54 | 56 | ||
55 | for x in (httpc.ConnectionError,): | 57 | for x in (httpc.ConnectionError,): |
56 | globals()[x.__name__] = x | 58 | globals()[x.__name__] = x |
diff --git a/linden/indra/lib/python/indra/ipc/mysql_pool.py b/linden/indra/lib/python/indra/ipc/mysql_pool.py index 507b185..25a66cf 100644 --- a/linden/indra/lib/python/indra/ipc/mysql_pool.py +++ b/linden/indra/lib/python/indra/ipc/mysql_pool.py | |||
@@ -30,8 +30,10 @@ import MySQLdb | |||
30 | from eventlet import db_pool | 30 | from eventlet import db_pool |
31 | 31 | ||
32 | class DatabaseConnector(db_pool.DatabaseConnector): | 32 | class DatabaseConnector(db_pool.DatabaseConnector): |
33 | def __init__(self, credentials, min_size = 0, max_size = 4, *args, **kwargs): | 33 | def __init__(self, credentials, *args, **kwargs): |
34 | super(DatabaseConnector, self).__init__(MySQLdb, credentials, min_size, max_size, conn_pool=db_pool.ConnectionPool, *args, **kwargs) | 34 | super(DatabaseConnector, self).__init__(MySQLdb, credentials, |
35 | conn_pool=db_pool.ConnectionPool, | ||
36 | *args, **kwargs) | ||
35 | 37 | ||
36 | # get is extended relative to eventlet.db_pool to accept a port argument | 38 | # get is extended relative to eventlet.db_pool to accept a port argument |
37 | def get(self, host, dbname, port=3306): | 39 | def get(self, host, dbname, port=3306): |
@@ -42,7 +44,7 @@ class DatabaseConnector(db_pool.DatabaseConnector): | |||
42 | new_kwargs['host'] = host | 44 | new_kwargs['host'] = host |
43 | new_kwargs['port'] = port | 45 | new_kwargs['port'] = port |
44 | new_kwargs.update(self.credentials_for(host)) | 46 | new_kwargs.update(self.credentials_for(host)) |
45 | dbpool = ConnectionPool(self._min_size, self._max_size, *self._args, **new_kwargs) | 47 | dbpool = ConnectionPool(*self._args, **new_kwargs) |
46 | self._databases[key] = dbpool | 48 | self._databases[key] = dbpool |
47 | 49 | ||
48 | return self._databases[key] | 50 | return self._databases[key] |
@@ -51,8 +53,8 @@ class ConnectionPool(db_pool.TpooledConnectionPool): | |||
51 | """A pool which gives out saranwrapped MySQLdb connections from a pool | 53 | """A pool which gives out saranwrapped MySQLdb connections from a pool |
52 | """ | 54 | """ |
53 | 55 | ||
54 | def __init__(self, min_size = 0, max_size = 4, *args, **kwargs): | 56 | def __init__(self, *args, **kwargs): |
55 | super(ConnectionPool, self).__init__(MySQLdb, min_size, max_size, *args, **kwargs) | 57 | super(ConnectionPool, self).__init__(MySQLdb, *args, **kwargs) |
56 | 58 | ||
57 | def get(self): | 59 | def get(self): |
58 | conn = super(ConnectionPool, self).get() | 60 | conn = super(ConnectionPool, self).get() |
@@ -77,14 +79,3 @@ class ConnectionPool(db_pool.TpooledConnectionPool): | |||
77 | conn.connection_parameters = converted_kwargs | 79 | conn.connection_parameters = converted_kwargs |
78 | return conn | 80 | return conn |
79 | 81 | ||
80 | def clear(self): | ||
81 | """ Close all connections that this pool still holds a reference to, leaving it empty.""" | ||
82 | for conn in self.free_items: | ||
83 | try: | ||
84 | conn.close() | ||
85 | except: | ||
86 | pass # even if stuff happens here, we still want to at least try to close all the other connections | ||
87 | self.free_items.clear() | ||
88 | |||
89 | def __del__(self): | ||
90 | self.clear() | ||
diff --git a/linden/indra/lib/python/indra/ipc/servicebuilder.py b/linden/indra/lib/python/indra/ipc/servicebuilder.py index 89cdfad..01f2c6f 100644 --- a/linden/indra/lib/python/indra/ipc/servicebuilder.py +++ b/linden/indra/lib/python/indra/ipc/servicebuilder.py | |||
@@ -51,12 +51,10 @@ def build(name, context={}, **kwargs): | |||
51 | > servicebuilder.build('version-manager-version', context, version='1.18.1.2') | 51 | > servicebuilder.build('version-manager-version', context, version='1.18.1.2') |
52 | 'http://int.util.vaak.lindenlab.com/channel/Second%20Life%20Release/1.18.1.2' | 52 | 'http://int.util.vaak.lindenlab.com/channel/Second%20Life%20Release/1.18.1.2' |
53 | """ | 53 | """ |
54 | context = context.copy() # shouldn't modify the caller's dictionary | ||
55 | context.update(kwargs) | ||
56 | global _g_builder | 54 | global _g_builder |
57 | if _g_builder is None: | 55 | if _g_builder is None: |
58 | _g_builder = ServiceBuilder() | 56 | _g_builder = ServiceBuilder() |
59 | return _g_builder.buildServiceURL(name, context) | 57 | return _g_builder.buildServiceURL(name, context, **kwargs) |
60 | 58 | ||
61 | class ServiceBuilder(object): | 59 | class ServiceBuilder(object): |
62 | def __init__(self, services_definition = services_config): | 60 | def __init__(self, services_definition = services_config): |
@@ -81,13 +79,36 @@ class ServiceBuilder(object): | |||
81 | else: | 79 | else: |
82 | self.builders[service['name']] = service_builder | 80 | self.builders[service['name']] = service_builder |
83 | 81 | ||
84 | def buildServiceURL(self, name, context): | 82 | def buildServiceURL(self, name, context={}, **kwargs): |
85 | """\ | 83 | """\ |
86 | @brief given the environment on construction, return a service URL. | 84 | @brief given the environment on construction, return a service URL. |
87 | @param name The name of the service. | 85 | @param name The name of the service. |
88 | @param context A dict of name value lookups for the service. | 86 | @param context A dict of name value lookups for the service. |
87 | @param kwargs Any keyword arguments are treated as members of the | ||
88 | context, this allows you to be all 31337 by writing shit like: | ||
89 | servicebuilder.build('name', param=value) | ||
89 | @returns Returns the | 90 | @returns Returns the |
90 | """ | 91 | """ |
92 | context = context.copy() # shouldn't modify the caller's dictionary | ||
93 | context.update(kwargs) | ||
91 | base_url = config.get('services-base-url') | 94 | base_url = config.get('services-base-url') |
92 | svc_path = russ.format(self.builders[name], context) | 95 | svc_path = russ.format(self.builders[name], context) |
93 | return base_url + svc_path | 96 | return base_url + svc_path |
97 | |||
98 | |||
99 | def on_in(query_name, host_key, schema_key): | ||
100 | """\ | ||
101 | @brief Constructs an on/in snippet (for running named queries) | ||
102 | from a schema name and two keys referencing values stored in | ||
103 | indra.xml. | ||
104 | |||
105 | @param query_name Name of the query. | ||
106 | @param host_key Logical name of destination host. Will be | ||
107 | looked up in indra.xml. | ||
108 | @param schema_key Logical name of destination schema. Will | ||
109 | be looked up in indra.xml. | ||
110 | """ | ||
111 | host_name = config.get(host_key) | ||
112 | schema_name = config.get(schema_key) | ||
113 | return '/'.join( ('on', host_name, 'in', schema_name, query_name.lstrip('/')) ) | ||
114 | |||
diff --git a/linden/indra/lib/python/indra/ipc/siesta.py b/linden/indra/lib/python/indra/ipc/siesta.py index 5fbea29..b206f18 100644 --- a/linden/indra/lib/python/indra/ipc/siesta.py +++ b/linden/indra/lib/python/indra/ipc/siesta.py | |||
@@ -24,9 +24,9 @@ except ImportError: | |||
24 | 24 | ||
25 | llsd_parsers = { | 25 | llsd_parsers = { |
26 | 'application/json': json_decode, | 26 | 'application/json': json_decode, |
27 | 'application/llsd+binary': llsd.parse_binary, | 27 | llsd.BINARY_MIME_TYPE: llsd.parse_binary, |
28 | 'application/llsd+notation': llsd.parse_notation, | 28 | 'application/llsd+notation': llsd.parse_notation, |
29 | 'application/llsd+xml': llsd.parse_xml, | 29 | llsd.XML_MIME_TYPE: llsd.parse_xml, |
30 | 'application/xml': llsd.parse_xml, | 30 | 'application/xml': llsd.parse_xml, |
31 | } | 31 | } |
32 | 32 | ||
diff --git a/linden/indra/lib/python/indra/util/llmanifest.py b/linden/indra/lib/python/indra/util/llmanifest.py index 4675177..a00d242 100644 --- a/linden/indra/lib/python/indra/util/llmanifest.py +++ b/linden/indra/lib/python/indra/util/llmanifest.py | |||
@@ -584,7 +584,7 @@ class LLManifest(object): | |||
584 | 584 | ||
585 | def wildcard_regex(self, src_glob, dst_glob): | 585 | def wildcard_regex(self, src_glob, dst_glob): |
586 | src_re = re.escape(src_glob) | 586 | src_re = re.escape(src_glob) |
587 | src_re = src_re.replace('\*', '([-a-zA-Z0-9._ ]+)') | 587 | src_re = src_re.replace('\*', '([-a-zA-Z0-9._ ]*)') |
588 | dst_temp = dst_glob | 588 | dst_temp = dst_glob |
589 | i = 1 | 589 | i = 1 |
590 | while dst_temp.count("*") > 0: | 590 | while dst_temp.count("*") > 0: |
@@ -621,6 +621,7 @@ class LLManifest(object): | |||
621 | count = 0 | 621 | count = 0 |
622 | if self.wildcard_pattern.search(src): | 622 | if self.wildcard_pattern.search(src): |
623 | for s,d in self.expand_globs(src, dst): | 623 | for s,d in self.expand_globs(src, dst): |
624 | assert(s != d) | ||
624 | count += self.process_file(s, d) | 625 | count += self.process_file(s, d) |
625 | else: | 626 | else: |
626 | # if we're specifying a single path (not a glob), | 627 | # if we're specifying a single path (not a glob), |
diff --git a/linden/indra/lib/python/indra/util/llversion.py b/linden/indra/lib/python/indra/util/llversion.py index 666cce4..fe9448f 100644 --- a/linden/indra/lib/python/indra/util/llversion.py +++ b/linden/indra/lib/python/indra/util/llversion.py | |||
@@ -50,7 +50,10 @@ def get_version(version_type): | |||
50 | m = re.search('const S32 IMP_VERSION_MINOR = (\d+);', file_str) | 50 | m = re.search('const S32 IMP_VERSION_MINOR = (\d+);', file_str) |
51 | VER_MINOR = m.group(1) | 51 | VER_MINOR = m.group(1) |
52 | m = re.search('const S32 IMP_VERSION_PATCH = (\d+);', file_str) | 52 | m = re.search('const S32 IMP_VERSION_PATCH = (\d+);', file_str) |
53 | version = "%(VER_MAJOR)s.%(VER_MINOR)s.%(VER_PATCH)s" % locals() | 53 | VER_PATCH = m.group(1) |
54 | m = re.search('const S32 IMP_VERSION_TEST = (\d+);', file_str) | ||
55 | VER_BUILD = m.group(1) | ||
56 | version = "%(VER_MAJOR)s.%(VER_MINOR)s.%(VER_PATCH)s.%(VER_TEST)s" % locals() | ||
54 | return version | 57 | return version |
55 | 58 | ||
56 | def get_channel(version_type): | 59 | def get_channel(version_type): |
diff --git a/linden/indra/lib/python/indra/util/named_query.py b/linden/indra/lib/python/indra/util/named_query.py index 20f2ec7..788fb0e 100644 --- a/linden/indra/lib/python/indra/util/named_query.py +++ b/linden/indra/lib/python/indra/util/named_query.py | |||
@@ -47,6 +47,8 @@ except NameError: | |||
47 | from indra.base import llsd | 47 | from indra.base import llsd |
48 | from indra.base import config | 48 | from indra.base import config |
49 | 49 | ||
50 | DEBUG = False | ||
51 | |||
50 | NQ_FILE_SUFFIX = config.get('named-query-file-suffix', '.nq') | 52 | NQ_FILE_SUFFIX = config.get('named-query-file-suffix', '.nq') |
51 | NQ_FILE_SUFFIX_LEN = len(NQ_FILE_SUFFIX) | 53 | NQ_FILE_SUFFIX_LEN = len(NQ_FILE_SUFFIX) |
52 | 54 | ||
@@ -63,7 +65,9 @@ def _init_g_named_manager(sql_dir = None): | |||
63 | 65 | ||
64 | # extra fallback directory in case config doesn't return what we want | 66 | # extra fallback directory in case config doesn't return what we want |
65 | if sql_dir is None: | 67 | if sql_dir is None: |
66 | sql_dir = os.path.dirname(__file__) + "../../../../web/dataservice/sql" | 68 | sql_dir = os.path.abspath( |
69 | os.path.join( | ||
70 | os.path.realpath(os.path.dirname(__file__)), "..", "..", "..", "..", "web", "dataservice", "sql")) | ||
67 | 71 | ||
68 | global _g_named_manager | 72 | global _g_named_manager |
69 | _g_named_manager = NamedQueryManager( | 73 | _g_named_manager = NamedQueryManager( |
@@ -103,11 +107,12 @@ class NamedQuery(object): | |||
103 | def __init__(self, name, filename): | 107 | def __init__(self, name, filename): |
104 | """ Construct a NamedQuery object. The name argument is an | 108 | """ Construct a NamedQuery object. The name argument is an |
105 | arbitrary name as a handle for the query, and the filename is | 109 | arbitrary name as a handle for the query, and the filename is |
106 | a path to a file containing an llsd named query document.""" | 110 | a path to a file or a file-like object containing an llsd named |
111 | query document.""" | ||
107 | self._stat_interval_seconds = 5 # 5 seconds | 112 | self._stat_interval_seconds = 5 # 5 seconds |
108 | self._name = name | 113 | self._name = name |
109 | if (filename is not None) \ | 114 | if (filename is not None and isinstance(filename, (str, unicode)) |
110 | and (NQ_FILE_SUFFIX != filename[-NQ_FILE_SUFFIX_LEN:]): | 115 | and NQ_FILE_SUFFIX != filename[-NQ_FILE_SUFFIX_LEN:]): |
111 | filename = filename + NQ_FILE_SUFFIX | 116 | filename = filename + NQ_FILE_SUFFIX |
112 | self._location = filename | 117 | self._location = filename |
113 | self._alternative = dict() | 118 | self._alternative = dict() |
@@ -122,8 +127,8 @@ class NamedQuery(object): | |||
122 | 127 | ||
123 | def get_modtime(self): | 128 | def get_modtime(self): |
124 | """ Returns the mtime (last modified time) of the named query | 129 | """ Returns the mtime (last modified time) of the named query |
125 | file, if such exists.""" | 130 | filename. For file-like objects, expect a modtime of 0""" |
126 | if self._location: | 131 | if self._location and isinstance(self._location, (str, unicode)): |
127 | return os.path.getmtime(self._location) | 132 | return os.path.getmtime(self._location) |
128 | return 0 | 133 | return 0 |
129 | 134 | ||
@@ -131,7 +136,12 @@ class NamedQuery(object): | |||
131 | """ Loads and parses the named query file into self. Does | 136 | """ Loads and parses the named query file into self. Does |
132 | nothing if self.location is nonexistant.""" | 137 | nothing if self.location is nonexistant.""" |
133 | if self._location: | 138 | if self._location: |
134 | self._reference_contents(llsd.parse(open(self._location).read())) | 139 | if isinstance(self._location, (str, unicode)): |
140 | contents = llsd.parse(open(self._location).read()) | ||
141 | else: | ||
142 | # we probably have a file-like object. Godspeed! | ||
143 | contents = llsd.parse(self._location.read()) | ||
144 | self._reference_contents(contents) | ||
135 | # Check for alternative implementations | 145 | # Check for alternative implementations |
136 | try: | 146 | try: |
137 | for name, alt in self._contents['alternative'].items(): | 147 | for name, alt in self._contents['alternative'].items(): |
@@ -182,6 +192,16 @@ class NamedQuery(object): | |||
182 | ready them for use in LIKE statements""" | 192 | ready them for use in LIKE statements""" |
183 | if sql: | 193 | if sql: |
184 | #print >>sys.stderr, "sql:",sql | 194 | #print >>sys.stderr, "sql:",sql |
195 | |||
196 | # This first sub is to properly escape any % signs that | ||
197 | # are meant to be literally passed through to mysql in the | ||
198 | # query. It leaves any %'s that are used for | ||
199 | # like-expressions. | ||
200 | expr = re.compile("(?<=[^a-zA-Z0-9_-])%(?=[^:])") | ||
201 | sql = expr.sub('%%', sql) | ||
202 | |||
203 | # This should tackle the rest of the %'s in the query, by | ||
204 | # converting them to LIKE clauses. | ||
185 | expr = re.compile("(%?):([a-zA-Z][a-zA-Z0-9_-]*)%") | 205 | expr = re.compile("(%?):([a-zA-Z][a-zA-Z0-9_-]*)%") |
186 | sql = expr.sub(self._prepare_like, sql) | 206 | sql = expr.sub(self._prepare_like, sql) |
187 | expr = re.compile("#:([a-zA-Z][a-zA-Z0-9_-]*)") | 207 | expr = re.compile("#:([a-zA-Z][a-zA-Z0-9_-]*)") |
@@ -333,7 +353,8 @@ class NamedQuery(object): | |||
333 | cursor = connection.cursor() | 353 | cursor = connection.cursor() |
334 | 354 | ||
335 | statement = self.sql(connection, params) | 355 | statement = self.sql(connection, params) |
336 | #print "SQL:", statement | 356 | if DEBUG: |
357 | print "SQL:", statement | ||
337 | rows = cursor.execute(statement) | 358 | rows = cursor.execute(statement) |
338 | 359 | ||
339 | # *NOTE: the expect_rows argument is a very cheesy way to get some | 360 | # *NOTE: the expect_rows argument is a very cheesy way to get some |